Merge branch 'master' of https://github.com/LQDJudge/online-judge into pagevote
This commit is contained in:
commit
8108967959
5 changed files with 35 additions and 13 deletions
|
@ -128,6 +128,7 @@ class PostList(FeedView, PageVoteListView, BookMarkListView):
|
|||
.annotate(count=Count("page"))
|
||||
.order_by()
|
||||
}
|
||||
context = self.add_pagevote_context_data(context)
|
||||
|
||||
return context
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ from judge.utils.problems import user_attempted_ids
|
|||
from judge.views.problem import ProblemList
|
||||
from judge.views.contests import ContestList
|
||||
from judge.views.submission import AllSubmissions, SubmissionsListBase
|
||||
from judge.views.pagevote import PageVoteListView
|
||||
|
||||
__all__ = [
|
||||
"OrganizationList",
|
||||
|
@ -265,10 +266,11 @@ class OrganizationList(TitleMixin, ListView, OrganizationBase):
|
|||
return context
|
||||
|
||||
|
||||
class OrganizationHome(OrganizationDetailView):
|
||||
class OrganizationHome(OrganizationDetailView, PageVoteListView):
|
||||
template_name = "organization/home.html"
|
||||
pagevote_object_name = "posts"
|
||||
|
||||
def get_posts(self):
|
||||
def get_posts_and_page_obj(self):
|
||||
posts = (
|
||||
BlogPost.objects.filter(
|
||||
visible=True,
|
||||
|
@ -282,12 +284,24 @@ class OrganizationHome(OrganizationDetailView):
|
|||
paginator = Paginator(posts, 10)
|
||||
page_number = self.request.GET.get("page", 1)
|
||||
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):
|
||||
context = super(OrganizationHome, self).get_context_data(**kwargs)
|
||||
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"] = {
|
||||
int(page[2:]): count
|
||||
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["page_type"] = "home"
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
|
|
@ -109,12 +109,9 @@ class PageVoteDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
|||
return context
|
||||
|
||||
|
||||
class PageVoteListView(ListView):
|
||||
pagevote_page = None
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(PageVoteListView, self).get_context_data(**kwargs)
|
||||
for item in context["object_list"]:
|
||||
class PageVoteListView:
|
||||
def add_pagevote_context_data(self, context, obj_list="object_list"):
|
||||
for item in context[obj_list]:
|
||||
pagevote, _ = PageVote.objects.get_or_create(
|
||||
page=self.get_comment_page(item)
|
||||
)
|
||||
|
|
|
@ -947,6 +947,7 @@ class ProblemFeed(ProblemList, PageVoteListView, BookMarkListView):
|
|||
context["feed_type"] = self.feed_type
|
||||
context["has_show_editorial_option"] = False
|
||||
context["has_have_editorial_option"] = False
|
||||
context = self.add_pagevote_context_data(context)
|
||||
|
||||
return context
|
||||
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
{% 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 %}
|
||||
<div class="page-title">
|
||||
<div class="tabs" style="border: none;">
|
||||
|
@ -29,10 +37,10 @@
|
|||
{% if is_member or can_edit %}
|
||||
{% for post in posts %}
|
||||
{% include "blog/content.html" %}
|
||||
{% endfor %}
|
||||
{% if posts.paginator.num_pages > 1 %}
|
||||
<div style="margin-bottom:10px;margin-top:10px">{% include "list-pages.html" %}</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="blog-sidebox sidebox">
|
||||
<h3>{{ _('About') }}<i class="fa fa-info-circle"></i></h3>
|
||||
|
|
Loading…
Reference in a new issue