def get_context_data(self, **kwargs): context = super(PostList, self).get_context_data(**kwargs) context['title'] = self.title or _( 'Page %d of Posts') % context['page_obj'].number context['first_page_href'] = reverse('home') context['page_prefix'] = reverse('blog_post_list') context['comments'] = Comment.most_recent(self.request.user, 10) context['new_problems'] = Problem.objects.filter( is_public=True, is_organization_private=False).order_by('-date', '-id')[:7] context['page_titles'] = CacheDict( lambda page: Comment.get_page_title(page)) context['has_clarifications'] = False if self.request.user.is_authenticated: participation = self.request.profile.current_contest if participation: clarifications = ProblemClarification.objects.filter( problem__in=participation.contest.problems.all()) context['has_clarifications'] = clarifications.count() > 0 context['clarifications'] = clarifications.order_by('-date') context['user_count'] = lazy(Profile.objects.count, int, long) context['problem_count'] = lazy( Problem.objects.filter(is_public=True).count, int, long) context['submission_count'] = lazy(Submission.objects.count, int, long) context['language_count'] = lazy(Language.objects.count, int, long) context['post_comment_counts'] = { int(page[2:]): count for page, count in Comment.objects.filter( page__in=['b:%d' % post.id for post in context['posts']], hidden=False).values_list('page').annotate( count=Count('page')).order_by() } now = timezone.now() visible_contests = Contest.contests_list( self.request.user).order_by('start_time') context['current_contests'] = visible_contests.filter( start_time__lte=now, end_time__gt=now) context['future_contests'] = visible_contests.filter( start_time__gt=now) if self.request.user.is_authenticated: context['own_open_tickets'] = Ticket.tickets_list( self.request.user, author=self.request.user) else: context['own_open_tickets'] = [] # Superusers better be staffs, not the spell-casting kind either. if self.request.user.is_staff: context['open_tickets'] = Ticket.tickets_list( self.request.user)[:10] else: context['open_tickets'] = [] return context
def get_context_data(self, **kwargs): context = super(PostList, self).get_context_data(**kwargs) context['title'] = self.title or _('Page %d of Posts') % context['page_obj'].number context['first_page_href'] = reverse('home') context['page_prefix'] = reverse('blog_post_list') context['new_problems'] = Problem.get_public_problems() \ .order_by('-date', '-id')[:settings.DMOJ_BLOG_NEW_PROBLEM_COUNT] context['has_clarifications'] = False if self.request.user.is_authenticated: participation = self.request.profile.current_contest if participation: clarifications = ProblemClarification.objects.filter(problem__in=participation.contest.problems.all()) context['has_clarifications'] = clarifications.count() > 0 context['clarifications'] = clarifications.order_by('-date') context['user_count'] = lazy(Profile.objects.count, int, int) context['problem_count'] = lazy(Problem.get_public_problems().count, int, int) context['submission_count'] = lazy(Submission.objects.count, int, int) context['language_count'] = lazy(Language.objects.count, int, int) now = timezone.now() visible_contests = Contest.get_visible_contests(self.request.user).order_by('start_time') context['current_contests'] = visible_contests.filter(start_time__lte=now, end_time__gt=now) context['future_contests'] = visible_contests.filter(start_time__gt=now) if self.request.user.is_authenticated: context['own_open_tickets'] = Ticket.tickets_list(self.request.user).filter(user=self.request.profile) else: context['own_open_tickets'] = [] # Superusers better be staffs, not the spell-casting kind either. if self.request.user.is_staff: context['open_tickets'] = Ticket.tickets_list(self.request.user)[:10] else: context['open_tickets'] = [] return context
def get_context_data(self, **kwargs): if not self.request.user.is_authenticated: raise Http404() user = self.request.user profile = self.request.profile context = super(UserDashboard, self).get_context_data(**kwargs) context['recently_attempted_problems'] = ( Submission.objects.filter( user=profile, problem__is_public=True).exclude( problem_id__in=user_completed_ids(profile)).values_list( 'problem__code', 'problem__name', 'problem__points').annotate( points=Max('points'), latest=Max('date')).order_by('-latest') [:settings.DMOJ_BLOG_RECENTLY_ATTEMPTED_PROBLEMS_COUNT]) context['own_tickets'] = Ticket.tickets_list(user).filter( user=profile)[:10] return context