Migrate pagevote and bookmark to use content_type
This commit is contained in:
parent
64495be799
commit
36e27321f7
19 changed files with 285 additions and 87 deletions
|
@ -86,11 +86,6 @@ class CommentForm(ModelForm):
|
||||||
class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
||||||
comment_page = None
|
comment_page = None
|
||||||
|
|
||||||
def get_comment_page(self):
|
|
||||||
if self.comment_page is None:
|
|
||||||
raise NotImplementedError()
|
|
||||||
return self.comment_page
|
|
||||||
|
|
||||||
def is_comment_locked(self):
|
def is_comment_locked(self):
|
||||||
if self.request.user.has_perm("judge.override_comment_lock"):
|
if self.request.user.has_perm("judge.override_comment_lock"):
|
||||||
return False
|
return False
|
||||||
|
|
70
judge/migrations/0158_migrate_pagevote.py
Normal file
70
judge/migrations/0158_migrate_pagevote.py
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
# Generated by Django 3.2.18 on 2023-08-03 07:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_pagevote(apps, schema_editor):
|
||||||
|
PageVote = apps.get_model("judge", "PageVote")
|
||||||
|
Problem = apps.get_model("judge", "Problem")
|
||||||
|
Solution = apps.get_model("judge", "Solution")
|
||||||
|
BlogPost = apps.get_model("judge", "BlogPost")
|
||||||
|
Contest = apps.get_model("judge", "Contest")
|
||||||
|
|
||||||
|
for vote in PageVote.objects.all():
|
||||||
|
page = vote.page
|
||||||
|
try:
|
||||||
|
if page.startswith("p:"):
|
||||||
|
code = page[2:]
|
||||||
|
vote.linked_object = Problem.objects.get(code=code)
|
||||||
|
elif page.startswith("s:"):
|
||||||
|
code = page[2:]
|
||||||
|
vote.linked_object = Solution.objects.get(problem__code=code)
|
||||||
|
elif page.startswith("c:"):
|
||||||
|
key = page[2:]
|
||||||
|
vote.linked_object = Contest.objects.get(key=key)
|
||||||
|
elif page.startswith("b:"):
|
||||||
|
blog_id = page[2:]
|
||||||
|
vote.linked_object = BlogPost.objects.get(id=blog_id)
|
||||||
|
vote.save()
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
vote.delete()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("contenttypes", "0002_remove_content_type_name"),
|
||||||
|
("judge", "0157_auto_20230801_1145"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="pagevote",
|
||||||
|
name="content_type",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="contenttypes.contenttype",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="pagevote",
|
||||||
|
name="object_id",
|
||||||
|
field=models.PositiveIntegerField(default=None),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name="pagevote",
|
||||||
|
unique_together={("content_type", "object_id")},
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name="pagevote",
|
||||||
|
index=models.Index(
|
||||||
|
fields=["content_type", "object_id"],
|
||||||
|
name="judge_pagev_content_ed8899_idx",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.RunPython(migrate_pagevote, migrations.RunPython.noop, atomic=True),
|
||||||
|
]
|
23
judge/migrations/0159_auto_20230803_1518.py
Normal file
23
judge/migrations/0159_auto_20230803_1518.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.2.18 on 2023-08-03 08:18
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("contenttypes", "0002_remove_content_type_name"),
|
||||||
|
("judge", "0158_migrate_pagevote"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="pagevote",
|
||||||
|
name="content_type",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="contenttypes.contenttype",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
80
judge/migrations/0160_migrate_bookmark.py
Normal file
80
judge/migrations/0160_migrate_bookmark.py
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
# Generated by Django 3.2.18 on 2023-08-03 08:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_bookmark(apps, schema_editor):
|
||||||
|
BookMark = apps.get_model("judge", "BookMark")
|
||||||
|
Problem = apps.get_model("judge", "Problem")
|
||||||
|
Solution = apps.get_model("judge", "Solution")
|
||||||
|
BlogPost = apps.get_model("judge", "BlogPost")
|
||||||
|
Contest = apps.get_model("judge", "Contest")
|
||||||
|
|
||||||
|
for bookmark in BookMark.objects.all():
|
||||||
|
page = bookmark.page
|
||||||
|
try:
|
||||||
|
if page.startswith("p:"):
|
||||||
|
code = page[2:]
|
||||||
|
bookmark.linked_object = Problem.objects.get(code=code)
|
||||||
|
elif page.startswith("s:"):
|
||||||
|
code = page[2:]
|
||||||
|
bookmark.linked_object = Solution.objects.get(problem__code=code)
|
||||||
|
elif page.startswith("c:"):
|
||||||
|
key = page[2:]
|
||||||
|
bookmark.linked_object = Contest.objects.get(key=key)
|
||||||
|
elif page.startswith("b:"):
|
||||||
|
blog_id = page[2:]
|
||||||
|
bookmark.linked_object = BlogPost.objects.get(id=blog_id)
|
||||||
|
bookmark.save()
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
bookmark.delete()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("contenttypes", "0002_remove_content_type_name"),
|
||||||
|
("judge", "0159_auto_20230803_1518"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="bookmark",
|
||||||
|
name="content_type",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="contenttypes.contenttype",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="bookmark",
|
||||||
|
name="object_id",
|
||||||
|
field=models.PositiveIntegerField(default=1),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="bookmark",
|
||||||
|
name="score",
|
||||||
|
field=models.IntegerField(default=0, verbose_name="votes"),
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name="bookmark",
|
||||||
|
unique_together={("content_type", "object_id")},
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name="bookmark",
|
||||||
|
index=models.Index(
|
||||||
|
fields=["content_type", "object_id"],
|
||||||
|
name="judge_bookm_content_964329_idx",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddIndex(
|
||||||
|
model_name="makebookmark",
|
||||||
|
index=models.Index(
|
||||||
|
fields=["user", "bookmark"], name="judge_makeb_user_id_f0e226_idx"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.RunPython(migrate_bookmark, migrations.RunPython.noop, atomic=True),
|
||||||
|
]
|
28
judge/migrations/0161_auto_20230803_1536.py
Normal file
28
judge/migrations/0161_auto_20230803_1536.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# Generated by Django 3.2.18 on 2023-08-03 08:36
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("contenttypes", "0002_remove_content_type_name"),
|
||||||
|
("judge", "0160_migrate_bookmark"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="bookmark",
|
||||||
|
name="content_type",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="contenttypes.contenttype",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="bookmark",
|
||||||
|
name="object_id",
|
||||||
|
field=models.PositiveIntegerField(),
|
||||||
|
),
|
||||||
|
]
|
|
@ -2,6 +2,8 @@ from django.db import models
|
||||||
from django.db.models import CASCADE
|
from django.db.models import CASCADE
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
from judge.models.profile import Profile
|
from judge.models.profile import Profile
|
||||||
|
|
||||||
|
@ -13,7 +15,11 @@ class BookMark(models.Model):
|
||||||
max_length=30,
|
max_length=30,
|
||||||
verbose_name=_("associated page"),
|
verbose_name=_("associated page"),
|
||||||
db_index=True,
|
db_index=True,
|
||||||
)
|
) # deprecated
|
||||||
|
score = models.IntegerField(verbose_name=_("votes"), default=0)
|
||||||
|
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||||
|
object_id = models.PositiveIntegerField()
|
||||||
|
linked_object = GenericForeignKey("content_type", "object_id")
|
||||||
|
|
||||||
def get_bookmark(self, user):
|
def get_bookmark(self, user):
|
||||||
userqueryset = MakeBookMark.objects.filter(bookmark=self, user=user)
|
userqueryset = MakeBookMark.objects.filter(bookmark=self, user=user)
|
||||||
|
@ -22,31 +28,16 @@ class BookMark(models.Model):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def page_object(self):
|
|
||||||
from judge.models.contest import Contest
|
|
||||||
from judge.models.interface import BlogPost
|
|
||||||
from judge.models.problem import Problem, Solution
|
|
||||||
|
|
||||||
try:
|
|
||||||
page = self.page
|
|
||||||
if page.startswith("p:"):
|
|
||||||
return Problem.objects.get(code=page[2:])
|
|
||||||
elif page.startswith("c:"):
|
|
||||||
return Contest.objects.get(key=page[2:])
|
|
||||||
elif page.startswith("b:"):
|
|
||||||
return BlogPost.objects.get(id=page[2:])
|
|
||||||
elif page.startswith("s:"):
|
|
||||||
return Solution.objects.get(problem__code=page[2:])
|
|
||||||
return None
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
return None
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("bookmark")
|
verbose_name = _("bookmark")
|
||||||
verbose_name_plural = _("bookmarks")
|
verbose_name_plural = _("bookmarks")
|
||||||
|
indexes = [
|
||||||
|
models.Index(fields=["content_type", "object_id"]),
|
||||||
|
]
|
||||||
|
unique_together = ("content_type", "object_id")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.page
|
return f"bookmark for {self.linked_object}"
|
||||||
|
|
||||||
|
|
||||||
class MakeBookMark(models.Model):
|
class MakeBookMark(models.Model):
|
||||||
|
@ -56,6 +47,9 @@ class MakeBookMark(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
indexes = [
|
||||||
|
models.Index(fields=["user", "bookmark"]),
|
||||||
|
]
|
||||||
unique_together = ["user", "bookmark"]
|
unique_together = ["user", "bookmark"]
|
||||||
verbose_name = _("make bookmark")
|
verbose_name = _("make bookmark")
|
||||||
verbose_name_plural = _("make bookmarks")
|
verbose_name_plural = _("make bookmarks")
|
||||||
|
|
|
@ -299,6 +299,8 @@ class Contest(models.Model):
|
||||||
help_text=_("Number of digits to round points to."),
|
help_text=_("Number of digits to round points to."),
|
||||||
)
|
)
|
||||||
comments = GenericRelation("Comment")
|
comments = GenericRelation("Comment")
|
||||||
|
pagevote = GenericRelation("PageVote")
|
||||||
|
bookmark = GenericRelation("BookMark")
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def format_class(self):
|
def format_class(self):
|
||||||
|
|
|
@ -96,6 +96,8 @@ class BlogPost(models.Model):
|
||||||
verbose_name=_("private to organizations"), default=False
|
verbose_name=_("private to organizations"), default=False
|
||||||
)
|
)
|
||||||
comments = GenericRelation("Comment")
|
comments = GenericRelation("Comment")
|
||||||
|
pagevote = GenericRelation("PageVote")
|
||||||
|
bookmark = GenericRelation("BookMark")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
@ -130,17 +132,21 @@ class BlogPost(models.Model):
|
||||||
and self.authors.filter(id=user.profile.id).exists()
|
and self.authors.filter(id=user.profile.id).exists()
|
||||||
)
|
)
|
||||||
|
|
||||||
@cached_property
|
def get_or_create_pagevote(self):
|
||||||
def pagevote(self):
|
if self.pagevote.count():
|
||||||
page = "b:%s" % self.id
|
return self.pagevote.first()
|
||||||
pagevote, _ = PageVote.objects.get_or_create(page=page)
|
new_pagevote = PageVote()
|
||||||
return pagevote
|
new_pagevote.linked_object = self
|
||||||
|
new_pagevote.save()
|
||||||
|
return new_pagevote
|
||||||
|
|
||||||
@cached_property
|
def get_or_create_bookmark(self):
|
||||||
def bookmark(self):
|
if self.bookmark.count():
|
||||||
page = "b:%s" % self.id
|
return self.bookmark.first()
|
||||||
bookmark, _ = BookMark.objects.get_or_create(page=page)
|
new_bookmark = BookMark()
|
||||||
return bookmark
|
new_bookmark.linked_object = self
|
||||||
|
new_bookmark.save()
|
||||||
|
return new_bookmark
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (("edit_all_post", _("Edit all posts")),)
|
permissions = (("edit_all_post", _("Edit all posts")),)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import CASCADE
|
from django.db.models import CASCADE
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
from judge.models.profile import Profile
|
from judge.models.profile import Profile
|
||||||
|
|
||||||
|
@ -12,12 +14,19 @@ class PageVote(models.Model):
|
||||||
max_length=30,
|
max_length=30,
|
||||||
verbose_name=_("associated page"),
|
verbose_name=_("associated page"),
|
||||||
db_index=True,
|
db_index=True,
|
||||||
)
|
) # deprecated
|
||||||
score = models.IntegerField(verbose_name=_("votes"), default=0)
|
score = models.IntegerField(verbose_name=_("votes"), default=0)
|
||||||
|
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||||
|
object_id = models.PositiveIntegerField()
|
||||||
|
linked_object = GenericForeignKey("content_type", "object_id")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("pagevote")
|
verbose_name = _("pagevote")
|
||||||
verbose_name_plural = _("pagevotes")
|
verbose_name_plural = _("pagevotes")
|
||||||
|
indexes = [
|
||||||
|
models.Index(fields=["content_type", "object_id"]),
|
||||||
|
]
|
||||||
|
unique_together = ("content_type", "object_id")
|
||||||
|
|
||||||
def vote_score(self, user):
|
def vote_score(self, user):
|
||||||
page_vote = PageVoteVoter.objects.filter(pagevote=self, voter=user)
|
page_vote = PageVoteVoter.objects.filter(pagevote=self, voter=user)
|
||||||
|
@ -27,7 +36,7 @@ class PageVote(models.Model):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"pagevote for {self.page}"
|
return f"pagevote for {self.linked_object}"
|
||||||
|
|
||||||
|
|
||||||
class PageVoteVoter(models.Model):
|
class PageVoteVoter(models.Model):
|
||||||
|
|
|
@ -272,6 +272,8 @@ class Problem(models.Model):
|
||||||
objects = TranslatedProblemQuerySet.as_manager()
|
objects = TranslatedProblemQuerySet.as_manager()
|
||||||
tickets = GenericRelation("Ticket")
|
tickets = GenericRelation("Ticket")
|
||||||
comments = GenericRelation("Comment")
|
comments = GenericRelation("Comment")
|
||||||
|
pagevote = GenericRelation("PageVote")
|
||||||
|
bookmark = GenericRelation("BookMark")
|
||||||
|
|
||||||
organizations = models.ManyToManyField(
|
organizations = models.ManyToManyField(
|
||||||
Organization,
|
Organization,
|
||||||
|
@ -448,18 +450,6 @@ class Problem(models.Model):
|
||||||
def usable_common_names(self):
|
def usable_common_names(self):
|
||||||
return set(self.usable_languages.values_list("common_name", flat=True))
|
return set(self.usable_languages.values_list("common_name", flat=True))
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def pagevote(self):
|
|
||||||
page = "p:%s" % self.code
|
|
||||||
pagevote, _ = PageVote.objects.get_or_create(page=page)
|
|
||||||
return pagevote
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def bookmark(self):
|
|
||||||
page = "p:%s" % self.code
|
|
||||||
bookmark, _ = BookMark.objects.get_or_create(page=page)
|
|
||||||
return bookmark
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def usable_languages(self):
|
def usable_languages(self):
|
||||||
return self.allowed_languages.filter(
|
return self.allowed_languages.filter(
|
||||||
|
@ -559,6 +549,22 @@ class Problem(models.Model):
|
||||||
cache.set(key, result)
|
cache.set(key, result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_or_create_pagevote(self):
|
||||||
|
if self.pagevote.count():
|
||||||
|
return self.pagevote.first()
|
||||||
|
new_pagevote = PageVote()
|
||||||
|
new_pagevote.linked_object = self
|
||||||
|
new_pagevote.save()
|
||||||
|
return new_pagevote
|
||||||
|
|
||||||
|
def get_or_create_bookmark(self):
|
||||||
|
if self.bookmark.count():
|
||||||
|
return self.bookmark.first()
|
||||||
|
new_bookmark = BookMark()
|
||||||
|
new_bookmark.linked_object = self
|
||||||
|
new_bookmark.save()
|
||||||
|
return new_bookmark
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Problem, self).save(*args, **kwargs)
|
super(Problem, self).save(*args, **kwargs)
|
||||||
if self.code != self.__original_code:
|
if self.code != self.__original_code:
|
||||||
|
@ -677,6 +683,8 @@ class Solution(models.Model):
|
||||||
authors = models.ManyToManyField(Profile, verbose_name=_("authors"), blank=True)
|
authors = models.ManyToManyField(Profile, verbose_name=_("authors"), blank=True)
|
||||||
content = models.TextField(verbose_name=_("editorial content"))
|
content = models.TextField(verbose_name=_("editorial content"))
|
||||||
comments = GenericRelation("Comment")
|
comments = GenericRelation("Comment")
|
||||||
|
pagevote = GenericRelation("PageVote")
|
||||||
|
bookmark = GenericRelation("BookMark")
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
problem = self.problem
|
problem = self.problem
|
||||||
|
|
|
@ -109,9 +109,6 @@ class PostList(HomeFeedView):
|
||||||
context["page_type"] = "blog"
|
context["page_type"] = "blog"
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_comment_page(self, post):
|
|
||||||
return "b:%s" % post.id
|
|
||||||
|
|
||||||
|
|
||||||
class TicketFeed(HomeFeedView):
|
class TicketFeed(HomeFeedView):
|
||||||
model = Ticket
|
model = Ticket
|
||||||
|
@ -180,9 +177,6 @@ class PostView(TitleMixin, CommentedDetailView, PageVoteDetailView, BookMarkDeta
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
return self.object.title
|
return self.object.title
|
||||||
|
|
||||||
def get_comment_page(self):
|
|
||||||
return "b:%s" % self.object.id
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(PostView, self).get_context_data(**kwargs)
|
context = super(PostView, self).get_context_data(**kwargs)
|
||||||
context["og_image"] = self.object.og_image
|
context["og_image"] = self.object.og_image
|
||||||
|
|
|
@ -71,6 +71,6 @@ def undobookmark_page(request):
|
||||||
class BookMarkDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
class BookMarkDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(BookMarkDetailView, self).get_context_data(**kwargs)
|
context = super(BookMarkDetailView, self).get_context_data(**kwargs)
|
||||||
queryset = BookMark.objects.get_or_create(page=self.get_comment_page())
|
queryset = self.object.bookmark
|
||||||
context["bookmark"] = queryset[0]
|
context["bookmark"] = queryset.first()
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -412,9 +412,6 @@ class ContestDetail(
|
||||||
):
|
):
|
||||||
template_name = "contest/contest.html"
|
template_name = "contest/contest.html"
|
||||||
|
|
||||||
def get_comment_page(self):
|
|
||||||
return "c:%s" % self.object.key
|
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
return self.object.name
|
return self.object.name
|
||||||
|
|
||||||
|
|
|
@ -270,9 +270,6 @@ class OrganizationHome(OrganizationHomeView, FeedView):
|
||||||
.prefetch_related("authors__user", "organizations")
|
.prefetch_related("authors__user", "organizations")
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_comment_page(self, post):
|
|
||||||
return "b:%s" % post.id
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(OrganizationHome, self).get_context_data(**kwargs)
|
context = super(OrganizationHome, self).get_context_data(**kwargs)
|
||||||
context["title"] = self.organization.name
|
context["title"] = self.organization.name
|
||||||
|
|
|
@ -101,6 +101,6 @@ class PageVoteDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(PageVoteDetailView, self).get_context_data(**kwargs)
|
context = super(PageVoteDetailView, self).get_context_data(**kwargs)
|
||||||
queryset = PageVote.objects.get_or_create(page=self.get_comment_page())
|
queryset = self.object.pagevote
|
||||||
context["pagevote"] = queryset[0]
|
context["pagevote"] = queryset.first()
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -224,9 +224,6 @@ class ProblemSolution(
|
||||||
context["has_solved_problem"] = self.problem.id in self.get_completed_problems()
|
context["has_solved_problem"] = self.problem.id in self.get_completed_problems()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_comment_page(self):
|
|
||||||
return "s:" + self.problem.code
|
|
||||||
|
|
||||||
|
|
||||||
class ProblemRaw(
|
class ProblemRaw(
|
||||||
ProblemMixin, TitleMixin, TemplateResponseMixin, SingleObjectMixin, View
|
ProblemMixin, TitleMixin, TemplateResponseMixin, SingleObjectMixin, View
|
||||||
|
@ -270,9 +267,6 @@ class ProblemDetail(
|
||||||
context_object_name = "problem"
|
context_object_name = "problem"
|
||||||
template_name = "problem/problem.html"
|
template_name = "problem/problem.html"
|
||||||
|
|
||||||
def get_comment_page(self):
|
|
||||||
return "p:%s" % self.object.code
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(ProblemDetail, self).get_context_data(**kwargs)
|
context = super(ProblemDetail, self).get_context_data(**kwargs)
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
|
@ -843,9 +837,6 @@ class ProblemFeed(ProblemList, FeedView):
|
||||||
title = _("Problem feed")
|
title = _("Problem feed")
|
||||||
feed_type = None
|
feed_type = None
|
||||||
|
|
||||||
def get_comment_page(self, problem):
|
|
||||||
return "p:%s" % problem.code
|
|
||||||
|
|
||||||
# arr = [[], [], ..]
|
# arr = [[], [], ..]
|
||||||
def merge_recommendation(self, arr):
|
def merge_recommendation(self, arr):
|
||||||
seed = datetime.now().strftime("%d%m%Y")
|
seed = datetime.now().strftime("%d%m%Y")
|
||||||
|
|
|
@ -46,8 +46,8 @@
|
||||||
<div class="show-more"> {{_("...More")}} </div>
|
<div class="show-more"> {{_("...More")}} </div>
|
||||||
</div>
|
</div>
|
||||||
<div class="actionbar-box">
|
<div class="actionbar-box">
|
||||||
{% set pagevote = post.pagevote %}
|
{% set pagevote = post.get_or_create_pagevote() %}
|
||||||
{% set bookmark = post.bookmark %}
|
{% set bookmark = post.get_or_create_bookmark() %}
|
||||||
{% set hide_actionbar_comment = True %}
|
{% set hide_actionbar_comment = True %}
|
||||||
{% set include_hr = False %}
|
{% set include_hr = False %}
|
||||||
{% set share_url = request.build_absolute_uri(post.get_absolute_url()) %}
|
{% set share_url = request.build_absolute_uri(post.get_absolute_url()) %}
|
||||||
|
|
|
@ -109,8 +109,8 @@
|
||||||
<div class="show-more"> {{_("...More")}} </div>
|
<div class="show-more"> {{_("...More")}} </div>
|
||||||
</div>
|
</div>
|
||||||
<div class="actionbar-box">
|
<div class="actionbar-box">
|
||||||
{% set pagevote = problem.pagevote %}
|
{% set pagevote = problem.get_or_create_pagevote() %}
|
||||||
{% set bookmark = problem.bookmark %}
|
{% set bookmark = problem.get_or_create_bookmark() %}
|
||||||
{% set hide_actionbar_comment = True %}
|
{% set hide_actionbar_comment = True %}
|
||||||
{% set include_hr = False %}
|
{% set include_hr = False %}
|
||||||
{% set share_url = request.build_absolute_uri(problem.get_absolute_url()) %}
|
{% set share_url = request.build_absolute_uri(problem.get_absolute_url()) %}
|
||||||
|
|
|
@ -16,10 +16,11 @@
|
||||||
<table style="display: none" class="table toggled">
|
<table style="display: none" class="table toggled">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for post in blogs %}
|
{% for post in blogs %}
|
||||||
{% if post.bookmark.page_object() %}
|
{% set object = post.bookmark.linked_object %}
|
||||||
|
{% if object %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="bookmark-name">
|
<td class="bookmark-name">
|
||||||
<a href="{{ url('blog_post', post.bookmark.page_object().id, post.bookmark.page_object().slug) }}">{{ post.bookmark.page_object().title}} </a>
|
<a href="{{ url('blog_post', object.id, object.slug) }}">{{ object.title}} </a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -36,10 +37,11 @@
|
||||||
<table style="display: none" class="table toggled">
|
<table style="display: none" class="table toggled">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for problem in problems %}
|
{% for problem in problems %}
|
||||||
{% if problem.bookmark.page_object() %}
|
{% set object = problem.bookmark.linked_object %}
|
||||||
|
{% if object %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="bookmark-name">
|
<td class="bookmark-name">
|
||||||
<a href="{{ url('problem_detail', problem.bookmark.page_object().code) }}">{{ problem.bookmark.page_object().name}} </a>
|
<a href="{{ url('problem_detail', object.code) }}">{{ object.name}} </a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -57,10 +59,11 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for contest in contests %}
|
{% for contest in contests %}
|
||||||
{% if contest.bookmark.page_object() %}
|
{% set object = contest.bookmark.linked_object %}
|
||||||
|
{% if object %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="bookmark-name">
|
<td class="bookmark-name">
|
||||||
<a href="{{ url('contest_view', contest.bookmark.page_object().key) }}">{{ contest.bookmark.page_object().name}} </a>
|
<a href="{{ url('contest_view', object.key) }}">{{ object.name}} </a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -78,10 +81,11 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for solution in solutions %}
|
{% for solution in solutions %}
|
||||||
{% if solution.bookmark.page_object() %}
|
{% set object = solution.bookmark.linked_object %}
|
||||||
|
{% if object %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="bookmark-name">
|
<td class="bookmark-name">
|
||||||
<a href="{{ url('problem_editorial', solution.bookmark.page_object().problem.code) }}">{{ solution.bookmark.page_object().problem.name}} </a>
|
<a href="{{ url('problem_editorial', object.problem.code) }}">{{ object.problem.name}} </a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue