add bookmarks page
This commit is contained in:
parent
8108967959
commit
6e72c08ef4
9 changed files with 143 additions and 9 deletions
|
@ -129,7 +129,7 @@ class PostList(FeedView, PageVoteListView, BookMarkListView):
|
|||
.order_by()
|
||||
}
|
||||
context = self.add_pagevote_context_data(context)
|
||||
|
||||
context = self.add_bookmark_context_data(context)
|
||||
return context
|
||||
|
||||
def get_comment_page(self, post):
|
||||
|
|
|
@ -76,10 +76,8 @@ class BookMarkDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
|||
return context
|
||||
|
||||
class BookMarkListView(ListView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(BookMarkListView, self).get_context_data(**kwargs)
|
||||
for item in context["object_list"]:
|
||||
def add_bookmark_context_data(self, context, obj_list="object_list"):
|
||||
for item in context[obj_list]:
|
||||
bookmark, _ = BookMark.objects.get_or_create(
|
||||
page=self.get_comment_page(item)
|
||||
)
|
||||
|
|
|
@ -72,6 +72,7 @@ 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
|
||||
|
||||
__all__ = [
|
||||
"OrganizationList",
|
||||
|
@ -266,7 +267,7 @@ class OrganizationList(TitleMixin, ListView, OrganizationBase):
|
|||
return context
|
||||
|
||||
|
||||
class OrganizationHome(OrganizationDetailView, PageVoteListView):
|
||||
class OrganizationHome(OrganizationDetailView, PageVoteListView, BookMarkListView):
|
||||
template_name = "organization/home.html"
|
||||
pagevote_object_name = "posts"
|
||||
|
||||
|
@ -294,6 +295,7 @@ class OrganizationHome(OrganizationDetailView, PageVoteListView):
|
|||
context["title"] = self.object.name
|
||||
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(
|
||||
|
|
|
@ -13,6 +13,7 @@ from django.db import transaction
|
|||
from django.db.models import Count, Max, Min
|
||||
from django.db.models.fields import DateField
|
||||
from django.db.models.functions import Cast, ExtractYear
|
||||
from judge.models.bookmark import MakeBookMark
|
||||
from django.forms import Form
|
||||
from django.http import (
|
||||
Http404,
|
||||
|
@ -52,7 +53,7 @@ from judge.utils.views import (
|
|||
)
|
||||
from .contests import ContestRanking
|
||||
|
||||
__all__ = ["UserPage", "UserAboutPage", "UserProblemsPage", "users", "edit_profile"]
|
||||
__all__ = ["UserPage", "UserAboutPage", "UserProblemsPage", "UserBookMarkPage", "users", "edit_profile"]
|
||||
|
||||
|
||||
def remap_keys(iterable, mapping):
|
||||
|
@ -349,6 +350,27 @@ class UserProblemsPage(UserPage):
|
|||
|
||||
return context
|
||||
|
||||
class UserBookMarkPage(UserPage):
|
||||
template_name = "user/user-bookmarks.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UserBookMarkPage, self).get_context_data(**kwargs)
|
||||
|
||||
makedownlist = MakeBookMark.objects.filter(user=self.object)
|
||||
pagelist = makedownlist.filter(bookmark__page__startswith='b')
|
||||
problemlist = makedownlist.filter(bookmark__page__startswith='p')
|
||||
contestlist = makedownlist.filter(bookmark__page__startswith='c')
|
||||
|
||||
context["pagelist"] = makedownlist
|
||||
context["postlist"] = pagelist
|
||||
context["problemlist"] = problemlist
|
||||
context["contestlist"] = contestlist
|
||||
|
||||
context["haspost"] = pagelist.exists()
|
||||
context["hasproblem"] = problemlist.exists()
|
||||
context["hascontest"] = contestlist.exists()
|
||||
return context
|
||||
|
||||
|
||||
class UserPerformancePointsAjax(UserProblemsPage):
|
||||
template_name = "user/pp-table-body.html"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue