Commits

Guilherme Gondim committed 8039d42 Merge

Merged up from new_feeds branch.

Comments (0)

Files changed (12)

diario/__init__.py

 Blog application for Django projects.
 """
 
-VERSION = (0, 3, 2, 'kamalmaz')
+VERSION = (0, 4)
 
 def get_version():
     """
     Returns the version as a human-format string.
     """
-    v = '.'.join([str(i) for i in VERSION[:-1]])
-    return '%s-%s' % (v, VERSION[-1])
+    return '.'.join([str(i) for i in VERSION])
 
 __author__ = 'See the file AUTHORS.'
 __license__ = 'GNU Lesser General Public License (GPL), Version 3'

diario/feeds/comments.py

 
 from django.conf import settings
 from django.contrib.comments.models import Comment
-from django.contrib.syndication.feeds import Feed
-from django.contrib.syndication.feeds import FeedDoesNotExist
+from django.contrib.syndication.views import Feed
+from django.contrib.syndication.views import FeedDoesNotExist
 from django.utils.feedgenerator import Atom1Feed
 from django.contrib.sites.models import Site
-from django.core.exceptions import ObjectDoesNotExist
 from django.core.urlresolvers import reverse
+from django.shortcuts import get_object_or_404
 from django.utils.translation import ugettext as _
+
 from diario.models import Entry
 
+
 class RssCommentsFeed(Feed):
     """All weblog comments RSS feeds.
     """
     def items(self):
         return self.get_query_set()[:30]
 
+
 class AtomCommentsFeed(RssCommentsFeed):
     """All weblog comments Atom feeds.
     """
     feed_type = Atom1Feed
     subtitle = RssCommentsFeed.description
 
+
+
 class RssCommentsByEntryFeed(RssCommentsFeed):
     """Comments RSS feeds for a specific entry.
     """
-    def get_object(self, bits):
-        # In case of "rss/weblog/1/foo/bar/", or other such clutter, check that
-        # bits has only one member.
-        if len(bits) != 1:
-            raise ObjectDoesNotExist
-        return Entry.objects.get(id=bits[0])
+
+    def get_object(self, request, year, month, day, slug):
+        kwargs = {
+            'pub_date__year': year,
+            'pub_date__month': month,
+            'pub_date__day': day,
+            'slug': slug
+        }
+        return get_object_or_404(Entry, **kwargs)
 
     def title(self, entry):
         if not hasattr(self, '_site'):
     def items(self, entry):
         return self.get_query_set(entry)[:30]
 
+
 class AtomCommentsByEntryFeed(RssCommentsByEntryFeed):
     """Comments Atom feeds for a specific entry.
     """

diario/feeds/entries.py

 #  Software Foundation. See the file README for copying conditions.
 #
 
-from django.conf import settings
-from django.contrib.syndication.feeds import Feed
-from django.contrib.syndication.feeds import FeedDoesNotExist
+from django.contrib.syndication.views import Feed
 from django.utils.feedgenerator import Atom1Feed
 from django.contrib.sites.models import Site
-from django.core.exceptions import ObjectDoesNotExist
 from django.core.urlresolvers import reverse, NoReverseMatch
 from django.utils.translation import ugettext as _
 
 from diario.models import Entry
 
+
 class RssEntriesFeed(Feed):
     description = _('Latest entries on Weblog')
     title_template = 'feeds/diario_title.html'
         except AttributeError:
             pass      # ignore if not have django-tagging support
 
+
 class AtomEntriesFeed(RssEntriesFeed):
     feed_type = Atom1Feed
     subtitle = RssEntriesFeed.description

diario/feeds/entries_by_author.py

 #
 
 from django.contrib.auth.models import User
-from django.contrib.syndication.feeds import Feed
-from django.contrib.syndication.feeds import FeedDoesNotExist
+from django.contrib.syndication.views import FeedDoesNotExist
 from django.utils.feedgenerator import Atom1Feed
 from django.contrib.sites.models import Site
-from django.core.exceptions import ObjectDoesNotExist
 from django.core.urlresolvers import reverse
+from django.shortcuts import get_object_or_404
 from django.utils.translation import ugettext as _
 
 from diario.feeds.entries import RssEntriesFeed
 from diario.models import Entry
 
+
 class RssEntriesByAuthorFeed(RssEntriesFeed):
-    def get_object(self, bits):
-        # In case of "rss/authors/example/foo/bar/", or other such
-        # clutter, check that bits has only one member.
-        if len(bits) != 1:
-            raise ObjectDoesNotExist
-        return User.objects.get(username__exact=bits[0])
+
+    def get_object(self, request, author):
+        return get_object_or_404(User, username__exact=author)
 
     def title(self, user):
         if not hasattr(self, '_site'):
     def items(self, user):
         return self.get_query_set(user)[:15]
 
+
 class AtomEntriesByAuthorFeed(RssEntriesByAuthorFeed):
     feed_type = Atom1Feed
     subtitle = RssEntriesByAuthorFeed.description

diario/feeds/tagged.py

 #  Software Foundation. See the file README for copying conditions.
 #
 
-from django.contrib.syndication.feeds import Feed
-from django.contrib.syndication.feeds import FeedDoesNotExist
+from django.contrib.syndication.views import Feed
+from django.contrib.syndication.views import FeedDoesNotExist
 from django.utils.feedgenerator import Atom1Feed
 from django.contrib.sites.models import Site
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.urlresolvers import reverse
+from django.shortcuts import get_object_or_404
 from django.utils.translation import ugettext as _
 
 from diario.feeds.entries import RssEntriesFeed
 from tagging.models import Tag
 
 class RssEntriesByTagFeed(RssEntriesFeed):
-    def get_object(self, bits):
-        # In case of "rss/tags/example/foo/bar/", or other such
-        # clutter, check that bits has only one member.
-        if len(bits) != 1:
-            raise ObjectDoesNotExist
-        return Tag.objects.get(name__exact=bits[0])
+
+    def get_object(self, request, tag):
+        return get_object_or_404(Tag, name__exact=tag)
 
     def title(self, tag):
         if not hasattr(self, '_site'):

diario/urls/comments.py

+# -*- coding: utf-8 -*-
+#
+#  Copyright (c) 2012 Guilherme Gondim and contributors
+#
+#  This file is part of Django Diário.
+#
+#  Django Diário is free software under terms of the GNU Lesser
+#  General Public License version 3 (LGPLv3) as published by the Free
+#  Software Foundation. See the file README for copying conditions.
+#
+
+"""
+URL definitions for weblog comments.
+"""
+
+from django.conf.urls.defaults import *
+from django.contrib.comments.models import Comment
+from django.contrib.sites.models import Site
+
+from diario import feeds
+
+
+def get_comments():
+    queryset = Comment.objects.filter(
+        site=Site.objects.get_current(),
+        content_type__app_label__exact='diario',
+        content_type__model__exact='entry'
+    )
+    return queryset.order_by('-submit_date')
+
+
+comments = url(
+    regex  = '^$',
+    view   = 'django.views.generic.list_detail.object_list',
+    name   = 'diario-comments',
+    kwargs = {
+        'queryset': get_comments(),
+        'paginate_by': 15,
+    }
+)
+
+
+comments_atom = url(
+    regex = 'atom/$',
+    view  = feeds.comments.AtomCommentsFeed(),
+    name  = 'diario-comments-atom'
+)
+
+comments_rss = url(
+    regex = 'rss/$',
+    view  = feeds.comments.RssCommentsFeed(),
+    name  ='diario-comments-rss'
+)
+
+
+urlpatterns = patterns('',
+    comments,
+    comments_atom, comments_rss
+)

diario/urls/entries.py

 """
 
 from django.conf.urls.defaults import *
