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().get_context_data(**kwargs) context['unseen_count'] = self.unseen_cnt context['title'] = _('Notifications (%d unseen)' % context['unseen_count']) context['has_notifications'] = self.queryset.exists() context['page_titles'] = CacheDict( lambda page: Comment.get_page_title(page)) 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'))[:7] context['own_comments'] = Comment.most_recent(user, 10, author=user) context['page_titles'] = CacheDict( lambda page: Comment.get_page_title(page)) 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['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')[:settings.DMOJ_BLOG_NEW_PROBLEM_COUNT] 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, int) context['problem_count'] = lazy(Problem.objects.filter(is_public=True).count, int, int) context['submission_count'] = lazy(Submission.objects.count, int, int) context['language_count'] = lazy(Language.objects.count, int, int) 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() # Dashboard stuff if self.request.user.is_authenticated: user = self.request.profile context['recently_attempted_problems'] = (Submission.objects.filter(user=user) .exclude(problem__in=user_completed_ids(user)) .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]) visible_contests = Contest.get_visible_contests(self.request.user).filter(is_visible=True) \ .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: profile = self.request.profile context['own_open_tickets'] = (Ticket.objects.filter(user=profile, is_open=True).order_by('-id') .prefetch_related('linked_item').select_related('user__user')) else: profile = None context['own_open_tickets'] = [] # Superusers better be staffs, not the spell-casting kind either. if self.request.user.is_staff: tickets = (Ticket.objects.order_by('-id').filter(is_open=True).prefetch_related('linked_item') .select_related('user__user')) context['open_tickets'] = filter_visible_tickets(tickets, self.request.user, profile)[: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['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.user.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.objects.filter(is_public=True).count, int, int) context['submission_count'] = lazy(Submission.objects.count, int, int) context['language_count'] = lazy(Language.objects.count, int, int) 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() # Dashboard stuff if self.request.user.is_authenticated: user = self.request.user.profile context['recently_attempted_problems'] = (Submission.objects.filter(user=user) .exclude(problem__in=user_completed_ids(user)) .values_list('problem__code', 'problem__name', 'problem__points') .annotate(points=Max('points'), latest=Max('date')) .order_by('-latest'))[:7] visible_contests = Contest.objects.filter(is_public=True).order_by('start_time') q = Q(is_private=False) if self.request.user.is_authenticated: q |= Q(organizations__in=user.organizations.all()) visible_contests = visible_contests.filter(q) 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: profile = self.request.user.profile context['own_open_tickets'] = (Ticket.objects.filter(user=profile, is_open=True).order_by('-id') .prefetch_related('linked_item').select_related('user__user')) else: profile = None context['own_open_tickets'] = [] # Superusers better be staffs, not the spell-casting kind either. if self.request.user.is_staff: tickets = (Ticket.objects.order_by('-id').filter(is_open=True).prefetch_related('linked_item') .select_related('user__user')) context['open_tickets'] = filter_visible_tickets(tickets, self.request.user, profile)[:10] else: context['open_tickets'] = [] return context