Infinite scrolling and comment migration
This commit is contained in:
parent
4b558bd656
commit
799ff5f8f8
33 changed files with 639 additions and 556 deletions
|
@ -72,9 +72,7 @@ from judge.utils.problems import user_attempted_ids, user_completed_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
|
||||
from judge.views.bookmark import BookMarkListView
|
||||
|
||||
from judge.views.feed import FeedView
|
||||
|
||||
__all__ = [
|
||||
"OrganizationList",
|
||||
|
@ -194,7 +192,7 @@ class MemberOrganizationMixin(OrganizationMixin):
|
|||
)
|
||||
|
||||
|
||||
class OrganizationHomeViewContext:
|
||||
class OrganizationHomeView(OrganizationMixin):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
if not hasattr(self, "organization"):
|
||||
|
@ -221,28 +219,6 @@ class OrganizationHomeViewContext:
|
|||
return context
|
||||
|
||||
|
||||
class OrganizationDetailView(
|
||||
OrganizationMixin, OrganizationHomeViewContext, DetailView
|
||||
):
|
||||
context_object_name = "organization"
|
||||
model = Organization
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if self.object.slug != kwargs["slug"]:
|
||||
return HttpResponsePermanentRedirect(
|
||||
request.get_full_path().replace(kwargs["slug"], self.object.slug)
|
||||
)
|
||||
context = self.get_context_data(object=self.object)
|
||||
return self.render_to_response(context)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["can_edit"] = self.can_edit_organization()
|
||||
context["is_member"] = self.is_member()
|
||||
return context
|
||||
|
||||
|
||||
class OrganizationList(TitleMixin, ListView, OrganizationBase):
|
||||
model = Organization
|
||||
context_object_name = "organizations"
|
||||
|
@ -272,51 +248,50 @@ class OrganizationList(TitleMixin, ListView, OrganizationBase):
|
|||
return context
|
||||
|
||||
|
||||
class OrganizationHome(OrganizationDetailView, PageVoteListView, BookMarkListView):
|
||||
class OrganizationHome(OrganizationHomeView, FeedView):
|
||||
template_name = "organization/home.html"
|
||||
pagevote_object_name = "posts"
|
||||
paginate_by = 4
|
||||
context_object_name = "posts"
|
||||
feed_content_template_name = "blog/content.html"
|
||||
|
||||
def get_posts_and_page_obj(self):
|
||||
posts = (
|
||||
def get_queryset(self):
|
||||
return (
|
||||
BlogPost.objects.filter(
|
||||
visible=True,
|
||||
publish_on__lte=timezone.now(),
|
||||
is_organization_private=True,
|
||||
organizations=self.object,
|
||||
organizations=self.organization,
|
||||
)
|
||||
.order_by("-sticky", "-publish_on")
|
||||
.prefetch_related("authors__user", "organizations")
|
||||
)
|
||||
paginator = Paginator(posts, 10)
|
||||
page_number = self.request.GET.get("page", 1)
|
||||
posts = paginator.get_page(page_number)
|
||||
return posts, paginator.page(page_number)
|
||||
|
||||
def get_comment_page(self, post):
|
||||
return "b:%s" % post.id
|
||||
|
||||
def get_feed_context(self, object_list):
|
||||
post_comment_counts = {
|
||||
int(page[2:]): count
|
||||
for page, count in Comment.objects.filter(
|
||||
page__in=["b:%d" % post.id for post in object_list], hidden=False
|
||||
)
|
||||
.values_list("page")
|
||||
.annotate(count=Count("page"))
|
||||
.order_by()
|
||||
}
|
||||
return {"post_comment_counts": post_comment_counts}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(OrganizationHome, self).get_context_data(**kwargs)
|
||||
context["title"] = self.object.name
|
||||
context["title"] = self.organization.name
|
||||
http = "http" if settings.DMOJ_SSL == 0 else "https"
|
||||
context["organization_subdomain"] = (
|
||||
http
|
||||
+ "://"
|
||||
+ self.object.slug
|
||||
+ self.organization.slug
|
||||
+ "."
|
||||
+ get_current_site(self.request).domain
|
||||
)
|
||||
context["posts"], context["page_obj"] = self.get_posts_and_page_obj()
|
||||
context = self.add_pagevote_context_data(context, "posts")
|
||||
context = self.add_bookmark_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(
|
||||
|
@ -331,7 +306,9 @@ class OrganizationHome(OrganizationDetailView, PageVoteListView, BookMarkListVie
|
|||
visible_contests = (
|
||||
Contest.get_visible_contests(self.request.user)
|
||||
.filter(
|
||||
is_visible=True, is_organization_private=True, organizations=self.object
|
||||
is_visible=True,
|
||||
is_organization_private=True,
|
||||
organizations=self.organization,
|
||||
)
|
||||
.order_by("start_time")
|
||||
)
|
||||
|
@ -344,11 +321,27 @@ class OrganizationHome(OrganizationDetailView, PageVoteListView, BookMarkListVie
|
|||
return context
|
||||
|
||||
|
||||
class OrganizationUsers(QueryStringSortMixin, OrganizationDetailView):
|
||||
class OrganizationUsers(QueryStringSortMixin, OrganizationMixin, FeedView):
|
||||
template_name = "organization/users.html"
|
||||
all_sorts = frozenset(("points", "problem_count", "rating", "performance_points"))
|
||||
default_desc = all_sorts
|
||||
default_sort = "-performance_points"
|
||||
context_object_name = "users"
|
||||
|
||||
def get_queryset(self):
|
||||
return ranker(
|
||||
self.organization.members.filter(is_unlisted=False)
|
||||
.order_by(self.order, "id")
|
||||
.select_related("user")
|
||||
.only(
|
||||
"display_rank",
|
||||
"user__username",
|
||||
"points",
|
||||
"rating",
|
||||
"performance_points",
|
||||
"problem_count",
|
||||
)
|
||||
)
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
res = super(OrganizationUsers, self).dispatch(request, *args, **kwargs)
|
||||
|
@ -363,26 +356,13 @@ class OrganizationUsers(QueryStringSortMixin, OrganizationDetailView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(OrganizationUsers, self).get_context_data(**kwargs)
|
||||
context["title"] = _("%s Members") % self.object.name
|
||||
context["title"] = _("%s Members") % self.organization.name
|
||||
context["partial"] = True
|
||||
context["kick_url"] = reverse(
|
||||
"organization_user_kick", args=[self.object.id, self.object.slug]
|
||||
"organization_user_kick",
|
||||
args=[self.organization.id, self.organization.slug],
|
||||
)
|
||||
|
||||
context["users"] = ranker(
|
||||
self.get_object()
|
||||
.members.filter(is_unlisted=False)
|
||||
.order_by(self.order, "id")
|
||||
.select_related("user")
|
||||
.only(
|
||||
"display_rank",
|
||||
"user__username",
|
||||
"points",
|
||||
"rating",
|
||||
"performance_points",
|
||||
"problem_count",
|
||||
)
|
||||
)
|
||||
context["first_page_href"] = "."
|
||||
context["page_type"] = "users"
|
||||
context.update(self.get_sort_context())
|
||||
|
@ -421,8 +401,7 @@ class OrganizationProblems(LoginRequiredMixin, MemberOrganizationMixin, ProblemL
|
|||
class OrganizationContestMixin(
|
||||
LoginRequiredMixin,
|
||||
TitleMixin,
|
||||
OrganizationMixin,
|
||||
OrganizationHomeViewContext,
|
||||
OrganizationHomeView,
|
||||
):
|
||||
model = Contest
|
||||
|
||||
|
@ -613,8 +592,7 @@ class RequestJoinOrganization(LoginRequiredMixin, SingleObjectMixin, FormView):
|
|||
class OrganizationRequestDetail(
|
||||
LoginRequiredMixin,
|
||||
TitleMixin,
|
||||
OrganizationMixin,
|
||||
OrganizationHomeViewContext,
|
||||
OrganizationHomeView,
|
||||
DetailView,
|
||||
):
|
||||
model = OrganizationRequest
|
||||
|
@ -639,7 +617,8 @@ OrganizationRequestFormSet = modelformset_factory(
|
|||
|
||||
|
||||
class OrganizationRequestBaseView(
|
||||
OrganizationDetailView,
|
||||
DetailView,
|
||||
OrganizationHomeView,
|
||||
TitleMixin,
|
||||
LoginRequiredMixin,
|
||||
SingleObjectTemplateResponseMixin,
|
||||
|
@ -760,7 +739,7 @@ class AddOrganizationMember(
|
|||
LoginRequiredMixin,
|
||||
TitleMixin,
|
||||
AdminOrganizationMixin,
|
||||
OrganizationDetailView,
|
||||
OrganizationHomeView,
|
||||
UpdateView,
|
||||
):
|
||||
template_name = "organization/add-member.html"
|
||||
|
@ -822,7 +801,7 @@ class EditOrganization(
|
|||
LoginRequiredMixin,
|
||||
TitleMixin,
|
||||
AdminOrganizationMixin,
|
||||
OrganizationDetailView,
|
||||
OrganizationHomeView,
|
||||
UpdateView,
|
||||
):
|
||||
template_name = "organization/edit.html"
|
||||
|
@ -1023,7 +1002,7 @@ class EditOrganizationContest(
|
|||
class AddOrganizationBlog(
|
||||
LoginRequiredMixin,
|
||||
TitleMixin,
|
||||
OrganizationHomeViewContext,
|
||||
OrganizationHomeView,
|
||||
MemberOrganizationMixin,
|
||||
CreateView,
|
||||
):
|
||||
|
@ -1074,7 +1053,7 @@ class AddOrganizationBlog(
|
|||
class EditOrganizationBlog(
|
||||
LoginRequiredMixin,
|
||||
TitleMixin,
|
||||
OrganizationHomeViewContext,
|
||||
OrganizationHomeView,
|
||||
MemberOrganizationMixin,
|
||||
UpdateView,
|
||||
):
|
||||
|
@ -1168,7 +1147,7 @@ class PendingBlogs(
|
|||
LoginRequiredMixin,
|
||||
TitleMixin,
|
||||
MemberOrganizationMixin,
|
||||
OrganizationHomeViewContext,
|
||||
OrganizationHomeView,
|
||||
ListView,
|
||||
):
|
||||
model = BlogPost
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue