Пример #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)
Пример #2
0
def remove( request, id ):
    activity = get_object_or_404( UserActivity, pk=id )
    if activity.can_remove( request.user ):
        activity.remove( request.user )
        return json_success()
    return json_error( _( 'Cannot remove activity' ) )