Exemplo n.º 1
0
    def dispatch(self, request, uidb36, token):
        # Checking the verify token and fetch the user
        assert uidb36 is not None and token is not None
        try:
            uid_int = base36_to_int(uidb36)
            user = User.objects.get(id=uid_int)
        except (ValueError, User.DoesNotExist):
            user = None
        if user is not None and token_generator.check_token(user, token):
            # validlink = True
            user.is_active = True
            user.save()
        else:
            # validlink = False
            raise User.DoesNotExist

        comments = CommentPlus.objects.filter(user=user).order_by("-submit_date")
        comments.update(is_public=True)
        comment = comments[0]
        model = models.get_model(comment.content_type.app_label, comment.content_type.model)
        target = model._default_manager.get(pk=comment.object_pk)

        # Notify followers
        notify_comment_followers(comment)

        if not request.user.is_authenticated():
            # Authentication
            user.backend = "kinsburg_tv.users.backends.ActivationBackend"
            auth_login(request, user)

        messages.add_message(request, messages.INFO, _("Your comment has successfully and the account activated!"))
        return redirect(reverse("film", kwargs={"pk": target.pk, "slug": target.slug}))
Exemplo n.º 2
0
    def dispatch(self, request, content_type_id, object_id):
        try:
            ctype = ContentType.objects.get(pk=content_type_id)
            target = ctype.get_object_for_this_type(pk=object_id)
        except ctype.model_class().DoesNotExist:
            raise Http404

        comments = CommentPlus.objects.filter(content_type_id=content_type_id, object_pk=object_id, user=request.user)
        if not comments.exists():
            return HttpResponseForbidden("<h1>403 Forbidden</h1>")

        # Unsubscribe!
        comments.update(followup=False)

        if request.GET.get("json", False):
            # If request from javascript, then reponse as JSON
            return self.render_to_response({"status": "success"})
        else:
            # Otherwise redirect to target url and draw message
            message = u"{}: {}".format(_("You have successfully unsubscribed from the comments to"), unicode(target))
            messages.add_message(request, messages.INFO, message)
            return redirect(target.get_absolute_url())