def all_submissions_view(request): submissions = [] if request.user.is_authenticated: queryset = Submission.objects \ .filter(user=request.user) \ .select_related('user', 'problem_instance', 'problem_instance__contest', 'problem_instance__round', 'problem_instance__problem') submissions_list = filter_my_all_visible_submissions(request, queryset) if django.VERSION >= (1, 11): submissions_list = submissions_list.order_by('-date') else: submissions_list.sort(reverse=True, key=lambda s: s.date) for s in submissions_list: request.contest = s.problem_instance.contest submissions.append(submission_template_context(request, s)) request.contest = None show_scores = any(s['can_see_score'] for s in submissions) navbar_links = navbar_links_registry.template_context(request) return TemplateResponse(request, 'contests/my_submissions_all.html', {'submissions': submissions, 'show_scores': show_scores, 'submissions_on_page': getattr(settings, 'SUBMISSIONS_ON_PAGE', 100), 'navbar_links': navbar_links})
def main_page_view(request): navbar_links = navbar_links_registry.template_context(request) to_show = getattr(settings, 'NUM_RECENT_CONTESTS', 7) rcontests = recent_contests(request) contests = list(visible_contests(request).difference(rcontests)) contests.sort(key=lambda x: x.creation_date, reverse=True) contests = (rcontests + contests)[:to_show] submissions = [] show_scores = False if request.user.is_authenticated: queryset = Submission.objects.filter( user=request.user).order_by('-date') # current_contest = request.contest # # for s in queryset: # request.contest = "lakdnasdn"#s.problem_instance.contest # submissions.append(submission_template_context(request, s)) # # request.contest = current_contest to_show = getattr(settings, 'NUM_PANEL_SUBMISSIONS', 7) # limit queryset size, because filtering all submissions is slow queryset = queryset[:to_show] limit_queryset_ids = [submission.id for submission in queryset] queryset = Submission.objects.filter( id__in=limit_queryset_ids).select_related( 'user', 'problem_instance', 'problem_instance__contest', 'problem_instance__round', 'problem_instance__problem', ) submissions_list = filter_my_all_visible_submissions(request, queryset) if django.VERSION >= (1, 11): submissions_list = submissions_list.order_by('-date') else: submissions_list.sort(reverse=True, key=lambda s: s.date) submissions = [ submission_template_context(request, s) for s in submissions_list ] show_scores = any(s['can_see_score'] for s in submissions) context = { 'navbar_links': navbar_links, 'contests': contests, 'submissions': submissions, 'show_scores': show_scores, } return TemplateResponse(request, 'main-page.html', context)