Example #1
0
def mute(request, key):
    try:
        comment = signed.loads(str(key),
                               extra_key=settings.COMMENTS_XTD_SALT)
    except (ValueError, signed.BadSignature):
        raise Http404
    # the comment does exist if the URL was already confirmed, then: Http404
    if not comment.followup or not _comment_exists(comment):
        raise Http404

    # Send signal that the comment thread has been muted
    signals.comment_thread_muted.send(sender=XtdComment,
                                      comment=comment,
                                      request=request)

    XtdComment.objects.filter(
        content_type=comment.content_type, object_pk=comment.object_pk,
        is_public=True, followup=True, user_email=comment.user_email
    ).update(followup=False)

    model = apps.get_model(comment.content_type.app_label,
                           comment.content_type.model)
    target = model._default_manager.get(pk=comment.object_pk)

    template_arg = [
        "django_comments_xtd/%s/%s/muted.html" % (
            comment.content_type.app_label,
            comment.content_type.model),
        "django_comments_xtd/%s/muted.html" % (
            comment.content_type.app_label,),
        "django_comments_xtd/muted.html"
    ]
    return render(request, template_arg, {"content_object": target})
Example #2
0
def confirm(request, key, template_discarded="django_comments_xtd/discarded.html"):
    try:
        tmp_comment = signed.loads(key, extra_key=settings.COMMENTS_XTD_SALT)
    except (ValueError, signed.BadSignature):
        raise Http404

    # the comment does exist if the URL was already confirmed, then: Http404
    if _comment_exists(tmp_comment):
        raise Http404

    # Send signal that the comment confirmation has been received
    responses = signals.confirmation_received.send(sender  = TmpXtdComment,
                                                   comment = tmp_comment,
                                                   request = request
    )

    # Check whether a signal receiver decides to discard the contact_msg
    for (receiver, response) in responses:
        if response == False:
            return render_to_response(template_discarded, 
                                      {'comment': tmp_comment},
                                      context_instance=RequestContext(request))

    comment = _create_comment(tmp_comment)
    notify_comment_followers(comment)
    return redirect(comment)
Example #3
0
def confirm(request, key,
            template_discarded="django_comments_xtd/discarded.html"):
    try:
        tmp_comment = signed.loads(str(key),
                                   extra_key=settings.COMMENTS_XTD_SALT)
    except (ValueError, signed.BadSignature):
        raise Http404
    # the comment does exist if the URL was already confirmed, then: Http404
    if _comment_exists(tmp_comment):
        raise Http404
    # Send signal that the comment confirmation has been received
    responses = signals.confirmation_received.send(sender=TmpXtdComment,
                                                   comment=tmp_comment,
                                                   request=request)
    # Check whether a signal receiver decides to discard the comment
    for (receiver, response) in responses:
        if response is False:
            return render(request, template_discarded, {'comment': tmp_comment})

    comment = _create_comment(tmp_comment)
    if comment.is_public is False:
        return render(request, get_moderated_tmpl(comment),
                      {'comment': comment})
    else:
        notify_comment_followers(comment)
        return redirect(comment)
Example #4
0
def mute(request, key):
    try:
        tmp_comment = signed.loads(str(key),
                                   extra_key=settings.COMMENTS_XTD_SALT)
    except (ValueError, signed.BadSignature) as exc:
        return bad_request(request, exc)

    # Can't mute a comment that doesn't have the followup attribute
    # set to True, or a comment that doesn't exist.
    if not tmp_comment.followup or _get_comment_if_exists(tmp_comment) is None:
        raise Http404

    # Send signal that the comment thread has been muted
    signals.comment_thread_muted.send(sender=XtdComment,
                                      comment=tmp_comment,
                                      request=request)

    XtdComment.norel_objects.filter(content_type=tmp_comment.content_type,
                                    object_pk=tmp_comment.object_pk,
                                    user_email=tmp_comment.user_email,
                                    is_public=True,
                                    followup=True).update(followup=False)

    model = apps.get_model(tmp_comment.content_type.app_label,
                           tmp_comment.content_type.model)
    target = model._default_manager.get(pk=tmp_comment.object_pk)

    template_arg = [
        "django_comments_xtd/%s/%s/muted.html" %
        (tmp_comment.content_type.app_label, tmp_comment.content_type.model),
        "django_comments_xtd/%s/muted.html" %
        (tmp_comment.content_type.app_label, ),
        "django_comments_xtd/muted.html"
    ]
    return render(request, template_arg, {"content_object": target})
Example #5
0
def confirm(request,
            key,
            template_discarded="django_comments_xtd/discarded.html"):
    try:
        tmp_comment = signed.loads(str(key),
                                   extra_key=settings.COMMENTS_XTD_SALT)
    except (ValueError, signed.BadSignature) as exc:
        return bad_request(request, exc)

    # The comment does exist if the URL was already confirmed,
    # in such a case, as per suggested in ticket #80, we return
    # the comment's URL, as if the comment is just confirmed.
    comment = _get_comment_if_exists(tmp_comment)
    if comment is not None:
        return redirect(comment)

    # Send signal that the comment confirmation has been received.
    responses = signals.confirmation_received.send(sender=TmpXtdComment,
                                                   comment=tmp_comment,
                                                   request=request)
    # Check whether a signal receiver decides to discard the comment.
    for (receiver, response) in responses:
        if response is False:
            return render(request, template_discarded,
                          {'comment': tmp_comment})

    comment = _create_comment(tmp_comment)
    if comment.is_public is False:
        return render(request, get_moderated_tmpl(comment),
                      {'comment': comment})
    else:
        notify_comment_followers(comment)
        return redirect(comment)
