Merge branch 'master' of https://github.com/LQDJudge/online-judge into pagevote

This commit is contained in:
Zhao-Linux 2022-11-18 02:17:56 +07:00
commit 8108967959
5 changed files with 35 additions and 13 deletions

View file

@ -128,6 +128,7 @@ class PostList(FeedView, PageVoteListView, BookMarkListView):
.annotate(count=Count("page")) .annotate(count=Count("page"))
.order_by() .order_by()
} }
context = self.add_pagevote_context_data(context)
return context return context

View file

@ -71,6 +71,7 @@ from judge.utils.problems import user_attempted_ids
from judge.views.problem import ProblemList from judge.views.problem import ProblemList
from judge.views.contests import ContestList from judge.views.contests import ContestList
from judge.views.submission import AllSubmissions, SubmissionsListBase from judge.views.submission import AllSubmissions, SubmissionsListBase
from judge.views.pagevote import PageVoteListView
__all__ = [ __all__ = [
"OrganizationList", "OrganizationList",
@ -265,10 +266,11 @@ class OrganizationList(TitleMixin, ListView, OrganizationBase):
return context return context
class OrganizationHome(OrganizationDetailView): class OrganizationHome(OrganizationDetailView, PageVoteListView):
template_name = "organization/home.html" template_name = "organization/home.html"
pagevote_object_name = "posts"
def get_posts(self): def get_posts_and_page_obj(self):
posts = ( posts = (
BlogPost.objects.filter( BlogPost.objects.filter(
visible=True, visible=True,
@ -282,12 +284,24 @@ class OrganizationHome(OrganizationDetailView):
paginator = Paginator(posts, 10) paginator = Paginator(posts, 10)
page_number = self.request.GET.get("page", 1) page_number = self.request.GET.get("page", 1)
posts = paginator.get_page(page_number) posts = paginator.get_page(page_number)
return posts return posts, paginator.page(page_number)
def get_comment_page(self, post):
return "b:%s" % post.id
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(OrganizationHome, self).get_context_data(**kwargs) context = super(OrganizationHome, self).get_context_data(**kwargs)
context["title"] = self.object.name context["title"] = self.object.name
context["posts"] = self.get_posts() context["posts"], context["page_obj"] = self.get_posts_and_page_obj()
context = self.add_pagevote_context_data(context, "posts")
# Hack: This allows page_obj to have page_range for non-ListView class
setattr(
context["page_obj"], "page_range", context["posts"].paginator.page_range
)
context["first_page_href"] = self.request.path
context["page_prefix"] = "?page="
context["post_comment_counts"] = { context["post_comment_counts"] = {
int(page[2:]): count int(page[2:]): count
for page, count in Comment.objects.filter( for page, count in Comment.objects.filter(
@ -311,6 +325,7 @@ class OrganizationHome(OrganizationDetailView):
) )
context["future_contests"] = visible_contests.filter(start_time__gt=now) context["future_contests"] = visible_contests.filter(start_time__gt=now)
context["page_type"] = "home" context["page_type"] = "home"
return context return context

View file

@ -109,12 +109,9 @@ class PageVoteDetailView(TemplateResponseMixin, SingleObjectMixin, View):
return context return context
class PageVoteListView(ListView): class PageVoteListView:
pagevote_page = None def add_pagevote_context_data(self, context, obj_list="object_list"):
for item in context[obj_list]:
def get_context_data(self, **kwargs):
context = super(PageVoteListView, self).get_context_data(**kwargs)
for item in context["object_list"]:
pagevote, _ = PageVote.objects.get_or_create( pagevote, _ = PageVote.objects.get_or_create(
page=self.get_comment_page(item) page=self.get_comment_page(item)
) )

View file

@ -947,6 +947,7 @@ class ProblemFeed(ProblemList, PageVoteListView, BookMarkListView):
context["feed_type"] = self.feed_type context["feed_type"] = self.feed_type
context["has_show_editorial_option"] = False context["has_show_editorial_option"] = False
context["has_have_editorial_option"] = False context["has_have_editorial_option"] = False
context = self.add_pagevote_context_data(context)
return context return context

View file

@ -2,6 +2,14 @@
{% block title_ruler %}{% endblock %} {% block title_ruler %}{% endblock %}
{% block org_js %}
{% include "actionbar/media-js.html" %}
{% endblock %}
{% block three_col_media %}
{% include "actionbar/media-css.html" %}
{% endblock %}
{% block middle_title %} {% block middle_title %}
<div class="page-title"> <div class="page-title">
<div class="tabs" style="border: none;"> <div class="tabs" style="border: none;">
@ -29,10 +37,10 @@
{% if is_member or can_edit %} {% if is_member or can_edit %}
{% for post in posts %} {% for post in posts %}
{% include "blog/content.html" %} {% include "blog/content.html" %}
{% if posts.paginator.num_pages > 1 %}
<div style="margin-bottom:10px;margin-top:10px">{% include "list-pages.html" %}</div>
{% endif %}
{% endfor %} {% endfor %}
{% if posts.paginator.num_pages > 1 %}
<div style="margin-bottom:10px;margin-top:10px">{% include "list-pages.html" %}</div>
{% endif %}
{% else %} {% else %}
<div class="blog-sidebox sidebox"> <div class="blog-sidebox sidebox">
<h3>{{ _('About') }}<i class="fa fa-info-circle"></i></h3> <h3>{{ _('About') }}<i class="fa fa-info-circle"></i></h3>