-from diario.settings import DIARIO_NUM_LATEST
-from diario.views.entries import EntryList, EntryDetail, EntryArchiveDay, \
-                                EntryArchiveMonth, EntryArchiveYear
 
-info_dict = {
-    'template_object_name': 'entry',
-}
+from diario.feeds import entries as feeds
+from diario.feeds import comments as comment_feeds
+from diario.views import entries as views
+
+
+entry_list = url(
+    regex  = '^$',
+    view   = views.EntryList.as_view(),
+    name   = 'diario-entry-list'
+)
 
 entry_detail = url(
     regex  = '^(?P<year>\d{4})/(?P<month>[0-9]{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
-    view   = EntryDetail.as_view(),    
+    view   = views.EntryDetail.as_view(),
     name   = 'diario-entry'
 )
 
+
 archive_day = url(
     regex  = '^(?P<year>\d{4})/(?P<month>[0-9]{2})/(?P<day>\d{2})/$',
-    view   = EntryArchiveDay.as_view(),    
+    view   = views.EntryArchiveDay.as_view(),
     name   = 'diario-archive-day'
 )
 
 archive_month = url(
     regex  = '^(?P<year>\d{4})/(?P<month>[0-9]{2})/$',
-    view   = EntryArchiveMonth.as_view(),    
+    view   = views.EntryArchiveMonth.as_view(),
     name   = 'diario-archive-month'
 )
 
 archive_year = url(
     regex  = '^(?P<year>\d{4})/$',
-    view   = EntryArchiveYear.as_view(),    
+    view   = views.EntryArchiveYear.as_view(),
     name   = 'diario-archive-year'
 )
 
