Esempio n. 1
0
 def get_context_data(self, **kwargs):
     data = super(AccountList, self).get_context_data(**kwargs)
     data['keyword'] = self.request.GET.get('keyword')
     data['admin'] = self.request.GET.get('admin')
     for user in data["user_list"]:
         user.solved = get_accept_problem_count(user.pk)
     return data
Esempio n. 2
0
def home_view(request):
    if request.user.is_authenticated:
        ctx = {'solved': get_accept_problem_count(request.user.pk),
               'bulletin': site_settings_get('BULLETIN', ''),
               'global_rating': User.objects.filter(rating__gt=0).order_by("-rating")[:10],
               'update_log': UpdateLog.objects.all().order_by("-pk")[:10],
               'submission_count': Submission.objects.all().count()
               }
        if not is_site_closed(request):
            LIMIT, LIMIT_BLOG = 20, 15
            ctx['blog_list'] = Blog.objects.with_likes().with_likes_flag(request.user).select_related(
                "author").order_by("-create_time").filter(visible=True, recommend=True)[:LIMIT_BLOG]
            comment_list, blog_list = XtdComment.objects.filter(is_public=True, is_removed=False).order_by(
                "-submit_date").select_related("user", "content_type").prefetch_related('content_object').all()[:LIMIT], \
                                      Blog.objects.order_by("-create_time").select_related("author").filter(
                                          visible=True)[:LIMIT]
            ctx['comment_list'] = []
            i, j = 0, 0
            for k in range(LIMIT):
                if i < len(comment_list) and (j == len(blog_list) or (
                        j < len(blog_list) and comment_list[i].submit_date > blog_list[j].create_time)):
                    ctx['comment_list'].append(comment_list[i])
                    i += 1
                elif j < len(blog_list):
                    ctx['comment_list'].append(blog_list[j])
                    j += 1
                else:
                    break
            for comment in ctx['comment_list']:
                if isinstance(comment, XtdComment) and len(comment.comment) > LIMIT:
                    comment.comment = comment.comment[:LIMIT] + '...'
        return render(request, 'home_logged_in.jinja2', context=ctx)
    else:
        return render(request, 'home.jinja2', context={'bg': '/static/image/bg/%d.jpg' % randint(1, 14), })
Esempio n. 3
0
 def get_context_data(self, **kwargs):
     res = super(GenericView, self).get_context_data(**kwargs)
     res['profile'] = self.user
     res['solved'] = get_accept_problem_count(self.user.pk)
     if is_admin_or_root(self.request.user):
         res['is_privileged'] = True
     if self.request.user == self.user:
         res['is_author'] = res['is_privileged'] = True
     return res
Esempio n. 4
0
 def get_context_data(self, **kwargs):  # pylint: disable=arguments-differ
     res = super(GetRewardsView, self).get_context_data(**kwargs)
     res['profile'] = self.user
     res['solved'] = get_accept_problem_count(self.user.pk)
     if is_admin_or_root(self.request.user):
         res['is_privileged'] = True
     if self.request.user == self.user:
         res['is_author'] = res['is_privileged'] = True
     return res
Esempio n. 5
0
def home_view(request):
  if request.user.is_authenticated:
    ctx = {'solved': get_accept_problem_count(request.user.pk),
           'bulletin': site_settings_get('BULLETIN', ''),
           'global_rating': User.objects.filter(rating__gt=0).order_by("-rating")[:10],
           }
    if is_site_closed(request):
      return redirect(reverse("contest:list"))
    else:
      LIMIT, LIMIT_BLOG = 20, 15
      ctx['blog_list'] = Blog.objects.with_likes().with_likes_flag(request.user).select_related(
        "author").order_by("-create_time").filter(visible=True, recommend=True, is_reward=False)[:LIMIT_BLOG]
      # prefetch more comments
      comment_list = XtdComment.objects.filter(is_public=True, is_removed=False).order_by(
        "-submit_date").select_related("user", "content_type").prefetch_related('content_object').all()[:LIMIT * 2]
      blog_list = Blog.objects.order_by("-create_time").select_related("author").filter(
        visible=True, is_reward=False)[:LIMIT]
      ctx['comment_list'] = []
      i, j = 0, 0
      for _ in range(LIMIT):
        while i < len(comment_list) and \
            comment_list[i].content_type == ContentType.objects.get_for_model(Blog) and \
            Blog.objects.filter(pk=comment_list[i].object_pk, is_reward=True).exists():
          # Skip this comment
          i += 1
        # Merge comments and blogs in time order
        if i < len(comment_list) and (j == len(blog_list) or (
            j < len(blog_list) and comment_list[i].submit_date > blog_list[j].create_time)):
          ctx['comment_list'].append(comment_list[i])
          i += 1
        elif j < len(blog_list):
          ctx['comment_list'].append(blog_list[j])
          j += 1
        else:
          break
      for comment in ctx['comment_list']:
        if isinstance(comment, XtdComment) and len(comment.comment) > LIMIT:
          comment.comment = comment.comment[:LIMIT] + '...'
    return render(request, 'home_logged_in.jinja2', context=ctx)
  else:
    return render(request, 'home.jinja2', context={'bg': '/static/image/bg/%d.jpg' % randint(1, 14), })
Esempio n. 6
0
 def get_solved(self):
     return get_accept_problem_count(self.user.id)