def contest_selection(context): request = context['request'] to_show = getattr(settings, 'NUM_RECENT_CONTESTS', 5) 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+1] default_contest = None if rcontests: default_contest = rcontests[0] elif contests: default_contest = contests[0] contest_selection_context = { 'contests': contests[:to_show], 'default_contest': default_contest, 'more_contests': len(contests) > to_show, 'is_teacher': request.user.has_perm('teachers.teacher'), 'is_inactive_teacher': request.user.is_authenticated and bool(Teacher.objects.filter(user=request.user, is_active=False)) } return RequestContext(request, contest_selection_context)
def render(self, request, m): rcontests = recent_contests(request) contests = list(visible_contests(request).difference(rcontests)) contests.sort(key=lambda x: x.creation_date, reverse=True) contests = (rcontests + contests)[:self.TO_SHOW + 1] default_contest = None if rcontests: default_contest = rcontests[0] elif contests: default_contest = contests[0] context = { 'contests': contests[:self.TO_SHOW], 'default_contest': default_contest, 'more_contests': len(contests) > self.TO_SHOW, 'is_teacher': request.user.has_perm('teachers.teacher'), 'is_inactive_teacher': request.user.is_authenticated() and bool( Teacher.objects.filter(user=request.user, is_active=False)) } return render_to_string('teachers/widgets/contest-selection.html', RequestContext(request, context))
def contest_selection(context): request = context['request'] to_show = getattr(settings, 'NUM_RECENT_CONTESTS', 5) 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 + 1] default_contest = None if rcontests: default_contest = rcontests[0] elif contests: default_contest = contests[0] contest_selection_context = { 'contests': contests[:to_show], 'default_contest': default_contest, 'more_contests': len(contests) > to_show, 'is_teacher': request.user.has_perm('teachers.teacher'), 'is_inactive_teacher': request.user.is_authenticated and bool(Teacher.objects.filter(user=request.user, is_active=False)) } return RequestContext(request, contest_selection_context)
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)
def reattach_problem_contest_list_view(request, problem_instance_id, full_list=False): problem_instance = get_object_or_404(ProblemInstance, id=problem_instance_id) if full_list: contests = Contest.objects.all() else: contests = recent_contests(request) or Contest.objects.all() contests = [c for c in contests if can_admin_contest(request.user, c)] return TemplateResponse(request, 'contests/reattach_problem_contest_list.html', {'problem_instance': problem_instance, 'contest_list': contests, 'full_list': full_list})
def _generate_add_to_contest_metadata(request): administered = administered_contests(request) # If user doesn't own any contest we won't show the option. if administered: show_add_button = True else: show_add_button = False # We want to show administered recent contests, because # these are most likely to be picked by an user. rcontests = recent_contests(request) administered_recent_contests = None if rcontests: administered_recent_contests = [ contest for contest in rcontests if request.user.has_perm("contests.contest_admin", contest) ] return show_add_button, administered_recent_contests
def _generate_add_to_contest_metadata(request): administered = administered_contests(request) # If user doesn't own any contest we won't show the option. if administered: show_add_button = True else: show_add_button = False # We want to show administered recent contests, because # these are most likely to be picked by an user. rcontests = recent_contests(request) administered_recent_contests = None if rcontests: administered_recent_contests = \ [contest for contest in rcontests if request.user.has_perm('contests.contest_admin', contest)] return show_add_button, administered_recent_contests
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') \ .select_related('user', 'problem_instance', 'problem_instance__contest', 'problem_instance__round', 'problem_instance__problem') # 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 submissions = [ submission_template_context(request, s) for s in queryset ] to_show = getattr(settings, 'NUM_PANEL_SUBMISSIONS', 7) submissions = submissions[:to_show] 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)
def generate_add_to_contest_metadata(request): """This generates all metadata needed for "add to contest" functionality in problemset. """ administered = administered_contests(request) # If user doesn't own any contest we won't show the option. if administered: show_add_button = True else: show_add_button = False # We want to show administered recent contests, because # these are most likely to be picked by an user. rcontests = recent_contests(request) administered_recent_contests = None if rcontests: administered_recent_contests = [ contest for contest in rcontests if request.user.has_perm('contests.contest_admin', contest) ] return show_add_button, administered_recent_contests
def render(self, request, m): contests = list(visible_contests(request)[:self.TO_SHOW]) rcontests = recent_contests(request) contests = rcontests + [c for c in contests if c not in rcontests] default_contest = None if rcontests: default_contest = rcontests[0] elif contests: default_contest = contests[0] context = { 'contests': contests[:self.TO_SHOW-1], 'default_contest': default_contest, 'more_contests': len(contests) > self.TO_SHOW-1, 'is_teacher': request.user.has_perm('teachers.teacher'), 'is_inactive_teacher': request.user.is_authenticated() and bool(Teacher.objects.filter(user=request.user, is_active=False)), } return render_to_string('portals/widgets/contest_selection.html', RequestContext(request, context))
def render(self, request, m): rcontests = recent_contests(request) contests = list(visible_contests(request).difference(rcontests)) contests.sort(key=lambda x: x.creation_date, reverse=True) contests = (rcontests + contests)[:self.TO_SHOW+1] default_contest = None if rcontests: default_contest = rcontests[0] elif contests: default_contest = contests[0] context = { 'contests': contests[:self.TO_SHOW], 'default_contest': default_contest, 'more_contests': len(contests) > self.TO_SHOW, 'is_teacher': request.user.has_perm('teachers.teacher'), 'is_inactive_teacher': request.user.is_authenticated() and bool(Teacher.objects.filter(user=request.user, is_active=False)) } return render_to_string('portals/widgets/contest_selection.html', RequestContext(request, context))