コード例 #1
0
ファイル: views.py プロジェクト: tiriplicamihai/wouso
def challenge(request, id):
    """ Displays a challenge, only if status = accepted
    This is play """
    chall_user = request.user.get_profile().get_extension(ChallengeUser)

    chall = get_object_or_404(Challenge, pk=id)

    # check to see if challenge was already submitted
    try:
        participant = chall.participant_for_player(chall_user)
    except:
        raise Http404

    if participant.played:
        return do_result(
            request, _("You have already submitted this challenge" " and scored %.2f points") % participant.score
        )

    # this is caught by chall_user
    # if not chall_user.can_play(chall):
    #    return do_result(request, _('You cannot play this challenge.'))

    if request.method == "GET" and not chall.is_started_for_user(chall_user):
        chall.set_start(chall_user)

    if request.method == "POST":
        form = ChallengeForm(chall, request.POST)
        results = chall.set_played(chall_user, form.get_response())
        form.check_self_boxes()
        if results.get("results", False):
            results["results"] = form.get_results_in_order(results["results"])
            questions_and_answers = zip(form.visible_fields(), results["results"])
        else:
            questions_and_answers = None
        return render_to_response(
            "challenge/result.html",
            {
                "challenge": chall,
                "challenge_user": chall_user,
                "points": results["points"],
                "form": form,
                "questions_and_answers": questions_and_answers,
            },
            context_instance=RequestContext(request),
        )
    else:
        form = ChallengeForm(chall)

    seconds_left = chall.time_for_user(chall_user)
    return render_to_response(
        "challenge/challenge.html",
        {"challenge": chall, "form": form, "challenge_user": chall_user, "seconds_left": seconds_left},
        context_instance=RequestContext(request),
    )
コード例 #2
0
def challenge(request, id):
    """ Displays a challenge, only if status = accepted
    This is play """
    chall_user = request.user.get_profile().get_extension(ChallengeUser)

    chall = get_object_or_404(Challenge, pk=id)

    # check to see if challenge was already submitted
    try:
        participant = chall.participant_for_player(chall_user)
    except:
        raise Http404

    if participant.played:
        return do_result(request, _('You have already submitted this challenge'\
                                   ' and scored %.2f points') % participant.score)

    # this is caught by chall_user
    #if not chall_user.can_play(chall):
    #    return do_result(request, _('You cannot play this challenge.'))

    if request.method == 'GET' and not chall.is_started_for_user(chall_user):
        chall.set_start(chall_user)

    if request.method == "POST":
        form = ChallengeForm(chall, request.POST)
        results = chall.set_played(chall_user, form.get_response())
        form.check_self_boxes()
        if results.get('results', False):
            results['results'] = form.get_results_in_order(results['results'])
            questions_and_answers = zip(form.visible_fields(),
                                        results['results'])
        else:
            questions_and_answers = None
        return render_to_response(
            'challenge/result.html', {
                'challenge': chall,
                'challenge_user': chall_user,
                'points': results['points'],
                'form': form,
                'questions_and_answers': questions_and_answers
            },
            context_instance=RequestContext(request))
    else:
        form = ChallengeForm(chall)

    seconds_left = chall.time_for_user(chall_user)
    return render_to_response('challenge/challenge.html', {
        'challenge': chall,
        'form': form,
        'challenge_user': chall_user,
        'seconds_left': seconds_left
    },
                              context_instance=RequestContext(request))
コード例 #3
0
    def post(self, request, **kwargs):
        form = ChallengeForm(self.chall, request.POST)
        results = self.chall.set_played(self.chall_user, form.get_response())
        form.check_self_boxes()

        if results.get('results', False):
            results['results'] = form.get_results_in_order(results['results'])
            questions_and_answers = zip(form.visible_fields(), results['results'])
        else:
            questions_and_answers = None
        return render_to_response('challenge/result.html',
            {'challenge': self.chall, 'challenge_user': self.chall_user,
            'points': results['points'], 'form' : form,  'questions_and_answers' : questions_and_answers},
            context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: anaion/wouso
def challenge(request, id):
    """ Displays a challenge, only if status = accepted
    This is play """
    chall_user = request.user.get_profile().get_extension(ChallengeUser)

    chall = get_object_or_404(Challenge, pk=id)

    # check to see if challenge was already submitted
    try:
        participant = chall.participant_for_player(chall_user)
    except:
        raise Http404

    if participant.played:
        return do_result(request, _('You have already submitted this challenge'\
                                   ' and scored %.2f points') % participant.score)

    # this is caught by chall_user
    #if not chall_user.can_play(chall):
    #    return do_result(request, _('You cannot play this challenge.'))

    if request.method == 'GET' and not chall.is_started_for_user(chall_user):
        chall.set_start(chall_user)

    if request.method == "POST":
        form = ChallengeForm(chall, request.POST)
        results = chall.set_played(chall_user, form.get_response())
        form.check_self_boxes()
        results['results'] = form.get_results_in_order(results['results'])
        questions_and_answers = zip(form.visible_fields(), results['results'])

        return render_to_response('challenge/result.html',
            {'challenge': chall, 'challenge_user': chall_user, 'points': results['points'], 'form' : form,  'questions_and_answers' : questions_and_answers},
            context_instance=RequestContext(request))
    else:
        form = ChallengeForm(chall)

    seconds_left = chall.time_for_user(chall_user)
    return render_to_response('challenge/challenge.html',
            {'challenge': chall, 'form': form, 'challenge_user': chall_user, 'seconds_left': seconds_left},
            context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: TeodorMihai/wouso
    def post(self, request, **kwargs):
        form = ChallengeForm(self.chall, request.POST)
        results = self.chall.set_played(self.chall_user, form.get_response())
        form.check_self_boxes()

        if results.get("results", False):
            results["results"] = form.get_results_in_order(results["results"])
            questions_and_answers = zip(form.visible_fields(), results["results"])
        else:
            questions_and_answers = None
        return render_to_response(
            "challenge/result.html",
            {
                "challenge": self.chall,
                "challenge_user": self.chall_user,
                "points": results["points"],
                "form": form,
                "questions_and_answers": questions_and_answers,
            },
            context_instance=RequestContext(request),
        )