def start_page(request, problem_id): create_problems() try: problem = Problem.objects.get(id=problem_id) except Problem.DoesNotExist: messages.warning(request, _('This problem doesn\'t seem to exist. ' 'we have redirected you to the main page.')) return redirect('home') article = problem.start flush_game_session(request.session) request.session['problem'] = problem.id request.session['path'] = [article] # not so well tested, so we are conservatives links = get_links(article) try: third = len(links)//3 links1 = links[:third] links2 = links[third:third*2] links3 = links[third*2:] except: links1 = links links2 = [] links3 = [] context = {'article': article, 'links1': links1, 'links2': links2, 'links3': links3, 'path': request.session['path'], 'problem': problem} return render(request, 'article.html', context)
def home(request): flush_game_session(request.session) create_problems() easy_problems = Problem.objects.filter(id__in=(1,2,3)) problems = Problem.objects.filter(id__in=(4,5,6,7,8)) hard_problems = Problem.objects.filter(id__in=(9,10)) return render(request, 'home.html', {'problems': problems, 'easy_problems': easy_problems, 'hard_problems': hard_problems})
def home(request): flush_game_session(request.session) create_problems() easy_problems = Problem.objects.filter(id__in=(1, 2, 3)) problems = Problem.objects.filter(id__in=(4, 5, 6, 7, 8)) hard_problems = Problem.objects.filter(id__in=(9, 10)) return render( request, 'home.html', { 'problems': problems, 'easy_problems': easy_problems, 'hard_problems': hard_problems })
def start_page(request, problem_id): create_problems() try: problem = Problem.objects.get(id=problem_id) except Problem.DoesNotExist: messages.warning( request, _('This problem doesn\'t seem to exist. ' 'we have redirected you to the main page.')) return redirect('home') article = problem.start flush_game_session(request.session) request.session['problem'] = problem.id request.session['path'] = [article] # not so well tested, so we are conservatives links = get_links(article) try: third = len(links) // 3 links1 = links[:third] links2 = links[third:third * 2] links3 = links[third * 2:] except: links1 = links links2 = [] links3 = [] context = { 'article': article, 'links1': links1, 'links2': links2, 'links3': links3, 'path': request.session['path'], 'problem': problem } return render(request, 'article.html', context)
def about(request): create_problems() # visit about to create the problems (HACK!!) return render(request, 'about.html')