Commits

Anonymous committed 66d4f88

made compatible with Django 1.5.1 and django-cms 2.4.1

Comments (0)

Files changed (8)

-0.1
+0.2
 
 Name: cmsplugin-advancednews
 Description: A advanced news plugin for django-cms based on cmsplugin-news
-Download: http://bitbucket.org/chernysh/cmsplugin-advancednews/
+Download: 
+    http://bitbucket.org/chernysh/cmsplugin-advancednews/ for version 0.1
+    compatible with previous versions of Django and cms 2
+    http://bitbucket.org/aaloy/cmsplugin-advancednews/ for version 0.2
 
 Requirements:
-- django-cms-2.0.0 final
-- django: 1.1.1
-+ requirements for django-cms-2.0
+- django-cms-2.4.1 final
+- django: 1.5.1
++ requirements for django-cms-2.4
 
 Futures:
 - support categories for news. We can put to page all news or only from one category

cmsplugin_advancednews/cms_app.py

+#!/usr/bin/env python
+# encoding: utf-8
+# ----------------------------------------------------------------------------
+
 from cms.app_base import CMSApp
 from cms.apphook_pool import apphook_pool
 from django.utils.translation import ugettext_lazy as _
 
+
 class NewsApphook(CMSApp):
     name = _("Latest Advanced News")
     urls = ["cmsplugin_advancednews.urls"]

cmsplugin_advancednews/cms_plugins.py

+#!/usr/bin/env python
+# encoding: utf-8
+# ----------------------------------------------------------------------------
+
 from django.utils.translation import ugettext_lazy as _
 
 from cms.plugin_base import CMSPluginBase
 from cms.plugin_pool import plugin_pool
+from cmsplugin_advancednews.models import LatestAdvancedNewsPlugin, News
 
-from cmsplugin_advancednews.models import LatestAdvancedNewsPlugin, News
-from cmsplugin_advancednews import settings
-
-from django.conf import settings
 
 class CMSLatestAdvancedNewsPlugin(CMSPluginBase):
     """ Plugin class for the latest news """
     model = LatestAdvancedNewsPlugin
-
     name = _('Latest news')
     render_template = 'cmsplugin_advancednews/latest_news.html'
-    
-    
+
     def render(self, context, instance, placeholder):
         """ Render the latest news """
         query = News.published
         if instance.category is None:
             latest = query.all()[:instance.limit]
         else:
-            latest = query.filter(category=instance.category).all()[:instance.limit]
+            latest = query.filter(
+                category=instance.category).all()[:instance.limit]
         context.update({
             'instance': instance,
             'latest': latest,
         })
         return context
 
-##if not settings.DISABLE_LATEST_ADVANCEDNEWS_PLUGIN:
 plugin_pool.register_plugin(CMSLatestAdvancedNewsPlugin)

cmsplugin_advancednews/models.py

 from hvad.models import TranslatableModel, TranslatedFields
 from hvad.manager import TranslationManager
 from cms.models.fields import PlaceholderField
+from django.core.urlresolvers import reverse
+
 
 class PublishedNewsManager(TranslationManager):
     """ Filters out all unpublished and items with a publication date in the future. """
     def get_query_set(self):
         return super(PublishedNewsManager, self).get_query_set().filter(is_published=True).filter(pub_date__lte=datetime.datetime.now())
 
-    
+
 class News(TranslatableModel):
     """ News model """
-    
-    slug = models.SlugField(_('Slug'), unique_for_date='pub_date', 
+
+    slug = models.SlugField(_('Slug'), unique_for_date='pub_date',
             help_text=_('Name in lowercase with no spaces which will be chown in the URL of the navigator'))
 
     category = models.ForeignKey("Category", related_name="n_category",
 
     is_published = models.BooleanField(_('Published'), default=False)
     pub_date = models.DateTimeField(_('Publication date'), default=datetime.datetime.now())
-    
+
     created = models.DateTimeField(auto_now_add=True, editable=False)
     updated = models.DateTimeField(auto_now=True, editable=False)
-    content = PlaceholderField('content', language_aware=True,
+    content = PlaceholderField('content',
             verbose_name=_('Full news body'),
             help_text=_('Full content that will be shown in the body of the news item \
                     <br/><b>Quick note</b>: To add text content: \
-                    <br/>Select Available Plutins > Text > Add a plugin'))   
-    
-    translations = TranslatedFields( 
+                    <br/>Select Available Plutins > Text > Add a plugin'))
+
+    translations = TranslatedFields(
         title = models.CharField(verbose_name=_('Title'), max_length=255,
             help_text=_('Title of the news item')),
         excerpt = models.TextField(verbose_name=_('Excerpt'), blank=True,
             help_text=_('Short exceprt of the new item. Will be shown on the news list.'))
     )
-    
+
     published = PublishedNewsManager()
     objects = TranslationManager()
-    
+
     class Meta:
         verbose_name = _('News')
         verbose_name_plural = _('News')
 
     def __unicode__(self):
         return self.lazy_translation_getter('title', 'New: %s' % self.id)
-            
-        
 
-    @models.permalink
+
+
     def get_absolute_url(self):
-        return ('news_detail', (), {
+        return reverse('news_detail', kwargs={
             'year': self.pub_date.strftime("%Y"),
             'month': self.pub_date.strftime("%m"),
             'day': self.pub_date.strftime("%d"),
     """
     Category
     """
-    
+
     pub_date        = models.DateTimeField(_('Publication date'), default=datetime.datetime.now())
     created         = models.DateTimeField(auto_now_add=True, editable=False)
     updated         = models.DateTimeField(auto_now=True, editable=False)
-    
+
     translations = TranslatedFields(
         title = models.CharField(_('Title'), max_length=255),
     )
-    
+
     class Meta:
         verbose_name = _('Category')
         verbose_name_plural = _('Categories')
         ordering = ('-pub_date', )
-    
-    def __unicode__(self):        
+
+    def __unicode__(self):
         return self.lazy_translation_getter('title', 'Category: %s' % self.id)
 
 
 class LatestAdvancedNewsPlugin(CMSPlugin):
     """ Model for the settings when using the latest news cms plugin. """
-    
+
     category = models.ForeignKey(Category, null=True, blank=True, default=None)
-    limit = models.PositiveIntegerField(_('Number of news items to show'), 
+    limit = models.PositiveIntegerField(_('Number of news items to show'),
                                         help_text=_('Limits the number of items that will be displayed'))

cmsplugin_advancednews/templates/cmsplugin_advancednews/latest_news.html

     <li>{% trans "No news yet" %}</li>
   {% endfor %}
 </ul>
-<a href="{% url news_archive_index %}">{% trans "Archive" %}</a>
+<a href="{% url 'news_archive_index' %}">{% trans "Archive" %}</a>

cmsplugin_advancednews/templates/cmsplugin_advancednews/news_archive_year.html

 <h1>{% blocktrans %}News for {{ year }}{% endblocktrans %}</h1>
 <ul>
   {% for date in date_list %}
-    <li><a href="{% url news_archive_month year=year month=date|date:'m'  %}">{{ date|date:"F" }}</a></li>
+    <li><a href="{% url 'news_archive_month' year=year month=date|date:'m'  %}">{{ date|date:"F" }}</a></li>
   {% empty %}
     <li>{% trans "No news for this year" %}</li>
   {% endfor %}

cmsplugin_advancednews/urls.py

+#!/usr/bin/env python
+# encoding: utf-8
+# ----------------------------------------------------------------------------
+
 from django.conf.urls.defaults import *
+from cmsplugin_advancednews.models import News
+from django.views.generic.dates import (ArchiveIndexView, YearArchiveView,
+        MonthArchiveView, DayArchiveView, DateDetailView)
 
-from cmsplugin_advancednews.models import News
-
-news_info_dict = {
-    'queryset': News.published.all(),
-    'date_field': 'pub_date',
-}
-
-news_info_month_dict = {
-    'queryset': News.published.all(),
-    'date_field': 'pub_date',
-    'month_format': '%m',
-}
-
-urlpatterns = patterns('django.views.generic.date_based',
-                       (r'^$',
-                        'archive_index', news_info_dict, 'news_archive_index'),
-
-                       (r'^(?P<year>\d{4})/$',
-                        'archive_year', news_info_dict, 'news_archive_year'),
-
-                       (r'^(?P<year>\d{4})/(?P<month>\d{2})/$',
-                        'archive_month', news_info_month_dict, 'news_archive_month'),
-
-                       (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$',
-                        'archive_day', news_info_month_dict, 'news_archive_day'),
-
-                       (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
-                        'object_detail', news_info_month_dict, 'news_detail'),
+urlpatterns = patterns('',
+                       url(r'^$',
+                        ArchiveIndexView.as_view(
+                            queryset=News.published.all(),
+                            date_field='pub_date'),
+                            name='news_archive_index'),
+                       url(r'^(?P<year>\d{4})/$',
+                        YearArchiveView.as_view(
+                            queryset=News.published.all(),
+                            date_field='pub_date'),
+                            name='news_archive_year'),
+                       url(r'^(?P<year>\d{4})/(?P<month>\d{2})/$',
+                        MonthArchiveView.as_view(
+                            month_format='%m',
+                            queryset=News.published.all(),
+                            date_field='pub_date'),
+                            name='news_archive_month'),
+                       url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$',
+                        DayArchiveView.as_view(
+                            month_format='%m',
+                            queryset=News.published.all(),
+                            date_field='pub_date'),
+                            name='news_archive_day'),
+                       url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
+                        DateDetailView.as_view(
+                            month_format='%m',
+                            queryset=News.published.all(),
+                            date_field='pub_date'),
+                        name='news_detail'),
                        )
 
 
 setup(
     name='cmsplugin-advancednews',
-    version='0.1',
-    description='This is a news app/plugin for the django-cms 2',
+    version='0.2',
+    description='This is a news app/plugin for the django-cms 2.4 and django 1.5',
     author='Vadim Chernysh',
     author_email='chernysh.vadim@gmail.com',
     url='http://bitbucket.org/chernysh/cmsplugin-advancednews/',