コード例 #1
0
ファイル: views.py プロジェクト: manlan2/filmaster
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
ファイル: views.py プロジェクト: manlan2/filmaster
def follow(request, ajax=None):
    if request.method == "POST":
        try:
            user_id = int(request.POST.get("user_id"))
            user_to_follow = get_object_or_404(User, id=user_id)
            follow_val = int(request.POST.get("follow_val"))
            next = str(request.POST.get("next"))
            if follow_val == Followers.UNKNOWN:
                request.user.followers.remove(user_to_follow)
            if follow_val == Followers.FOLLOWING:
                request.user.followers.follow(user_to_follow)
            if ajax=="json":
                context = {
                        'success': True,
                        'data': request.user.id,
                    }
                logger.debug("Sending ajax response.")
                return json_return(context)
            else:
                return HttpResponseRedirect(next)
        except:
            if ajax=="json":
                return json_error()
            else:
                raise Http404
コード例 #3
0
ファイル: views.py プロジェクト: yangjiandong/filmaster
def show_game(request, contest_permalink=None, game_permalink=None, ajax=None):
    """
        Simple view that show a single game with options to
                vote for the characters
    """

    the_contest = None
    the_game_vote = None
    contest_helper = ContestHelper()

    if request.POST:
        if (not request.user.is_authenticated()):
            if ajax==None:
                return HttpResponseRedirect(full_url('LOGIN') + '?next=%s' % request.path)
            elif ajax=='json':
                return json_error("LOGIN")
        voting_form = VotingForm(request.POST)
        if voting_form is not None:
            logger.debug("Voting form submitted.")
            if voting_form.is_valid():
                logger.debug("Voting form valid.")
                contest_helper.vote(voting_form.the_game, voting_form.the_character, request.user)
                if ajax == "json":
                    context = {
                            'success': True,
                            'data': request.user.id,
                        }
                    logger.debug("Sending ajax response.")
                    return json_return(context)
            else:
                logger.debug("Voting form invalid.")
        else:
            logger.debug("Voting form not submitted.")

    try:
        if contest_permalink is None:
            the_contest = contest_helper.get_current_contest()
        else:
            the_contest = contest_helper.get_contest_by_permalink(contest_permalink)

        if game_permalink is None:
            the_game = contest_helper.get_game_for_date(the_contest, datetime.today())
        else:
            the_game = contest_helper.get_game_by_permalink(game_permalink)
        if request.user.is_authenticated():
            the_game_vote = contest_helper.get_vote_for_game(the_game, request.user)
        votes_for_character1 = contest_helper.get_votes_for_character_in_game(the_game, the_game.character1)
        votes_for_character2 = contest_helper.get_votes_for_character_in_game(the_game, the_game.character2)
        if the_game_vote is None:
            voting_form1 = contest_helper.prepare_voting_form1(the_game)
            voting_form2 = contest_helper.prepare_voting_form2(the_game)
        else:
            # no need for forms if already voted
            voting_form1 = None
            voting_form2 = None
    except NoOpenContestException, e:
        raise Http404
コード例 #4
0
ファイル: views.py プロジェクト: manlan2/filmaster
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' ) )