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,)))
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
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' })
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))
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))
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))
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))
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))
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))
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, })
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, })
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))
def quest_points(user): try: return int(History.objects.filter(game=QuestGame.get_instance(), user=user).aggregate(points=Sum('amount'))['points']) except: return 0