Harro van der Klauw avatar Harro van der Klauw committed 896848a

Refactored to a more sensible structure
Renamed everything according to the other cms plugins
Shamelessly ripped and modified the readme from tehfink's faq plugin (thanks !)

Comments (0)

Files changed (25)

-CMS integration:
+ALPHA
+
+Name: cmsplugin-news
+Description: A news plugin for django-cms
+Download: http://bitbucket.org/MrOxiMoron/cmsplugin-news/
+
+Requirements:
+- django-cms-2.0: rev 2b59edde3cf1c140edfb14b544f2fbcbd56073f8
+- django: 1.1.1
+
+Last tested with:
+- django-cms-2.0: rev 2b59edde3cf1c140edfb14b544f2fbcbd56073f8
+- django: 1.1.1
+
+Setup
+- make sure requirements are installed and properly working
+- add cmsplugin_news to python path
+- add 'cmsplugin_news' to INSTALLED_APPS
+- run 'python manage.py syncdb'
+- Add the cmsplugin_news.urls to the CMS_APPLICATIONS_URLS setting 
+- Add the cmsplugin_news.navigation.get_nodes to the CMS_NAVIGATION_EXTENDERS setting
+- Create a page and link the application and navigation to it.
+- Create the propper templates for your site, the ones included with the app are VERY basic
+
+Todo and Tomaybes:
+- Add tests
+- Allow comments on news (add option to the news model for it)
+- Add migrations
+- Optimize the navigation code, it works but there is probably a better way to do it.
+- Add RSS feed
+- Use the textplugin's way of using a editor for the content
+- Add excerpt
+- Add optional author field
+- Add optional end date to hide news again
+- Add Tags
+- Add translations (I can do the dutch one)
+- Ideas other people come up with :D
+
+Examples:
 
 CMS_APPLICATIONS_URLS = (
-    ('news.urls', gettext('News')),
+    ('cmsplugin_news.urls', 'News'),
 )
 CMS_NAVIGATION_EXTENDERS = (
-    ('news.navigation.get_nodes', gettext('News menu')),
-)
+    ('cmsplugin_news.navigation.get_nodes','News navigation'),
+)

Empty file removed.

admin.py

-from django.contrib import admin
-
-from news.models import News
-
-class NewsAdmin(admin.ModelAdmin):
-    date_hierarchy = 'pub_date'
-    list_display = ('slug', 'title', 'is_published')
-    list_editable = ('title', 'is_published')
-    list_filter = ('is_published', )
-    search_fields = ['title', 'content']
-    prepopulated_fields = {'slug': ('title',)}
-    
-    save_as = True
-    save_on_top = True
-
-admin.site.register(News, NewsAdmin)
Add a comment to this file

cmsplugin_news/__init__.py

Empty file added.

cmsplugin_news/admin.py

+from django.contrib import admin
+
+from cmsplugin_news.models import News
+
+class NewsAdmin(admin.ModelAdmin):
+    date_hierarchy = 'pub_date'
+    list_display = ('slug', 'title', 'is_published')
+    list_editable = ('title', 'is_published')
+    list_filter = ('is_published', )
+    search_fields = ['title', 'content']
+    prepopulated_fields = {'slug': ('title',)}
+    
+    save_as = True
+    save_on_top = True
+
+admin.site.register(News, NewsAdmin)

cmsplugin_news/models.py