Example #6
0
def mute(request, key):
    try:
        comment = signed.loads(str(key), 
                               extra_key=settings.COMMENTS_XTD_SALT)
    except (ValueError, signed.BadSignature):
        raise Http404
    # the comment does exist if the URL was already confirmed, then: Http404
    if not comment.followup or not _comment_exists(comment):
        raise Http404

    # Send signal that the comment thread has been muted
    signals.comment_thread_muted.send(sender=XtdComment,
                                      comment=comment,
                                      request=request)

    XtdComment.objects.filter(
        content_type=comment.content_type, object_pk=comment.object_pk, 
        is_public=True, followup=True, user_email=comment.user_email
    ).update(followup=False)

    model = models.get_model(comment.content_type.app_label,
                             comment.content_type.model)
    target = model._default_manager.get(pk=comment.object_pk)
    
    template_arg = [
        "django_comments_xtd/%s/%s/muted.html" % (
            comment.content_type.app_label, 
            comment.content_type.model),
        "django_comments_xtd/%s/muted.html" % (
            comment.content_type.app_label,),
        "django_comments_xtd/muted.html"
    ]
    return render_to_response(template_arg, 
                              {"content_object": target },
                              context_instance=RequestContext(request))
Example #7
0
def confirm(request, key, template_discarded="django_comments_xtd/discarded.html"):
    try:
        tmp_comment = signed.loads(key, extra_key=COMMENTS_XTD_SALT)
    except (ValueError, signed.BadSignature):
        raise Http404

    # the comment does exist if the URL was already confirmed, then: Http404
    if _comment_exists(tmp_comment):
        raise Http404

    # Send signal that the comment confirmation has been received
    responses = signals.confirmation_received.send(sender  = TmpXtdComment,
                                                   comment = tmp_comment,
                                                   request = request
    )

    # Check whether a signal receiver decides to discard the contact_msg
    for (receiver, response) in responses:
        if response == False:
            return render_to_response(template_discarded, 
                                      {'comment': tmp_comment},
                                      context_instance=RequestContext(request))

    comment = _create_comment(tmp_comment)
    notify_comment_followers(comment)
    return redirect(comment)
Example #8
0
def confirm(request, key,
            template_discarded="django_comments_xtd/discarded.html"):
    try:
        tmp_comment = signed.loads(str(key),
                                   extra_key=settings.COMMENTS_XTD_SALT)
    except (ValueError, signed.BadSignature):
        raise Http404
    # the comment does exist if the URL was already confirmed, then: Http404
    if _comment_exists(tmp_comment):
        raise Http404
    # Send signal that the comment confirmation has been received
    responses = signals.confirmation_received.send(sender=TmpXtdComment,
                                                   comment=tmp_comment,
                                                   request=request)
    # Check whether a signal receiver decides to discard the comment
    for (receiver, response) in responses:
        if response is False:
            return render(request, template_discarded, {'comment': tmp_comment})

    comment = _create_comment(tmp_comment)
    if comment.is_public is False:
        return render(request, get_moderated_tmpl(comment),
                      {'comment': comment})
    else:
        notify_comment_followers(comment)
        return redirect(comment)
Example #9
0
 def test_comment_is_created_and_view_redirect(self):
     # testing that visiting a correct confirmation URL creates a XtdComment
     # and redirects to the article detail page
     Site.objects.get_current().domain = "testserver"  # django bug #7743
     self.get_confirm_comment_url(self.key)
     data = signed.loads(self.key, extra_key=SALT)
     try:
         comment = XtdComment.objects.get(content_type=data["content_type"],
                                          user_name=data["user_name"],
                                          user_email=data["user_email"],
                                          submit_date=data["submit_date"])
     except:
         comment = None
     self.assert_(comment != None)
     self.assertRedirects(self.response, self.article.get_absolute_url())
Example #10
0
 def test_comment_is_created_and_view_redirect(self):
     # testing that visiting a correct confirmation URL creates a XtdComment
     # and redirects to the article detail page
     Site.objects.get_current().domain = "testserver"  # django bug #7743
     response = confirm_comment_url(self.key, follow=False)
     data = signed.loads(self.key, extra_key=settings.COMMENTS_XTD_SALT)
     try:
         comment = XtdComment.objects.get(content_type=data["content_type"],
                                          user_name=data["user_name"],
                                          user_email=data["user_email"],
                                          submit_date=data["submit_date"])
     except:
         comment = None
     self.assertTrue(comment is not None)
     self.assertEqual(response.url, comment.get_absolute_url())
Example #11
0
 def test_comment_is_created_and_view_redirect(self):
     # testing that visiting a correct confirmation URL creates a XtdComment
     # and redirects to the article detail page
     Site.objects.get_current().domain = "testserver" # django bug #7743
     self.get_confirm_comment_url(self.key)
     data = signed.loads(self.key, extra_key=SALT)
     try:
         comment = XtdComment.objects.get(
             content_type=data["content_type"], 
             user_name=data["user_name"],
             user_email=data["user_email"],
             submit_date=data["submit_date"])
     except:
         comment = None
     self.assert_(comment != None)
     self.assertRedirects(self.response, self.article.get_absolute_url())