Implement hiding and showing functionality for user exams and collections
This commit is contained in:
@@ -698,6 +698,12 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
|
||||
default=True,
|
||||
)
|
||||
|
||||
@property
|
||||
def content_type_id(self) -> int:
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
return ContentType.objects.get_for_model(self).id
|
||||
|
||||
|
||||
authors_only = models.BooleanField(
|
||||
help_text="If true only exam/collection authors will be able to view.",
|
||||
default=False,
|
||||
@@ -2390,3 +2396,28 @@ class FindingBase(models.Model):
|
||||
return get_pretty_json(json.loads(self.viewport_json))
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
class UserHiddenItem(models.Model):
|
||||
"""Model to track which exams or collections have been hidden by a user.
|
||||
"""
|
||||
user = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="hidden_items",
|
||||
)
|
||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = GenericForeignKey("content_type", "object_id")
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["user", "content_type", "object_id"],
|
||||
name="unique_user_hidden_item",
|
||||
)
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user} hid {self.content_object}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user