Esempio n. 1
0
def dislike(request, comment_id, next=None):
    """
    Dislike a comment. Confirmation on GET, action on POST.

    Templates: :template:`django_comments_xtd/dislike.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """
    comment = get_object_or_404(get_comment_model(), pk=comment_id,
                                site__pk=settings.SITE_ID)
    if not has_app_model_option(comment)['allow_feedback']:
        ctype = ContentType.objects.get_for_model(comment.content_object)
        raise Http404("Comments posted to instances of '%s.%s' are not "
                      "explicitly allowed to receive 'disliked it' flags. "
                      "Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
                      "setting." % (ctype.app_label, ctype.model))
    # Flag on POST
    if request.method == 'POST':
        perform_dislike(request, comment)
        return next_redirect(request,
                             fallback=(next or 'comments-xtd-dislike-done'),
                             c=comment.pk)
    # Render a form on GET
    else:
        disliked_it = request.user in comment.users_flagging(DISLIKEDIT_FLAG)
        return render(request, 'django_comments_xtd/dislike.html',
                      {'comment': comment,
                       'already_disliked_it': disliked_it,
                       'next': next})
Esempio n. 2
0
def dislike(request, comment_id, next=None):
    """
    Dislike a comment. Confirmation on GET, action on POST.

    Templates: :template:`django_comments_xtd/dislike.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """
    comment = get_object_or_404(get_comment_model(),
                                pk=comment_id,
                                site__pk=settings.SITE_ID)
    # Flag on POST
    if request.method == 'POST':
        perform_dislike(request, comment)
        return next_redirect(request,
                             fallback=(next or 'comments-xtd-dislike-done'),
                             c=comment.pk)
    # Render a form on GET
    else:
        already_disliked_it = request.user in comment.users_who_disliked_it()
        return render(
            request, 'django_comments_xtd/dislike.html', {
                'comment': comment,
                'already_disliked_it': already_disliked_it,
                'next': next
            })
Esempio n. 3
0
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(get_comment_model(),
                                pk=comment_id, site__pk=settings.SITE_ID)
    if not has_app_model_option(comment)['allow_flagging']:
        ctype = ContentType.objects.get_for_model(comment.content_object)
        raise Http404("Comments posted to instances of '%s.%s' are not "
                      "explicitly allowed to receive 'removal suggestion' "
                      "flags. Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
                      "setting." % (ctype.app_label, ctype.model))
    # Flag on POST
    if request.method == 'POST':
        perform_flag(request, comment)
        return next_redirect(request, fallback=next or 'comments-flag-done',
                             c=comment.pk)

    # Render a form on GET
    else:
        return render(request, 'comments/flag.html',
                      {'comment': comment,
                       'next': next})
Esempio n. 4
0
def like(request, comment_id, next=None):
    """
    Like a comment. Confirmation on GET, action on POST.

    Templates: :template:`django_comments_xtd/like.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """

    comment = get_object_or_404(get_comment_model(), pk=comment_id,
                                    site__pk=settings.SITE_ID)
    next = comment.get_absolute_url()
    if request.user.is_authenticated():
        if not has_app_model_option(comment)['allow_feedback']:
            ctype = ContentType.objects.get_for_model(comment.content_object)
            raise Http404("Comments posted to instances of '%s.%s' are not "
                          "explicitly allowed to receive 'liked it' flags. "
                          "Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
                          "setting." % (ctype.app_label, ctype.model))

        perform_like(request, comment)
        return next_redirect(request,
                             fallback=next or 'comments-xtd-like-done',
                             c=comment.pk)
    messages.error(request, '只有登录用户才能点赞, 请在侧边栏内登录再尝试点赞!', extra_tags='bg-warning text-warning')
    return next_redirect(request,
                         fallback=next or 'comments-xtd-like-done',
                         c=comment.pk)
Esempio n. 5
0
def like(request, comment_id, next=None):
    """
    Like a comment. Confirmation on GET, action on POST.

    Templates: :template:`django_comments_xtd/like.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """
    comment = get_object_or_404(get_comment_model(),
                                pk=comment_id,
                                site__pk=get_current_site_id(request))
    if not get_app_model_options(comment=comment)['allow_feedback']:
        ctype = ContentType.objects.get_for_model(comment.content_object)
        raise Http404("Comments posted to instances of '%s.%s' are not "
                      "explicitly allowed to receive 'liked it' flags. "
                      "Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
                      "setting." % (ctype.app_label, ctype.model))
    # Flag on POST
    if request.method == 'POST':
        perform_like(request, comment)
        return next_redirect(request,
                             fallback=next or 'comments-xtd-like-done',
                             c=comment.pk)
    # Render a form on GET
    else:
        flag_qs = comment.flags.prefetch_related('user')\
            .filter(flag=LIKEDIT_FLAG)
        users_likedit = [item.user for item in flag_qs]
        return render(
            request, 'django_comments_xtd/like.html', {
                'comment': comment,
                'already_liked_it': request.user in users_likedit,
                'next': next
            })
