This commit is contained in:
Zhao-Linux 2022-11-18 04:45:27 +07:00
parent 6e72c08ef4
commit a447cdfcf1
5 changed files with 9 additions and 19 deletions

View file

@ -40,7 +40,6 @@ class BookMark(models.Model):
except ObjectDoesNotExist:
return None
class Meta:
verbose_name = _("bookmark")
verbose_name_plural = _("bookmarks")

View file

@ -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]:

View file

@ -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

View file

@ -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

View file

@ -8,7 +8,7 @@
{% endblock %}
{% block user_content %}
{% if haspost %}
{% if postlist %}
<div class="bookmark-group">
<h3 class="unselectable toggle closed">
<span class="fa fa-chevron-right fa-fw"></span>{{ _('Bookmarked Posts') }} ({{ postlist|length }})
@ -34,7 +34,7 @@
<i>{{ _('You have not yet bookmarked any post.') }}</i>
{% endif %}
<hr>
{% if hasproblem %}
{% if problemlist %}
<div class="bookmark-group">
<h3 class="unselectable toggle closed">
<span class="fa fa-chevron-right fa-fw"></span>{{ _('Bookmarked Problems') }} ({{ problemlist|length }})
@ -60,7 +60,7 @@
<i>{{ _('You have not yet bookmarked any problem.') }}</i>
{% endif %}
<hr>
{% if hascontest %}
{% if contestlist %}
<div class="bookmark-group">
<h3 class="unselectable toggle closed">
<span class="fa fa-chevron-right fa-fw"></span>{{ _('Bookmarked Contests') }} ({{ contestlist|length }})