Commits

Guilherme Gondim committed 6be7ce5

remove comments support (must be implemented in diario.contrib)

Comments (0)

Files changed (6)

diario/feeds/comments.py

-# -*- coding: utf-8 -*-
-#
-#  Copyright (c) 2007-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.conf import settings
-from django.contrib.comments.models import Comment
-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.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.
-    """
-    description = _('Latest comments on Weblog')
-    title_template = 'feeds/comments_title.html'
-    description_template = 'feeds/comments_description.html'
-
-    def title(self):
-        if not hasattr(self, '_site'):
-            self._site = Site.objects.get_current()
-        return _("%(title)s's Weblog comments") % {'title': self._site.name}
-
-    def link(self):
-        return reverse('diario-entry-list')
-
-    def item_pubdate(self, comment):
-        return comment.submit_date
-
-    def get_query_set(self):
-        get_list_function = Comment.objects.filter
-        kwargs = {
-            'is_public': True,
-            'site__pk': settings.SITE_ID,
-            'content_type__app_label__exact': 'diario',
-            'content_type__model__exact': 'entry',
-        }
-        return get_list_function(**kwargs).order_by('-submit_date')
-
-    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, 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'):
-            self._site = Site.objects.get_current()
-        return _("Comments on: %(entry title)s @ %(weblog title)s's Weblog") %\
-            {'entry title':  entry.title, 'weblog title': self._site.name}
-
-    def description(self, entry):
-        return _('Latest comments for "%(title)s"') % {'title': entry.title}
-
-    def link(self, entry):
-        if not entry:
-            raise FeedDoesNotExist
-        return reverse('diario-entry', kwargs={
-            'year' : str(entry.pub_date.year),
-            'month': str(entry.pub_date.month).zfill(2),
-            'day'  : str(entry.pub_date.day).zfill(2),
-            'slug' : str(entry.slug)
-        })
-
-    def item_author_name(self, comment):
-        return comment.user_name
-
-    def item_author_link(self, comment):
-        return comment.user_url
-
-    def get_query_set(self, entry):
-        get_list_function = Comment.objects.filter
-        kwargs = {
-            'is_public': True,
-            'site__pk': settings.SITE_ID,
-            'content_type__app_label__exact': 'diario',
-            'content_type__model__exact': 'entry',
-            'object_pk': entry.id
-        }
-        return get_list_function(**kwargs).order_by('-submit_date')
-
-    def items(self, entry):
-        return self.get_query_set(entry)[:30]
-
-
-class AtomCommentsByEntryFeed(RssCommentsByEntryFeed):
-    """Comments Atom feeds for a specific entry.
-    """
-    feed_type = Atom1Feed
-    subtitle = RssCommentsByEntryFeed.description

diario/models/__init__.py

 
 __all__ = [
     'BaseEntryModel', 'EntryManager', 'CurrentSiteEntryManager',
-    'BasicEntryMixin', 'AuthorMixin', 'CommentsMixin', 'SiteMixin',
-    'SlugMixin',
+    'BasicEntryMixin', 'AuthorMixin', 'SiteMixin', 'SlugMixin',
 ]
 
 

diario/models/mixins/__init__.py

 #
 
 from diario.models.mixins.base import BasicEntryMixin, AuthorMixin, SlugMixin
-from diario.models.mixins.comments import CommentsMixin
 from diario.models.mixins.sites import SiteMixin
 
 
 __all__ = [
-    'BasicEntryMixin', 'AuthorMixin', 'SlugMixin', 'CommentsMixin', 'SiteMixin',
+    'BasicEntryMixin', 'AuthorMixin', 'SlugMixin', 'SiteMixin',
 ]

diario/models/mixins/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.
-#
-
-from django.db import models
-from django.utils.translation import ugettext_lazy as _
-
-
-class CommentsMixin(models.Model):
-    enable_comments = models.BooleanField(_('enable comments'), default=True)
-
-    class Meta:
-        abstract = True

diario/templatetags/diario_comments.py

-# -*- coding: utf-8 -*-
-#
-#  Copyright (c) 2007-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.
-#
-
-"""
-The ``diario.templatetags.diario_comments`` module defines a number of
-template tags which may be used to work with comments.
-
-To access Diário comments template tags in a template, use the {% load %}
-tag::
-
-    {% load diario_comments %}
-"""
-
-from django import template
-from django.conf import settings
-from django.contrib.comments.models import Comment
-
-register = template.Library()
-
-class CommentListNode(template.Node):
-    def __init__(self, num, var_name, start=0):
-        try:
-            self.start = int(start)
-        except ValueError:
-            self.start =  template.Variable(start)
-        self.num = int(num)
-        self.var_name = var_name
-
-    def render(self, context):
-        if type(self.start) != int:
-            try:
-                self.start =  int(self.start.resolve(context))
-            except template.VariableDoesNotExist:
-                return ''
-        get_list_function = Comment.objects.filter
-        kwargs = {
-            'is_public': True,
-            'is_removed': False,
-            'site__pk': settings.SITE_ID,
-            'content_type__app_label__exact': 'diario',
-            'content_type__model__exact': 'entry',
-        }
-        comment_list = get_list_function(**kwargs).select_related().order_by('-submit_date')
-        context[self.var_name] = comment_list[self.start:][:self.num]
-        return ''
-
-def do_get_diario_comment_list(parser, token):
-    """
-    Gets Diário's comment list and populates the template context with a
-    variable containing that value, whose name is defined by the 'as' clause.
-
-    Syntax::
-
-        {% get_diario_comment_list [num] (from the [start]) as [var_name] %}
-
-    Example usage to get latest comments::
-
-        {% get_diario_comment_list 10 as latest_diario_comments %}
-
-    To get old comments::
-
-        {% get_diario_comment_list 10 from the 10 as old_comments %}
-
-    To get previous comments from the last comment on page with
-    ``last_on_page`` context variable provided by ``object_list``, do::
-
-        {% get_diario_comment_list 10 from the last_on_page as old_comments %}
-
-    Note: The start point is omitted.
-    """
-    bits = token.contents.split()
-    if len(bits) == 4:
-        if bits[2] != 'as':
-            raise template.TemplateSyntaxError, "Second argument to '%s' tag must be 'as'" % bits[0]
-        return CommentListNode(bits[1], bits[3])
-    if len(bits) == 7:
-        if bits[2] != 'from' or bits[3] != 'the':
-            raise template.TemplateSyntaxError, "Second and third arguments to '%s' tag must be 'from the'" % bits[0]
-        if bits[5] != 'as':
-            raise template.TemplateSyntaxError, "Fifth argument to '%s' tag must be 'as'" % bits[0]
-        return CommentListNode(bits[1], bits[6], bits[4])
-    else:
-        raise template.TemplateSyntaxError, "'%s' tag takes three or six arguments" % bits[0]
-
-register.tag('get_diario_comment_list', do_get_diario_comment_list)

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.feeds import comments as 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.AtomCommentsFeed(),
-    name  = 'diario-comments-atom'
-)
-
-comments_rss = url(
-    regex = 'rss/$',
-    view  = feeds.RssCommentsFeed(),
-    name  ='diario-comments-rss'
-)
-
-
-urlpatterns = patterns('',
-    comments,
-    comments_atom, comments_rss
-)