-entry_list = url(
-    regex  = '^$',
-    view   = EntryList.as_view(),    
-    name   = 'diario-entry-list'
+
+entries_atom = url(
+    regex = '^atom/$',
+    view  = feeds.AtomEntriesFeed(),
+    name  = 'diario-entry-atom'
+)
+
+entries_rss = url(
+    regex = '^rss/$',
+    view  = feeds.RssEntriesFeed(),
+    name  ='diario-entry-rss'
+)
+
+
+entry_comments_atom = url(
+    regex = '^(?P<year>\d{4})/(?P<month>[0-9]{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/atom/$',
+    view  = comment_feeds.AtomCommentsByEntryFeed(),
+    name  = 'diario-entry-comments-atom'
+)
+
+entry_comments_rss = url(
+    regex = '^(?P<year>\d{4})/(?P<month>[0-9]{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/rss/$',
+    view  = comment_feeds.RssCommentsByEntryFeed(),
+    name  ='diario-entry-comments-rss'
 )
 
-urlpatterns = patterns('', entry_detail, archive_day, archive_month,
-                       archive_year, entry_list)
+
+urlpatterns = patterns('',
+    entry_list, entry_detail,
+    archive_day, archive_month, archive_year,
+    entries_atom, entries_rss,
+    entry_comments_atom, entry_comments_rss
+)

diario/urls/entries_by_author.py

 """
 
 from django.conf.urls.defaults import *
-from diario.settings import DIARIO_NUM_LATEST
-from diario.views.entries_by_author import EntryListByAuthor
 
-entry_list_by_author = url(        # entries by author
+from diario.feeds import entries_by_author as feeds
+from diario.views import entries_by_author as views
+
+
+# TODO: AuthorListView
+# author_list = url(
+#     regex  = '^$',
+#     view   = views.AuthorListView.as_view(),    
+#     name   = 'diario-author-list',
+# )
+
+entry_list_by_author = url(     # entries by author
     regex  = '^(?P<author>[^/]+)/$',
-    view   = EntryListByAuthor.as_view(),    
+    view   = views.EntryListByAuthor.as_view(),    
     name   = 'diario-author-entry-list',
 )
 
-urlpatterns = patterns('', entry_list_by_author)
+
+entries_by_author_atom = url(
+    regex = '^(?P<author>[^/]+)/atom/$',
+    view  = feeds.AtomEntriesByAuthorFeed(),
+    name  = 'diario-author-entry-atom'
+)
+
+entries_by_author_rss = url(
+    regex = '^(?P<author>[^/]+)/rss/$',
+    view  = feeds.RssEntriesByAuthorFeed(),
+    name  = 'diario-author-entry-rss'
+)
+
+
+urlpatterns = patterns('',
+    entry_list_by_author,
+    entries_by_author_atom, entries_by_author_rss
+)

diario/urls/tagged.py

 """
 
 from django.conf.urls.defaults import *
+
 from diario.settings import DIARIO_NUM_LATEST
+from diario.feeds import tagged as feeds
+
 
-info_dict = {
-    'paginate_by': DIARIO_NUM_LATEST,
-    'template_name': 'diario/entry_list_tagged.html',
-    'template_object_name': 'entry',
-}
+# TODO: TagListView
+# author_list = url(
+#     regex  = '^$',
+#     view   = views.TagListView.as_view(),    
+#     name   = 'diario-tagged-tag-list',
+# )
 
 tagged_entry_list = url(        # entries by tag
     regex  = '^(?P<tag>[^/]+)/$',
     view   = 'diario.views.tagged.tagged_entry_list',
-    kwargs = info_dict,
     name   = 'diario-tagged-entry-list',
+    kwargs = {
+        'paginate_by': DIARIO_NUM_LATEST,
+        'template_name': 'diario/entry_list_tagged.html',
+        'template_object_name': 'entry',
+    }
+)
+
+
+tagged_entry_atom = url(
+    regex = '^(?P<tag>[^/]+)/atom/$',
+    view  = feeds.AtomEntriesByTagFeed(),
+    name = 'diario-tagged-entry-atom'
 )
 
-urlpatterns = patterns('', tagged_entry_list)
+tagged_entry_rss = url(
+    regex = '^(?P<tag>[^/]+)/rss/$',
+    view  = feeds.RssEntriesByTagFeed(),
+    name = 'diario-tagged-entry-rss'
+)
+
+
+urlpatterns = patterns('',
+    tagged_entry_list,
+    tagged_entry_atom, tagged_entry_rss
+)

diario/views/entries.py

 
 from diario.models import Entry
 from django.views.generic.list import ListView
-from django.views.generic.dates import DateDetailView, YearArchiveView, \
-                                        MonthArchiveView, DayArchiveView
+from django.views.generic import dates
 from diario.settings import DIARIO_NUM_LATEST
 
 
-class EntryDetail(DateDetailView):    
+class EntryDetail(dates.DateDetailView):
     slug_field = 'slug'
     date_field = 'pub_date'
     queryset = Entry.published_on_site.all()
     month_format = '%m'
-    
-    
+
     def dispatch(self, request, *args, **kwargs):
         if request.user.has_perm('diario.change_entry'):
             self.allow_future = True
         else:
             self.allow_future = False
         return super(EntryDetail, self).dispatch(request, *args, **kwargs)
-    
 
-    
-class EntryArchiveYear(YearArchiveView):
+
+class EntryArchiveYear(dates.YearArchiveView):
     queryset = Entry.published_on_site.all()
     date_field = 'pub_date'
-    
 
 
-class EntryArchiveMonth(MonthArchiveView):
+class EntryArchiveMonth(dates.MonthArchiveView):
     month_format = '%m'
     date_field = 'pub_date'
     queryset = Entry.published_on_site.all()
-    
 
-class EntryArchiveDay(DayArchiveView):
+
+class EntryArchiveDay(dates.DayArchiveView):
     month_format = '%m'
     date_field = 'pub_date'
     queryset = Entry.published_on_site.all()
 class EntryList(ListView):
     queryset = Entry.published_on_site.all()
     paginate_by = DIARIO_NUM_LATEST
-

diario/views/entries_by_author.py

 from django.http import Http404
 from django.utils.translation import ugettext as _
 from django.views.generic.list import ListView
-from diario.settings import DIARIO_NUM_LATEST
 
+from diario.settings import DIARIO_NUM_LATEST
 from diario.models import Entry
 
+
 class EntryListByAuthor(ListView):
     paginate_by = DIARIO_NUM_LATEST
     template_name = 'diario/entry_list_by_author.html'

diario/views/syndication.py

-# -*- coding: utf-8 -*-
-#
-#  Copyright (c) 2008-2012 Guilherme Gondim and contributors
-#
-#  This file is part of Django Diário.
-#
-#  Django Diário is free software under terms of the GNU Lesser
-#  General Public License version 3 (LGPLv3) as published by the Free
-#  Software Foundation. See the file README for copying conditions.
-#
-
-from django.contrib.syndication import feeds
-from django.http import Http404, HttpResponse
-
-def feed(request, slug, bit='', feed_dict=None):
-    """
-    TODO: documment this.
-    """
-    if not feed_dict:
-        raise Http404, "No feeds are registered."
-
-    try:
-        feed = feed_dict[slug]
-    except KeyError:
-        raise Http404, "Slug %r isn't registered." % slug
-
-    try:
-        feedgen = feed(slug, request).get_feed(bit)
-    except feeds.FeedDoesNotExist:
-        raise Http404, "Invalid feed parameters. Slug %r is valid, " % slug +\
-                       "but bit, or lack thereof, are not."
-
-    response = HttpResponse(mimetype=feedgen.mime_type)
-    feedgen.write(response, 'utf-8')
-    return response
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.