Exemplo n.º 1
0
def index(request):
    quest = QuestGame.get_current()

    if quest == None:
        return render_to_response('quest/none.html', context_instance=RequestContext(request))

    quest_user = request.user.get_profile().get_extension(QuestUser)
    if quest_user.current_quest is None:
        quest_user.set_current(quest)
    elif not quest_user.current_quest.is_active:
        quest_user.finish_quest()
        quest_user.set_current(quest)

    error = ''
    if request.method == "POST":
        form = QuestForm(request.POST)
        if form.is_valid():
            answer = form.cleaned_data['answer']
            check = quest.check_answer(quest_user, answer)
            if not check:
                error = "Wrong answer, try again"
        else:
            error = "Invalid form"

    form = QuestForm()

    return render_to_response('quest/index.html',
            {'quest': quest, 'progress': quest_user, 'form': form, 'error': error},
            context_instance=RequestContext(request))
Exemplo n.º 2
0
def sidebar_widget(context):
    user = context.get('user', None)
    quest = QuestGame.get_current()

    if quest is None or user is None or not user.is_authenticated():
        return ''

    quest_user = user.get_profile().get_extension(QuestUser)
    if not quest_user.started:
        quest_progress = None
    else:
        quest_progress = 1.0 * quest_user.current_level / quest.count * 100

    if quest_user.finished and (quest_user.is_current(quest)):
        time_passed = datetime.now() - quest_user.finished_time
        if time_passed > timedelta(seconds=600):  # ten minutes
            return ''

    return render_to_string(
        'quest/sidebar.html', {
            'quest': quest,
            'quser': quest_user,
            'quest_progress': quest_progress,
            'id': 'quest'
        })
Exemplo n.º 3
0
def sidebar_widget(request):
    quest = QuestGame.get_current()

    if quest is None:
       return ''

    quest_user = request.user.get_profile().get_extension(QuestUser)
    if not quest_user.started:
        quest_progress = None
    else:
        quest_progress = 1.0 * quest_user.current_level / quest.count * 100

    if quest_user.finished and (quest_user.is_current(quest)):
        time_passed = datetime.now() - quest_user.finished_time
        if time_passed > timedelta(seconds=600): # ten minutes
            return ''

    return render_to_string('quest/sidebar.html',
            {'quest': quest, 'quser': quest_user,
             'quest_progress': quest_progress,
             })
Exemplo n.º 4
0
def sidebar_widget(request):
    quest = QuestGame.get_current()

    if quest is None:
        return ''

    quest_user = request.user.get_profile().get_extension(QuestUser)
    if not quest_user.started:
        quest_progress = None
    else:
        quest_progress = 1.0 * quest_user.current_level / quest.count * 100

    if quest_user.finished and (quest_user.current_quest == quest):
        time_passed = datetime.now() - quest_user.finished_time
        if time_passed > timedelta(seconds=600): # ten minutes
            return ''

    return render_string('quest/sidebar.html',
            {'quest': quest, 'quser': quest_user,
             'quest_progress': quest_progress,
             })