Commits

Anonymous committed bac520f

added support for languages (currently stable with plugin view)
added news feeds (using NULL feed is ok, so they are optional)

Comments (0)

Files changed (5)

cmsplugin_news/admin.py

 from django.core import serializers
 
 from cmsplugin_news.forms import NewsForm
-from cmsplugin_news.models import News
+from cmsplugin_news.models import News, NewsFeed
     
+class NewsFeedAdmin(admin.ModelAdmin):
+    search_fields = [('title', )]
+admin.site.register(NewsFeed, NewsFeedAdmin)
+
 class NewsAdmin(admin.ModelAdmin):
     """
         Admin for news
     """
     date_hierarchy = 'pub_date'
-    list_display = ('slug', 'title', 'is_published', 'pub_date')
-    #list_editable = ('title', 'is_published')
-    list_filter = ('is_published', )
+    list_display = ('slug', 'title', 'language', 'feed', 'is_published', 'pub_date')
+    list_filter = ('is_published', 'language', 'feed', )
     search_fields = ['title', 'excerpt', 'content']
     prepopulated_fields = {'slug': ('title',)}
     form = NewsForm

cmsplugin_news/cms_plugins.py

         """
             Render the latest news
         """
-        latest = News.published.all()[:instance.limit]
+        if instance.feed:
+            latest = News.published.filter(language=instance.language).filter(feed=instance.feed).all()[:instance.limit]
+        else:
+            latest = News.published.filter(language=instance.language).all()[:instance.limit]
+            
         context.update({
             'instance': instance,
             'latest': latest,
         return context
 
 if not settings.DISABLE_LATEST_NEWS_PLUGIN:
-    plugin_pool.register_plugin(CMSLatestNewsPlugin)
+    plugin_pool.register_plugin(CMSLatestNewsPlugin)
+

cmsplugin_news/forms.py

         super(NewsForm, self).__init__(*args, **kwargs)
         widget = self._get_widget()
         self.fields['content'].widget = widget
-        
+    language = forms.ChoiceField(label="Language", choices=settings.CMS_LANGUAGES,
+        help_text='The current language of the content fields.')
+        

cmsplugin_news/models.py

                     .filter(is_published=True) \
                     .filter(pub_date__lte=datetime.datetime.now())
     
+class NewsFeed(models.Model):
+    """
+    News Feed
+    """
+    title = models.CharField(_('Title'), max_length=255)
+    def __unicode__(self):
+        return self.title
+    
 class News(models.Model):
     """
     News
     """
     
+    language        = models.CharField(_("language"), max_length=5, db_index=True)
+    feed            = models.ForeignKey(NewsFeed, verbose_name=_('Feed'))
     title           = models.CharField(_('Title'), max_length=255)
     slug            = models.SlugField(_('Slug'), unique_for_date='pub_date', 
                         help_text=_('A slug is a short name which uniquely identifies the news item for this day'))
     """
     limit = models.PositiveIntegerField(_('Number of news items to show'), 
                     help_text=_('Limits the number of items that will be displayed'))
+    feed = models.ForeignKey(NewsFeed, verbose_name=_('Feed'), null=True, blank=True,
+                    help_text=_('News feed to be displayed'))
+

cmsplugin_news/navigation.py

             day_node.childrens.append(item_node)
             
     return res
-            
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.