def get_paginator(self, queryset, per_page, orphans=0, allow_empty_first_page=True, **kwargs): paginator = DiggPaginator( queryset, per_page, body=6, padding=2, orphans=orphans, allow_empty_first_page=allow_empty_first_page, **kwargs) if not self.in_contest: # Get the number of pages and then add in this magic. # noinspection PyStatementEffect paginator.num_pages queryset = queryset.add_i18n_name(self.request.LANGUAGE_CODE) sort_key = self.order.lstrip('-') if sort_key in self.sql_sort: queryset = queryset.order_by(self.order) elif sort_key == 'name': queryset = queryset.order_by( self.order.replace('name', 'i18n_name')) elif sort_key == 'group': queryset = queryset.order_by(self.order + '__name') elif sort_key == 'solved': if self.request.user.is_authenticated: profile = self.request.user.profile solved = user_completed_ids(profile) attempted = user_attempted_ids(profile) def _solved_sort_order(problem): if problem.id in solved: return 1 if problem.id in attempted: return 0 return -1 queryset = list(queryset) queryset.sort(key=_solved_sort_order, reverse=self.order.startswith('-')) elif sort_key == 'type': if self.show_types: queryset = list(queryset) queryset.sort(key=lambda problem: problem.types_list[0] if problem.types_list else '', reverse=self.order.startswith('-')) paginator.object_list = queryset return paginator
def get_paginator(self, queryset, per_page, orphans=0, allow_empty_first_page=True, **kwargs): paginator = DiggPaginator(queryset, per_page, body=6, padding=2, orphans=orphans, allow_empty_first_page=allow_empty_first_page, **kwargs) if not self.in_contest: # Get the number of pages and then add in this magic. # noinspection PyStatementEffect paginator.num_pages queryset = queryset.add_i18n_name(self.request.LANGUAGE_CODE) sort_key = self.order.lstrip('-') if sort_key in self.sql_sort: queryset = queryset.order_by(self.order) elif sort_key == 'name': queryset = queryset.order_by(self.order.replace('name', 'i18n_name')) elif sort_key == 'group': queryset = queryset.order_by(self.order + '__name') elif sort_key == 'solved': if self.request.user.is_authenticated: profile = self.request.user.profile solved = user_completed_ids(profile) attempted = user_attempted_ids(profile) def _solved_sort_order(problem): if problem.id in solved: return 1 if problem.id in attempted: return 0 return -1 queryset = list(queryset) queryset.sort(key=_solved_sort_order, reverse=self.order.startswith('-')) elif sort_key == 'type': if self.show_types: queryset = list(queryset) queryset.sort(key=lambda problem: problem.types_list[0] if problem.types_list else '', reverse=self.order.startswith('-')) paginator.object_list = queryset return paginator
def get_attempted_problems(self): if self.in_contest: return contest_attempted_ids(self.profile.current_contest) else: return user_attempted_ids(self.profile) if self.profile is not None else ()
def get_attempted_problems(self): return user_attempted_ids( self.profile) if self.profile is not None else ()