diff --git a/backend/apps/comment/managers.py b/backend/apps/comment/managers.py new file mode 100644 index 0000000..064477d --- /dev/null +++ b/backend/apps/comment/managers.py @@ -0,0 +1,18 @@ +from django.db import models + +from .models import CommentModel + + +class CommentManager(models.Manager): + def soft_delete(self, instance: CommentModel): + # if no children- hard delete + if instance.children_count == 0: + instance.delete() + # else- soft delete + else: + instance.deleted = True + instance.content = "[deleted]" + instance.save() + + def clean_up_soft_deleted(self): + self.filter(deleted=True, children_count=0).delete() diff --git a/backend/apps/comment/models.py b/backend/apps/comment/models.py index 578b369..92ae2db 100644 --- a/backend/apps/comment/models.py +++ b/backend/apps/comment/models.py @@ -11,7 +11,7 @@ class CommentModel(CreatedAtMixin, TreeModel): quibbler = models.ForeignKey( - ProfileModel, on_delete=models.CASCADE, verbose_name=_('quibbler') + ProfileModel, on_delete=models.SET_NULL, null=True, verbose_name=_('quibbler') ) content = models.TextField(_('content')) upvotes = models.ManyToManyField( @@ -20,13 +20,15 @@ class CommentModel(CreatedAtMixin, TreeModel): downvotes = models.ManyToManyField( ProfileModel, related_name='downvotes', blank=True, verbose_name=_('downvotes') ) + # flag + deleted = models.BooleanField(default=False) @property def children_count(self): return self.children().count() def __str__(self) -> str: - return f"Comment by {self.quibbler.username}" + return f"Comment by {self.quibbler}" class Meta: # pyright: ignore indexes = [idx.GistIndex(fields=['path'])] diff --git a/backend/locale/.gitkeep b/backend/locale/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/backend/locale/en/LC_MESSAGES/django.po b/backend/locale/en/LC_MESSAGES/django.po deleted file mode 100644 index 4f84a81..0000000 --- a/backend/locale/en/LC_MESSAGES/django.po +++ /dev/null @@ -1,139 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-12-08 13:19+0530\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=2; plural=(n != 1);\n" - -#: apps/quib/models.py:14 -msgid "quiblet" -msgstr "" - -#: apps/quib/models.py:20 -msgid "quibber" -msgstr "Quibbler" - -#: apps/quib/models.py:23 -msgid "title" -msgstr "Title" - -#: apps/quib/models.py:24 -msgid "slug" -msgstr "Slug" - -#: apps/quib/models.py:25 -msgid "content" -msgstr "Content" - -#: apps/quib/models.py:27 -msgid "likes" -msgstr "Likes" - -#: apps/quib/models.py:30 -msgid "dislikes" -msgstr "Dislikes" - -#: apps/quiblet/models.py:12 -msgid "name" -msgstr "Name" - -#: apps/quiblet/models.py:13 -msgid "description" -msgstr "Description" - -#: apps/quiblet/models.py:15 -msgid "cover" -msgstr "Cover" - -#: apps/quiblet/models.py:21 -msgid "members" -msgstr "Members" - -#: apps/quiblet/models.py:24 -msgid "rangers" -msgstr "Rangers" - -#: apps/user/admin.py:17 -msgid "permissions" -msgstr "Permissions" - -#: apps/user/admin.py:22 apps/user/admin.py:50 -msgid "important dates" -msgstr "Important dates" - -#: apps/user/forms.py:39 -msgid "a user cannot have more than 5 profiles." -msgstr "A user cannot have more than 5 profiles." - -#: apps/user/models.py:11 -msgid "email address" -msgstr "Email Address" - -#: apps/user/models.py:12 -msgid "date joined" -msgstr "Date Joined" - -#: apps/user/models.py:14 -msgid "staff status" -msgstr "Staff status" - -#: apps/user/models.py:16 -msgid "designates whether the user can log into this admin site." -msgstr "Designates whether this user should be treated as active." - -#: apps/user/models.py:19 -msgid "active" -msgstr "Active" - -#: apps/user/models.py:22 -msgid "" -"designates whether this user should be treated as active. unselect this " -"instead of deleting accounts." -msgstr "" -"Designates whether this user should be treated as active. Unselect this " -"instead of deleting accounts." - -#: apps/user/models.py:39 -msgid "username" -msgstr "Username" - -#: apps/user/models.py:40 -msgid "first name" -msgstr "First Name" - -#: apps/user/models.py:41 -msgid "last name" -msgstr "Last Name" - -#: common/mixins.py:13 -msgid "create at" -msgstr "Created At" - -#: common/mixins.py:38 -msgid "color" -msgstr "Color" - -#: common/mixins.py:52 -msgid "avatar" -msgstr "Avatar" - -#: common/mixins.py:65 -msgid "is public" -msgstr "Is Public" - -#: common/mixins.py:75 -msgid "id" -msgstr "Id"