Esempio n. 6
0
def dislike(request, comment_id, next=None):
    """
    Dislike a comment. Confirmation on GET, action on POST.

    Templates: :template:`django_comments_xtd/dislike.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """
    comment = get_object_or_404(get_comment_model(), pk=comment_id,
                                site__pk=settings.SITE_ID)
    if not has_app_model_option(comment)['allow_feedback']:
        ctype = ContentType.objects.get_for_model(comment.content_object)
        raise Http404("Comments posted to instances of '%s.%s' are not "
                      "explicitly allowed to receive 'disliked it' flags. "
                      "Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
                      "setting." % (ctype.app_label, ctype.model))
    # Flag on POST
    if request.method == 'POST':
        perform_dislike(request, comment)
        return next_redirect(request,
                             fallback=(next or 'comments-xtd-dislike-done'),
                             c=comment.pk)
    # Render a form on GET
    else:
        disliked_it = request.user in comment.users_flagging(DISLIKEDIT_FLAG)
        return render(request, 'django_comments_xtd/dislike.html',
                      {'comment': comment,
                       'already_disliked_it': disliked_it,
                       'next': next})
Esempio n. 7
0
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(get_comment_model(),
                                pk=comment_id, site__pk=settings.SITE_ID)
    if not has_app_model_option(comment)['allow_flagging']:
        ctype = ContentType.objects.get_for_model(comment.content_object)
        raise Http404("Comments posted to instances of '%s.%s' are not "
                      "explicitly allowed to receive 'removal suggestion' "
                      "flags. Check the COMMENTS_XTD_APP_MODEL_OPTIONS "
                      "setting." % (ctype.app_label, ctype.model))
    # Flag on POST
    if request.method == 'POST':
        perform_flag(request, comment)
        return next_redirect(request, fallback=next or 'comments-flag-done',
                             c=comment.pk)

    # Render a form on GET
    else:
        return render(request, 'comments/flag.html',
                      {'comment': comment,
                       'next': next})
Esempio n. 8
0
def delete_own_comment(request, comment_id, next=None):
    comment = get_object_or_404(get_comment_model(),
                                pk=comment_id,
                                user=request.user,
                                site__pk=get_current_site(request).pk)

    # Delete on POST
    if request.method == 'POST':
        # Flag the comment as deleted instead of actually deleting it.
        if comment.user == request.user:
            comment.is_removed = True
            comment.save()

            flag, created = CommentFlag.objects.get_or_create(
                comment=comment,
                user=request.user,
                flag=CommentFlag.MODERATOR_DELETION
            )


            django_comments_signals.comment_was_flagged.send(
                sender=comment.__class__,
                comment=comment,
                flag=flag,
                created=created,
                request=request,
            )

        return next_redirect(request, fallback=next or 'comments-delete-done',
                             c=comment.pk)

    # Render a form on GET
    else:
        return render(request, 'comments/own_comment_delete.html', {'comment': comment, "next": next})
Esempio n. 9
0
def dislike(request, comment_id, next=None):
    """
    Dislike a comment. Confirmation on GET, action on POST.

    Templates: :template:`django_comments_xtd/dislike.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """
    comment = get_object_or_404(get_comment_model(), pk=comment_id,
                                site__pk=settings.SITE_ID)
    # Flag on POST
    if request.method == 'POST':
        perform_dislike(request, comment)
        return next_redirect(request,
                             fallback=(next or 'comments-xtd-dislike-done'),
                             c=comment.pk)
    # Render a form on GET
    else:
        already_disliked_it = request.user in comment.users_who_disliked_it()
        return render(request, 'django_comments_xtd/dislike.html',
                      {'comment': comment,
                       'already_disliked_it': already_disliked_it,
                       'next': next})
Esempio n. 10
0

from django_comments.models import CommentFlag
from django_comments.views.moderation import perform_flag
from django_comments.views.utils import next_redirect, confirmation_view

from django_comments_xtd import (get_form, comment_was_posted, signals, signed,
                                 get_model as get_comment_model)
from django_comments_xtd.conf import settings
from django_comments_xtd.models import (TmpXtdComment,
                                        MaxThreadLevelExceededException,
                                        LIKEDIT_FLAG, DISLIKEDIT_FLAG)
from django_comments_xtd.utils import send_mail, has_app_model_option


XtdComment = get_comment_model()


def get_moderated_tmpl(cmt):
    return [
        "django_comments_xtd/%s/%s/moderated.html" % (
            cmt.content_type.app_label, cmt.content_type.model),
        "django_comments_xtd/%s/moderated.html" % cmt.content_type.app_label,
        "django_comments_xtd/moderated.html"
    ]


def send_email_confirmation_request(
        comment, key, site,
        text_template="django_comments_xtd/email_confirmation_request.txt",
        html_template="django_comments_xtd/email_confirmation_request.html"):
Esempio n. 11
0
try:
    from urllib.parse import urlencode
except ImportError:
    from urllib import urlencode

from django.contrib.contenttypes.models import ContentType
from django.template import (Library, Node, TemplateSyntaxError,
                             Variable, loader)
from django.urls import reverse
from django.utils.safestring import mark_safe

from django_comments_xtd import get_model as get_comment_model
from django_comments_xtd.conf import settings
from django_comments_xtd.api import frontend

XtdComment = get_comment_model()


register = Library()


# ----------------------------------------------------------------------
class XtdCommentCountNode(Node):
    """Store the number of XtdComments for the given list of app.models"""

    def __init__(self, as_varname, content_types):
        """Class method to parse get_xtdcomment_list and return a Node."""
        self.as_varname = as_varname
        self.qs = XtdComment.objects.for_content_types(content_types,
                                                       site=settings.SITE_ID)
Esempio n. 12
0
def user_comments(request):
    curr_user = request.user
    XtdComment = get_comment_model()
    comments = XtdComment.objects.filter(user_id=curr_user.id)
    context = {'comments': comments}
    return render(request, 'user_comments.html', context)