コード例 #1
0
ファイル: moderation.py プロジェクト: timothyclemans/djangocg
    def connect(self):
        """
        Hook up the moderation methods to pre- and post-save signals
        from the comment models.

        """
        signals.comment_will_be_posted.connect(self.pre_save_moderation, sender=comments.get_model())
        signals.comment_was_posted.connect(self.post_save_moderation, sender=comments.get_model())
コード例 #2
0
ファイル: feeds.py プロジェクト: timothyclemans/djangocg
 def items(self):
     qs = comments.get_model().objects.filter(
         site__pk = settings.SITE_ID,
         is_public = True,
         is_removed = False,
     )
     return qs.order_by('-submit_date')[:40]
コード例 #3
0
ファイル: comments.py プロジェクト: timothyclemans/djangocg
 def __init__(self, ctype=None, object_pk_expr=None, object_expr=None, as_varname=None, comment=None):
     if ctype is None and object_expr is None:
         raise template.TemplateSyntaxError("Comment nodes must be given either a literal object or a ctype and object pk.")
     self.comment_model = comments.get_model()
     self.as_varname = as_varname
     self.ctype = ctype
     self.object_pk_expr = object_pk_expr
     self.object_expr = object_expr
     self.comment = comment
コード例 #4
0
ファイル: utils.py プロジェクト: timothyclemans/djangocg
 def confirmed(request):
     comment = None
     if 'c' in request.GET:
         try:
             comment = comments.get_model().objects.get(pk=request.GET['c'])
         except (ObjectDoesNotExist, ValueError):
             pass
     return render_to_response(template,
         {'comment': comment},
         context_instance=RequestContext(request)
     )
コード例 #5
0
ファイル: moderation.py プロジェクト: timothyclemans/djangocg
def flag(request, comment_id, next=None):
    """
    Flags a comment. Confirmation on GET, action on POST.

    Templates: :template:`comments/flag.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """
    comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)

    # Flag on POST
    if request.method == 'POST':
        perform_flag(request, comment)
        return next_redirect(request.POST.copy(), next, flag_done, c=comment.pk)

    # Render a form on GET
    else:
        return render_to_response('comments/flag.html',
            {'comment': comment, "next": next},
            template.RequestContext(request)
        )
コード例 #6
0
ファイル: moderation.py プロジェクト: timothyclemans/djangocg
def approve(request, comment_id, next=None):
    """
    Approve a comment (that is, mark it as public and non-removed). Confirmation
    on GET, action on POST. Requires the "can moderate comments" permission.

    Templates: :template:`comments/approve.html`,
    Context:
        comment
            the `comments.comment` object for approval
    """
    comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)

    # Delete on POST
    if request.method == 'POST':
        # Flag the comment as approved.
        perform_approve(request, comment)
        return next_redirect(request.POST.copy(), next, approve_done, c=comment.pk)

    # Render a form on GET
    else:
        return render_to_response('comments/approve.html',
            {'comment': comment, "next": next},
            template.RequestContext(request)
        )
コード例 #7
0
ファイル: moderation.py プロジェクト: timothyclemans/djangocg
def delete(request, comment_id, next=None):
    """
    Deletes a comment. Confirmation on GET, action on POST. Requires the "can
    moderate comments" permission.

    Templates: :template:`comments/delete.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """
    comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)

    # Delete on POST
    if request.method == 'POST':
        # Flag the comment as deleted instead of actually deleting it.
        perform_delete(request, comment)
        return next_redirect(request.POST.copy(), next, delete_done, c=comment.pk)

    # Render a form on GET
    else:
        return render_to_response('comments/delete.html',
            {'comment': comment, "next": next},
            template.RequestContext(request)
        )
コード例 #8
0
    def testGetModel(self):
        from regressiontests.comment_tests.custom_comments.models import CustomComment

        self.assertEqual(comments.get_model(), CustomComment)
コード例 #9
0
ファイル: admin.py プロジェクト: timothyclemans/djangocg
    def approve_comments(self, request, queryset):
        self._bulk_flag(request, queryset, perform_approve,
                        lambda n: ungettext('approved', 'approved', n))
    approve_comments.short_description = _("Approve selected comments")

    def remove_comments(self, request, queryset):
        self._bulk_flag(request, queryset, perform_delete,
                        lambda n: ungettext('removed', 'removed', n))
    remove_comments.short_description = _("Remove selected comments")

    def _bulk_flag(self, request, queryset, action, done_message):
        """
        Flag, approve, or remove some comments from an admin action. Actually
        calls the `action` argument to perform the heavy lifting.
        """
        n_comments = 0
        for comment in queryset:
            action(request, comment)
            n_comments += 1

        msg = ungettext('1 comment was successfully %(action)s.',
                        '%(count)s comments were successfully %(action)s.',
                        n_comments)
        self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)})

# Only register the default admin if the model is the built-in comment model
# (this won't be true if there's a custom comment app).
if get_model() is Comment:
    admin.site.register(Comment, CommentsAdmin)