Ejemplo n.º 1
0
def toggle_subscribe(request, ajax=False):
    """
        Subscribe to receive notifications for an object (post, short review, thread).
        If already subscribed, the action unsubscribes to stop receiving notices.
    """
    if request.POST:
        if not request.user.is_authenticated():
            if ajax:
                return json_error('LOGIN')
            else:
                return HttpResponseRedirect(full_url('LOGIN') + '?next=%s&reason=vote' % request.path)

        from film20.useractivity.forms import SubscribeForm
        form = SubscribeForm(request.POST)
        valid = form.is_valid()

        if not valid:
            if ajax:
                return json_error("Form not valid") # TODO: pass error?
            else:
                return __return_to_object_view(request, form)

        watching_helper = WatchingHelper()
        watching_helper.alter_watching_subscribed(request.user, form.object)

        if ajax:
            return json_success()
        else:
            return __return_to_object_view(request, form)
    # Not a POST - fail!
    else:
        if ajax:
            return json_error("Not a POST request!");
        else:
            return __return_to_object_view(request)
Ejemplo n.º 2
0
def subscribe(request):
    if request.method == "POST":
        from .forms import SubscribeForm
        form = SubscribeForm(request.POST, user=request.user)
        if form.is_valid():
            logger.info("HERE: %r", form.cleaned_data)
            form.save()
        else:
            print form.errors
    if 'HTTP_X_REQUESTED_WITH' in request.META:
        return HttpResponse('ok')
    next = request.REQUEST.get('next', request.META.get('HTTP_REFERER'))
    return HttpResponseRedirect(next or '/')