예제 #1
0
def create_finale(request):
    if QuestGame.final_exists():
        fq = QuestGame.get_final()
    else:
        fq = FinalQuest.objects.create(start=datetime.datetime.now(), end=datetime.datetime.now())

    return HttpResponseRedirect(reverse('quest_edit', args=(fq.id,)))
예제 #2
0
파일: cpanel.py 프로젝트: MathPlayer/wouso
def create_finale(request):
    if QuestGame.final_exists():
        fq = QuestGame.get_final()
    else:
        fq = FinalQuest.objects.create(start=datetime.datetime.now(), end=datetime.datetime.now())

    return HttpResponseRedirect(reverse('quest_edit', args=(fq.id,)))
예제 #3
0
파일: cpanel.py 프로젝트: MathPlayer/wouso
 def get_context_data(self, **kwargs):
     context = super(QuestHomeView, self).get_context_data(**kwargs)
     final = QuestGame.get_final()
     context.update({'final': final,
                     'final_checker': settings.FINAL_QUEST_CHECKER_PATH,
                     'module': 'quest'})
     return context
예제 #4
0
 def get_context_data(self, **kwargs):
     context = super(QuestHomeView, self).get_context_data(**kwargs)
     final = QuestGame.get_final()
     context.update({'final': final,
                     'final_checker': settings.FINAL_QUEST_CHECKER_PATH,
                     'module': 'quest'})
     return context
예제 #5
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'
        })
예제 #6
0
def final_results(request):
    final = QuestGame.get_final()
    if not final:
        return render_to_response('quest/cpanel_final_results.html',
                                  context_instance=RequestContext(request))

    # fetch levels
    levels = []
    for level in xrange(len(final.levels) + 1):
        level_data = {'id': level, 'users': []}
        for user in QuestUser.objects.filter(current_quest=final,
                                             current_level=level):
            # Check finalquest bonus amount
            amount = History.objects.filter(
                user=user.user, formula__name='finalquest-ok').aggregate(
                    sum=Sum('amount'))['sum']
            user.amount = amount
            level_data['users'].append(user)
        levels.append(level_data)

    return render_to_response('quest/cpanel_final_results.html', {
        'quest': final,
        'module': 'quest',
        'levels': levels
    },
                              context_instance=RequestContext(request))
예제 #7
0
파일: views.py 프로젝트: anaion/wouso
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))
예제 #8
0
def final_score(request):
    final = QuestGame.get_final()
    if final:
        final.give_level_bonus()

    return render_to_response('quest/cpanel_final_results.html',
                              {'quest': final, 'done': True},
                            context_instance=RequestContext(request))
예제 #9
0
파일: cpanel.py 프로젝트: MathPlayer/wouso
def final_score(request):
    final = QuestGame.get_final()
    if final:
        final.give_level_bonus()

    return render_to_response('quest/cpanel_final_results.html',
                              {'quest': final, 'done': True},
                              context_instance=RequestContext(request))
예제 #10
0
파일: cpanel.py 프로젝트: cvicentiu/wouso
def quest_home(request):
    quests = Quest.objects.all()
    final = QuestGame.get_final()

    return render_to_response('quest/cpanel_home.html',
                              {'quests': quests,
                               'final': final,
                               'final_checker': settings.FINAL_QUEST_CHECKER_PATH,
                               'module': 'quest'},
                              context_instance=RequestContext(request))
예제 #11
0
def quest_home(request):
    quests = Quest.objects.all()
    final = QuestGame.get_final()

    return render_to_response('quest/cpanel_home.html', {
        'quests': quests,
        'final': final,
        'final_checker': settings.FINAL_QUEST_CHECKER_PATH,
        'module': 'quest'
    },
                              context_instance=RequestContext(request))
예제 #12
0
def final_results(request):
    final = QuestGame.get_final()
    if not final:
        return render_to_response('quest/cpanel_final_results.html',
                            context_instance=RequestContext(request))
    levels = final.fetch_levels()
    return render_to_response('quest/cpanel_final_results.html',
                              {'quest': final,
                               'module': 'quest',
                               'levels': levels},
                              context_instance=RequestContext(request))
예제 #13
0
파일: cpanel.py 프로젝트: MathPlayer/wouso
def final_results(request):
    final = QuestGame.get_final()
    if not final:
        return render_to_response('quest/cpanel_final_results.html',
                                  context_instance=RequestContext(request))
    levels = final.fetch_levels()
    return render_to_response('quest/cpanel_final_results.html',
                              {'quest': final,
                               'module': 'quest',
                               'levels': levels},
                              context_instance=RequestContext(request))
예제 #14
0
파일: views.py 프로젝트: alexef/wouso-1
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,
             })
예제 #15
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,
             })
예제 #16
0
파일: cpanel.py 프로젝트: cvicentiu/wouso
def final_results(request):
    final = QuestGame.get_final()
    if not final:
        return render_to_response('quest/cpanel_final_results.html',
                            context_instance=RequestContext(request))

    # fetch levels
    levels = []
    for level in xrange(len(final.levels) + 1):
        level_data = {'id': level, 'users': []}
        for user in QuestUser.objects.filter(current_quest=final, current_level=level):
            # Check finalquest bonus amount
            amount = History.objects.filter(user=user.user, formula__name='finalquest-ok').aggregate(sum=Sum('amount'))['sum']
            user.amount = amount
            level_data['users'].append(user)
        levels.append(level_data)

    return render_to_response('quest/cpanel_final_results.html',
                              {'quest': final,
                               'module': 'quest',
                               'levels': levels},
                              context_instance=RequestContext(request))
예제 #17
0
파일: views.py 프로젝트: iuliam/wouso
 def quest_points(user):
     try:
         return int(History.objects.filter(game=QuestGame.get_instance(),
             user=user).aggregate(points=Sum('amount'))['points'])
     except:
         return 0
예제 #18
0
 def quest_points(user):
     try:
         return int(History.objects.filter(game=QuestGame.get_instance(),
             user=user).aggregate(points=Sum('amount'))['points'])
     except:
         return 0