+import datetime
+
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+class PublishedNewsManager(models.Manager):
+    """
+        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(models.Model):
+    """
+    News
+    """
+    
+    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'))
+    content         = models.TextField(_('Content'), blank=True)
+    
+    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)
+    
+    published = PublishedNewsManager()
+    objects = models.Manager()
+    
+    class Meta:
+        verbose_name = _('News')
+        verbose_name_plural = _('News')
+        ordering = ('-pub_date', )
+    
+    def __unicode__(self):
+        return self.title
+    
+    @models.permalink
+    def get_absolute_url(self):
+        return ('news_detail', (), { 'year': self.pub_date.strftime("%Y"),
+                                     'month': self.pub_date.strftime("%m"),
+                                     'day': self.pub_date.strftime("%d"),
+                                     'slug': self.slug })
+    

cmsplugin_news/navigation.py

+from datetime import datetime
+from django.core.urlresolvers import reverse
+
+from cms.utils.navigation import NavigationNode
+
+from cmsplugin_news.models import News
+
+def get_nodes(request):
+    res = []
+    
+    items = News.published.all()
+    
+    years_done = []
+    months_done = []
+    days_done = []
+    slug_done = []
+    
+    for item in items:
+        date = item.pub_date
+        
+        if not date.year in years_done:
+            years_done.append(date.year)
+            year_node = NavigationNode(date.year, reverse('news_archive_year', kwargs=dict(year=date.year)))
+            year_node.childrens = []
+            months_done = []
+            res.append(year_node)
+        
+        if not date.month in months_done:
+            months_done.append(date.month)
+            month_node = NavigationNode(datetime.strftime(date, '%B'), 
+                                reverse('news_archive_month', kwargs=dict(
+                                    year=date.year, 
+                                    month=datetime.strftime(date, '%m'))))
+            month_node.childrens = []
+            days_done = []
+            year_node.childrens.append(month_node)
+            
+        if not date.day in days_done:
+            days_done.append(date.day)
+            day_node = NavigationNode(datetime.strftime(date, '%d'), 
+                                reverse('news_archive_day', kwargs=dict(
+                                    year=date.year, 
+                                    month=datetime.strftime(date, '%m'),
+                                    day=datetime.strftime(date, '%d'))))
+            day_node.childrens = []
+            slug_done = []
+            month_node.childrens.append(day_node)
+            
+        if not item.slug in slug_done:
+            slug_done.append(item.slug)
+            item_node = NavigationNode(item.title, item.get_absolute_url())
+            item_node.childrens = []
+            day_node.childrens.append(item_node)
+            
+    return res
+            

cmsplugin_news/templates/cmsplugin_news/news_archive.html

+<h1>Latest news</h1>
+
+{% for object in latest %}
+	<p><strong>{{ object.title }}</strong><br/><a href="{{ object.get_absolute_url }}">Read more</a></p>
+{% endfor %}

cmsplugin_news/templates/cmsplugin_news/news_archive_day.html

+<h1>News for {{ day }}</h1>
+
+<ul>
+	{% for object in object_list %}
+		<li><a href="{{ object.get_absolute_url }}">{{ object.title }}</a></li>
+	{% empty %}
+		<li>No news for this day</li>
+	{% endfor %}
+</ul>

cmsplugin_news/templates/cmsplugin_news/news_archive_month.html

+<h1>News for {{ month }}</h1>
+
+<ul>
+	{% for object in object_list %}
+		<li><a href="{{ object.get_absolute_url }}">{{ object.title }}</a></li>
+	{% empty %}
+		<li>No news for this month</li>
+	{% endfor %}
+</ul>

cmsplugin_news/templates/cmsplugin_news/news_archive_year.html

+<h1>News months</h1>
+
+<ul>
+{% for month in datelist %}
+	<li>{{ month }}</li>
+{% endfor %}
+</ul>

cmsplugin_news/templates/cmsplugin_news/news_detail.html

+<h1>{{ object.title }}</h1>
+
+<p><span class="date">{{ object.pub_date }}</span><br/>
+	{{ object.content }}
+</p>
+

cmsplugin_news/tests.py

+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+

cmsplugin_news/urls.py

+from django.conf.urls.defaults import *
+
+from cmsplugin_news.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'),
+)
+

cmsplugin_news/views.py

+# Create your views here.

models.py

-import datetime
-
-from django.db import models
-from django.utils.translation import ugettext_lazy as _
-
-class PublishedNewsManager(models.Manager):
-    """
-        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(models.Model):
-    """
-    News
-    """
-    
-    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'))
-    content         = models.TextField(_('Content'), blank=True)
-    
-    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)
-    
-    published = PublishedNewsManager()
-    objects = models.Manager()
-    
-    class Meta:
-        verbose_name = _('News')
-        verbose_name_plural = _('News')
-        ordering = ('-pub_date', )
-    
-    def __unicode__(self):
-        return self.title
-    
-    @models.permalink
-    def get_absolute_url(self):
-        return ('news_detail', (), { 'year': self.pub_date.strftime("%Y"),
-                                     'month': self.pub_date.strftime("%m"),
-                                     'day': self.pub_date.strftime("%d"),
-                                     'slug': self.slug })
-    

