예제 #1
0
파일: comments.py 프로젝트: tikul/site
    def get_context_data(self, **kwargs):
        context = super(CommentedDetailView, self).get_context_data(**kwargs)
        queryset = Comment.objects.filter(page=self.get_comment_page())
        context['has_comments'] = queryset.exists()
        queryset = queryset.select_related('author__user').defer('author__about').annotate(revisions=Count('versions'))

        if self.request.user.is_authenticated:
            queryset = queryset.annotate(vote_score=Coalesce(RawSQLColumn(CommentVote, 'score'), Value(0)))
            profile = self.request.user.profile
            unique_together_left_join(queryset, CommentVote, 'comment', 'voter', profile.id)
            context['is_new_user'] = (not self.request.user.is_staff and
                                      not profile.submission_set.filter(points=F('problem__points')).exists())
        context['comment_list'] = queryset

        return context
예제 #2
0
 def add_i18n_name(self, language):
     queryset = self._clone()
     alias = unique_together_left_join(queryset, ProblemTranslation,
                                       'problem', 'language', language)
     return queryset.annotate(
         i18n_name=Coalesce(RawSQL('%s.name' % alias, ()),
                            F('name'),
                            output_field=models.CharField()))
예제 #3
0
파일: problem.py 프로젝트: ziap/tgboj
 def add_problem_i18n_name(self, key, language, name_field=None):
     queryset = self._clone() if name_field is None else self.annotate(_name=F(name_field))
     alias = unique_together_left_join(queryset, ProblemTranslation, 'problem', 'language', language,
                                       parent_model=Problem)
     # You must specify name_field if Problem is not yet joined into the QuerySet.
     kwargs = {key: Coalesce(RawSQL('%s.name' % alias, ()),
                             F(name_field) if name_field else RawSQLColumn(Problem, 'name'),
                             output_field=models.CharField())}
     return queryset.annotate(**kwargs)
예제 #4
0
파일: problem.py 프로젝트: DMOJ/site
 def add_problem_i18n_name(self, key, language, name_field=None):
     queryset = self._clone() if name_field is None else self.annotate(_name=F(name_field))
     alias = unique_together_left_join(queryset, ProblemTranslation, 'problem', 'language', language,
                                       parent_model=Problem)
     # You must specify name_field if Problem is not yet joined into the QuerySet.
     kwargs = {key: Coalesce(RawSQL('%s.name' % alias, ()),
                             F(name_field) if name_field else RawSQLColumn(Problem, 'name'),
                             output_field=models.CharField())}
     return queryset.annotate(**kwargs)
예제 #5
0
    def get_context_data(self, **kwargs):
        context = super(CommentedDetailView, self).get_context_data(**kwargs)
        queryset = Comment.objects.filter(page=self.get_comment_page())
        context['has_comments'] = queryset.exists()
        queryset = queryset.select_related('author__user').defer('author__about').annotate(revisions=Count('versions'))

        # This version uses public Django interface, but it requires support on the model.
        #if self.request.user.is_authenticated():
        #    votes = CommentVote.objects.filter(voter=self.request.user.profile)
        #else:
        #    votes = CommentVote.objects.none()
        #context['comment_list'] = queryset.prefetch_related(Prefetch('votes', queryset=votes))

        # This version digs into django internals.
        if self.request.user.is_authenticated():
            queryset = queryset.annotate(vote_score=Coalesce(RawSQLColumn(CommentVote, 'score'), Value(0)))
            unique_together_left_join(queryset, CommentVote, 'comment', 'voter', self.request.user.profile.id)
        context['comment_list'] = queryset

        return context
예제 #6
0
    def get_context_data(self, **kwargs):
        context = super(CommentedDetailView, self).get_context_data(**kwargs)
        queryset = Comment.objects.filter(hidden=False,
                                          page=self.get_comment_page())
        context['has_comments'] = queryset.exists()
        context['comment_lock'] = self.is_comment_locked()
        queryset = queryset.select_related('author__user').defer(
            'author__about').annotate(revisions=Count('versions'))

        if self.request.user.is_authenticated:
            queryset = queryset.annotate(vote_score=Coalesce(
                RawSQLColumn(CommentVote, 'score'), Value(0)))
            profile = self.request.profile
            unique_together_left_join(queryset, CommentVote, 'comment',
                                      'voter', profile.id)
            context[
                'is_new_user'] = not self.request.user.is_staff and not profile.has_any_solves
        context['comment_list'] = queryset
        context[
            'vote_hide_threshold'] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD

        return context
예제 #7
0
    def get_context_data(self, **kwargs):
        context = super(CommentedDetailView, self).get_context_data(**kwargs)
        queryset = Comment.objects.filter(page=self.get_comment_page())
        context['has_comments'] = queryset.exists()
        queryset = queryset.select_related('author__user').defer(
            'author__about').annotate(revisions=Count('versions'))

        # This version uses public Django interface, but it requires support on the model.
        #if self.request.user.is_authenticated():
        #    votes = CommentVote.objects.filter(voter=self.request.user.profile)
        #else:
        #    votes = CommentVote.objects.none()
        #context['comment_list'] = queryset.prefetch_related(Prefetch('votes', queryset=votes))

        # This version digs into django internals.
        if self.request.user.is_authenticated():
            queryset = queryset.annotate(vote_score=Coalesce(
                RawSQLColumn(CommentVote, 'score'), Value(0)))
            unique_together_left_join(queryset, CommentVote, 'comment',
                                      'voter', self.request.user.profile.id)
        context['comment_list'] = queryset

        return context
예제 #8
0
파일: problem.py 프로젝트: ziap/tgboj
 def add_i18n_name(self, language):
     queryset = self._clone()
     alias = unique_together_left_join(queryset, ProblemTranslation, 'problem', 'language', language)
     return queryset.annotate(i18n_name=RawSQL('%s.name' % alias, ()))
예제 #9
0
파일: problem.py 프로젝트: DMOJ/site
 def add_i18n_name(self, language):
     queryset = self._clone()
     alias = unique_together_left_join(queryset, ProblemTranslation, 'problem', 'language', language)
     return queryset.annotate(i18n_name=Coalesce(RawSQL('%s.name' % alias, ()), F('name'),
                                                 output_field=models.CharField()))