Format and add trans
This commit is contained in:
parent
bba7a761ac
commit
2c39774ff7
10 changed files with 294 additions and 205 deletions
|
@ -7,32 +7,67 @@ import django.db.models.deletion
|
|||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('judge', '0137_auto_20221116_2201'),
|
||||
("judge", "0137_auto_20221116_2201"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='BookMark',
|
||||
name="BookMark",
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('page', models.CharField(db_index=True, max_length=30, verbose_name='associated page')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"page",
|
||||
models.CharField(
|
||||
db_index=True, max_length=30, verbose_name="associated page"
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'bookmark',
|
||||
'verbose_name_plural': 'bookmarks',
|
||||
"verbose_name": "bookmark",
|
||||
"verbose_name_plural": "bookmarks",
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='MakeBookMark',
|
||||
name="MakeBookMark",
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('bookmark', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bookmark', to='judge.bookmark')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_bookmark', to='judge.profile')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"bookmark",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="bookmark",
|
||||
to="judge.bookmark",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="user_bookmark",
|
||||
to="judge.profile",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'make bookmark',
|
||||
'verbose_name_plural': 'make bookmarks',
|
||||
'unique_together': {('user', 'bookmark')},
|
||||
"verbose_name": "make bookmark",
|
||||
"verbose_name_plural": "make bookmarks",
|
||||
"unique_together": {("user", "bookmark")},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
|
|
@ -47,9 +47,12 @@ class BookMark(models.Model):
|
|||
def __str__(self):
|
||||
return self.page
|
||||
|
||||
|
||||
class MakeBookMark(models.Model):
|
||||
bookmark = models.ForeignKey(BookMark, related_name="bookmark", on_delete=CASCADE)
|
||||
user = models.ForeignKey(Profile, related_name="user_bookmark", on_delete=CASCADE, db_index=True)
|
||||
user = models.ForeignKey(
|
||||
Profile, related_name="user_bookmark", on_delete=CASCADE, db_index=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ["user", "bookmark"]
|
||||
|
|
|
@ -41,7 +41,9 @@ def bookmark_page(request, delta):
|
|||
raise Http404()
|
||||
|
||||
if delta == 0:
|
||||
bookmarklist = MakeBookMark.objects.filter(bookmark=bookmark_page.first(), user=request.profile)
|
||||
bookmarklist = MakeBookMark.objects.filter(
|
||||
bookmark=bookmark_page.first(), user=request.profile
|
||||
)
|
||||
if not bookmarklist.exists():
|
||||
newbookmark = MakeBookMark(
|
||||
bookmark=bookmark_page.first(),
|
||||
|
@ -49,7 +51,9 @@ def bookmark_page(request, delta):
|
|||
)
|
||||
newbookmark.save()
|
||||
else:
|
||||
bookmarklist = MakeBookMark.objects.filter(bookmark=bookmark_page.first(), user=request.profile)
|
||||
bookmarklist = MakeBookMark.objects.filter(
|
||||
bookmark=bookmark_page.first(), user=request.profile
|
||||
)
|
||||
if bookmarklist.exists():
|
||||
bookmarklist.delete()
|
||||
|
||||
|
@ -79,4 +83,4 @@ class BookMarkListView(ListView):
|
|||
page=self.get_comment_page(item)
|
||||
)
|
||||
setattr(item, "bookmark", bookmark)
|
||||
return context
|
||||
return context
|
||||
|
|
|
@ -383,7 +383,13 @@ class ContestMixin(object):
|
|||
)
|
||||
|
||||
|
||||
class ContestDetail(ContestMixin, TitleMixin, CommentedDetailView, PageVoteDetailView, BookMarkDetailView):
|
||||
class ContestDetail(
|
||||
ContestMixin,
|
||||
TitleMixin,
|
||||
CommentedDetailView,
|
||||
PageVoteDetailView,
|
||||
BookMarkDetailView,
|
||||
):
|
||||
template_name = "contest/contest.html"
|
||||
|
||||
def get_comment_page(self):
|
||||
|
|
|
@ -245,7 +245,11 @@ class ProblemRaw(
|
|||
|
||||
|
||||
class ProblemDetail(
|
||||
ProblemMixin, SolvedProblemMixin, CommentedDetailView, PageVoteDetailView, BookMarkDetailView
|
||||
ProblemMixin,
|
||||
SolvedProblemMixin,
|
||||
CommentedDetailView,
|
||||
PageVoteDetailView,
|
||||
BookMarkDetailView,
|
||||
):
|
||||
context_object_name = "problem"
|
||||
template_name = "problem/problem.html"
|
||||
|
@ -948,6 +952,7 @@ class ProblemFeed(ProblemList, PageVoteListView, BookMarkListView):
|
|||
context["has_show_editorial_option"] = False
|
||||
context["has_have_editorial_option"] = False
|
||||
context = self.add_pagevote_context_data(context)
|
||||
context = self.add_bookmark_context_data(context)
|
||||
|
||||
return context
|
||||
|
||||
|
|
|
@ -53,7 +53,14 @@ from judge.utils.views import (
|
|||
)
|
||||
from .contests import ContestRanking
|
||||
|
||||
__all__ = ["UserPage", "UserAboutPage", "UserProblemsPage", "UserBookMarkPage", "users", "edit_profile"]
|
||||
__all__ = [
|
||||
"UserPage",
|
||||
"UserAboutPage",
|
||||
"UserProblemsPage",
|
||||
"UserBookMarkPage",
|
||||
"users",
|
||||
"edit_profile",
|
||||
]
|
||||
|
||||
|
||||
def remap_keys(iterable, mapping):
|
||||
|
@ -350,22 +357,19 @@ 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
|
||||
|
||||
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")
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue