diff --git a/judge/views/blog.py b/judge/views/blog.py index 8bdb261..89cc151 100644 --- a/judge/views/blog.py +++ b/judge/views/blog.py @@ -127,6 +127,7 @@ class PostList(FeedView, PageVoteListView): .annotate(count=Count("page")) .order_by() } + context = self.add_pagevote_context_data(context) return context diff --git a/judge/views/organization.py b/judge/views/organization.py index b61569e..486bf77 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -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 diff --git a/judge/views/pagevote.py b/judge/views/pagevote.py index a7f9a9f..f749978 100644 --- a/judge/views/pagevote.py +++ b/judge/views/pagevote.py @@ -115,12 +115,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) ) diff --git a/judge/views/problem.py b/judge/views/problem.py index ee5c19c..8b922b6 100644 --- a/judge/views/problem.py +++ b/judge/views/problem.py @@ -945,6 +945,7 @@ class ProblemFeed(ProblemList, PageVoteListView): 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 diff --git a/templates/organization/home.html b/templates/organization/home.html index 49b1d15..8a0d5e5 100644 --- a/templates/organization/home.html +++ b/templates/organization/home.html @@ -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 %}
@@ -29,10 +37,10 @@ {% if is_member or can_edit %} {% for post in posts %} {% include "blog/content.html" %} - {% if posts.paginator.num_pages > 1 %} -
{% include "list-pages.html" %}
- {% endif %} {% endfor %} + {% if posts.paginator.num_pages > 1 %} +
{% include "list-pages.html" %}
+ {% endif %} {% else %}