From a447cdfcf1bfb80a86522535044fe1d4801c4e01 Mon Sep 17 00:00:00 2001 From: Zhao-Linux Date: Fri, 18 Nov 2022 04:45:27 +0700 Subject: [PATCH] fix typo --- judge/models/bookmark.py | 1 - judge/views/bookmark.py | 9 +++------ judge/views/pagevote.py | 7 ++----- judge/views/user.py | 5 +---- templates/user/user-bookmarks.html | 6 +++--- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/judge/models/bookmark.py b/judge/models/bookmark.py index 326f3ac..6945719 100644 --- a/judge/models/bookmark.py +++ b/judge/models/bookmark.py @@ -40,7 +40,6 @@ class BookMark(models.Model): except ObjectDoesNotExist: return None - class Meta: verbose_name = _("bookmark") verbose_name_plural = _("bookmarks") diff --git a/judge/views/bookmark.py b/judge/views/bookmark.py index a804089..f4cf85f 100644 --- a/judge/views/bookmark.py +++ b/judge/views/bookmark.py @@ -65,16 +65,13 @@ def undobookmark_page(request): class BookMarkDetailView(TemplateResponseMixin, SingleObjectMixin, View): - def get_context_data(self, **kwargs): context = super(BookMarkDetailView, self).get_context_data(**kwargs) - queryset = BookMark.objects.filter(page=self.get_comment_page()) - if queryset.exists() == False: - bookmark = BookMark(page=self.get_comment_page(),) - bookmark.save() - context["bookmark"] = queryset.first() + queryset = BookMark.objects.get_or_create(page=self.get_comment_page()) + context["bookmark"] = queryset[0] return context + class BookMarkListView(ListView): def add_bookmark_context_data(self, context, obj_list="object_list"): for item in context[obj_list]: diff --git a/judge/views/pagevote.py b/judge/views/pagevote.py index de29c62..e01f664 100644 --- a/judge/views/pagevote.py +++ b/judge/views/pagevote.py @@ -101,11 +101,8 @@ class PageVoteDetailView(TemplateResponseMixin, SingleObjectMixin, View): def get_context_data(self, **kwargs): context = super(PageVoteDetailView, self).get_context_data(**kwargs) - queryset = PageVote.objects.filter(page=self.get_comment_page()) - if queryset.exists() == False: - pagevote = PageVote(page=self.get_comment_page(), score=0) - pagevote.save() - context["pagevote"] = queryset.first() + queryset = PageVote.objects.get_or_create(page=self.get_comment_page()) + context["pagevote"] = queryset[0] return context diff --git a/judge/views/user.py b/judge/views/user.py index bf49269..4832be8 100644 --- a/judge/views/user.py +++ b/judge/views/user.py @@ -365,10 +365,7 @@ class UserBookMarkPage(UserPage): context["postlist"] = pagelist context["problemlist"] = problemlist context["contestlist"] = contestlist - - context["haspost"] = pagelist.exists() - context["hasproblem"] = problemlist.exists() - context["hascontest"] = contestlist.exists() + return context diff --git a/templates/user/user-bookmarks.html b/templates/user/user-bookmarks.html index 39ea196..9ba9215 100644 --- a/templates/user/user-bookmarks.html +++ b/templates/user/user-bookmarks.html @@ -8,7 +8,7 @@ {% endblock %} {% block user_content %} - {% if haspost %} + {% if postlist %}

{{ _('Bookmarked Posts') }} ({{ postlist|length }}) @@ -34,7 +34,7 @@ {{ _('You have not yet bookmarked any post.') }} {% endif %}
- {% if hasproblem %} + {% if problemlist %}

{{ _('Bookmarked Problems') }} ({{ problemlist|length }}) @@ -60,7 +60,7 @@ {{ _('You have not yet bookmarked any problem.') }} {% endif %}
- {% if hascontest %} + {% if contestlist %}

{{ _('Bookmarked Contests') }} ({{ contestlist|length }})