navigation.py

-from datetime import datetime
-from django.core.urlresolvers import reverse
-
-from cms.utils.navigation import NavigationNode
-
-from news.models import News
-
-def get_nodes(request):
-    res = []
-    
-    items = News.published.all()
-    
-    years_done = []
-    months_done = []
-    days_done = []
-    slug_done = []
-    
-    for item in items:
-        date = item.pub_date
-        
-        if not date.year in years_done:
-            years_done.append(date.year)
-            year_node = NavigationNode(date.year, reverse('news_archive_year', kwargs=dict(year=date.year)))
-            year_node.childrens = []
-            months_done = []
-            res.append(year_node)
-        
-        if not date.month in months_done:
-            months_done.append(date.month)
-            month_node = NavigationNode(datetime.strftime(date, '%B'), 
-                                reverse('news_archive_month', kwargs=dict(
-                                    year=date.year, 
-                                    month=datetime.strftime(date, '%m'))))
-            month_node.childrens = []
-            days_done = []
-            year_node.childrens.append(month_node)
-            
-        if not date.day in days_done:
-            days_done.append(date.day)
-            day_node = NavigationNode(datetime.strftime(date, '%d'), 
-                                reverse('news_archive_day', kwargs=dict(
-                                    year=date.year, 
-                                    month=datetime.strftime(date, '%m'),
-                                    day=datetime.strftime(date, '%d'))))
-            day_node.childrens = []
-            slug_done = []
-            month_node.childrens.append(day_node)
-            
-        if not item.slug in slug_done:
-            slug_done.append(item.slug)
-            item_node = NavigationNode(item.title, item.get_absolute_url())
-            item_node.childrens = []
-            day_node.childrens.append(item_node)
-            
-    return res
-            

templates/news/news_archive.html

-<h1>Latest news</h1>
-
-{% for object in latest %}
-	<p><strong>{{ object.title }}</strong><br/><a href="{{ object.get_absolute_url }}">Read more</a></p>
-{% endfor %}

templates/news/news_archive_day.html

-<h1>News for {{ day }}</h1>
-
-<ul>
-	{% for object in object_list %}
-		<li><a href="{{ object.get_absolute_url }}">{{ object.title }}</a></li>
-	{% empty %}
-		<li>No news for this day</li>
-	{% endfor %}
-</ul>

templates/news/news_archive_month.html

-<h1>News for {{ month }}</h1>
-
-<ul>
-	{% for object in object_list %}
-		<li><a href="{{ object.get_absolute_url }}">{{ object.title }}</a></li>
-	{% empty %}
-		<li>No news for this month</li>
-	{% endfor %}
-</ul>

templates/news/news_archive_year.html

-<h1>News months</h1>
-
-<ul>
-{% for month in datelist %}
-	<li>{{ month }}</li>
-{% endfor %}
-</ul>

templates/news/news_detail.html

-<h1>{{ object.title }}</h1>
-
-<p><span class="date">{{ object.pub_date }}</span><br/>
-	{{ object.content }}
-</p>
-

tests.py

-"""
-This file demonstrates two different styles of tests (one doctest and one
-unittest). These will both pass when you run "manage.py test".
-
-Replace these with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-class SimpleTest(TestCase):
-    def test_basic_addition(self):
-        """
-        Tests that 1 + 1 always equals 2.
-        """
-        self.failUnlessEqual(1 + 1, 2)
-
-__test__ = {"doctest": """
-Another way to test that 1 + 1 is equal to 2.
-
->>> 1 + 1 == 2
-True
-"""}
-

urls.py

-from django.conf.urls.defaults import *
-
-from news.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'),
-)
-

views.py

-# Create your views here.
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.