Redesign Bookmark (#112)
This commit is contained in:
parent
829e6a802d
commit
c6acfa5e05
13 changed files with 398 additions and 243 deletions
|
@ -704,6 +704,10 @@ class Solution(models.Model, PageVotable, Bookmarkable):
|
|||
else:
|
||||
return reverse("problem_editorial", args=[problem.code])
|
||||
|
||||
@cache_wrapper(prefix="Sga", expected_type=models.query.QuerySet)
|
||||
def get_authors(self):
|
||||
return self.authors.only("id")
|
||||
|
||||
def __str__(self):
|
||||
return _("Editorial for %s") % self.problem.name
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ from .models import (
|
|||
Profile,
|
||||
Submission,
|
||||
NavigationBar,
|
||||
Solution,
|
||||
)
|
||||
|
||||
|
||||
|
@ -120,14 +121,7 @@ def comment_update(sender, instance, **kwargs):
|
|||
|
||||
@receiver(post_save, sender=BlogPost)
|
||||
def post_update(sender, instance, **kwargs):
|
||||
cache.delete_many(
|
||||
[
|
||||
make_template_fragment_key("post_summary", (instance.id,)),
|
||||
"blog_slug:%d" % instance.id,
|
||||
"blog_feed:%d" % instance.id,
|
||||
]
|
||||
+ [make_template_fragment_key("post_content", (instance.id,))]
|
||||
)
|
||||
cache.delete(make_template_fragment_key("post_content", (instance.id,)))
|
||||
BlogPost.get_authors.dirty(instance)
|
||||
|
||||
|
||||
|
@ -175,3 +169,8 @@ def contest_submission_update(sender, instance, **kwargs):
|
|||
@receiver(post_save, sender=NavigationBar)
|
||||
def navbar_update(sender, instance, **kwargs):
|
||||
judge.template_context._nav_bar.dirty()
|
||||
|
||||
|
||||
@receiver(post_save, sender=Solution)
|
||||
def solution_update(sender, instance, **kwargs):
|
||||
cache.delete(make_template_fragment_key("solution_content", (instance.id,)))
|
||||
|
|
|
@ -22,6 +22,7 @@ from django.db.models import (
|
|||
Q,
|
||||
When,
|
||||
IntegerField,
|
||||
Sum,
|
||||
)
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.db.utils import ProgrammingError
|
||||
|
@ -644,6 +645,16 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
queryset = queryset.filter(points__gte=self.point_start)
|
||||
if self.point_end is not None:
|
||||
queryset = queryset.filter(points__lte=self.point_end)
|
||||
|
||||
queryset = queryset.annotate(
|
||||
has_public_editorial=Sum(
|
||||
Case(
|
||||
When(solution__is_public=True, then=1),
|
||||
default=0,
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
)
|
||||
)
|
||||
return queryset.distinct()
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
|
@ -36,7 +36,17 @@ from django.template.loader import render_to_string
|
|||
from reversion import revisions
|
||||
|
||||
from judge.forms import UserForm, ProfileForm, ProfileInfoForm
|
||||
from judge.models import Profile, Rating, Submission, Friend, ProfileInfo
|
||||
from judge.models import (
|
||||
Profile,
|
||||
Rating,
|
||||
Submission,
|
||||
Friend,
|
||||
ProfileInfo,
|
||||
BlogPost,
|
||||
Problem,
|
||||
Contest,
|
||||
Solution,
|
||||
)
|
||||
from judge.performance_points import get_pp_breakdown
|
||||
from judge.ratings import rating_class, rating_progress
|
||||
from judge.tasks import import_users
|
||||
|
@ -54,10 +64,13 @@ from judge.utils.views import (
|
|||
TitleMixin,
|
||||
generic_message,
|
||||
SingleObjectFormView,
|
||||
DiggPaginatorMixin,
|
||||
)
|
||||
from judge.utils.infinite_paginator import InfinitePaginationMixin
|
||||
from judge.views.problem import ProblemList
|
||||
from .contests import ContestRanking
|
||||
|
||||
|
||||
__all__ = [
|
||||
"UserPage",
|
||||
"UserAboutPage",
|
||||
|
@ -305,17 +318,49 @@ class UserProblemsPage(UserPage):
|
|||
return context
|
||||
|
||||
|
||||
class UserBookMarkPage(UserPage):
|
||||
class UserBookMarkPage(DiggPaginatorMixin, ListView, UserPage):
|
||||
template_name = "user/user-bookmarks.html"
|
||||
context_object_name = "bookmarks"
|
||||
paginate_by = 10
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.current_tab = self.request.GET.get("tab", "problems")
|
||||
self.user = self.object = self.get_object()
|
||||
return super(UserBookMarkPage, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_queryset(self):
|
||||
model = None
|
||||
if self.current_tab == "posts":
|
||||
model = BlogPost
|
||||
elif self.current_tab == "contests":
|
||||
model = Contest
|
||||
elif self.current_tab == "editorials":
|
||||
model = Solution
|
||||
else:
|
||||
model = Problem
|
||||
|
||||
q = MakeBookMark.objects.filter(user=self.user).select_related("bookmark")
|
||||
q = q.filter(bookmark__content_type=ContentType.objects.get_for_model(model))
|
||||
object_ids = q.values_list("bookmark__object_id", flat=True)
|
||||
|
||||
res = model.objects.filter(id__in=object_ids)
|
||||
if self.current_tab == "contests":
|
||||
res = res.prefetch_related("organizations", "tags")
|
||||
elif self.current_tab == "editorials":
|
||||
res = res.select_related("problem")
|
||||
|
||||
return res
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UserBookMarkPage, self).get_context_data(**kwargs)
|
||||
|
||||
bookmark_list = MakeBookMark.objects.filter(user=self.object)
|
||||
context["blogs"] = bookmark_list.filter(bookmark__page__startswith="b")
|
||||
context["problems"] = bookmark_list.filter(bookmark__page__startswith="p")
|
||||
context["contests"] = bookmark_list.filter(bookmark__page__startswith="c")
|
||||
context["solutions"] = bookmark_list.filter(bookmark__page__startswith="s")
|
||||
context["current_tab"] = self.current_tab
|
||||
context["user"] = self.user
|
||||
|
||||
context["page_prefix"] = (
|
||||
self.request.path + "?tab=" + self.current_tab + "&page="
|
||||
)
|
||||
context["first_page_href"] = self.request.path
|
||||
|
||||
return context
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue