Commits

Peter A. Kerzum  committed bac520f

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

  • Participants
  • Parent commits 03ba1b8

Comments (0)

Files changed (5)

File 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

File 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)
+

File 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.')
+        

File 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'))
+

File cmsplugin_news/navigation.py

             day_node.childrens.append(item_node)
             
     return res
-            
+