From d6e3dc4d8cc7b345ca880a2a91ccdbcf150db5af Mon Sep 17 00:00:00 2001 From: krmax44 Date: Mon, 18 Nov 2024 15:13:45 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20FoiMessageDraft=20proxy=20mod?= =?UTF-8?q?el=20to=20remove=20drafts=20in=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- froide/foirequest/admin.py | 12 ++++++++---- froide/foirequest/models/message.py | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/froide/foirequest/admin.py b/froide/foirequest/admin.py index f7e5da6ef..e656cdb69 100644 --- a/froide/foirequest/admin.py +++ b/froide/foirequest/admin.py @@ -22,6 +22,7 @@ from froide.account.models import UserTag from froide.comments.models import FroideComment +from froide.foirequest.models.message import FoiMessageDraft from froide.guide.models import Action from froide.guide.utils import assign_guidance_action from froide.helper.admin_utils import ( @@ -522,7 +523,6 @@ class MessageTagsFilter(MultiFilterMixin, TaggitListFilter): class FoiMessageAdmin(admin.ModelAdmin): save_on_top = True list_display = ( - "is_draft", "subject", "timestamp", "message_page", @@ -600,9 +600,7 @@ def get_urls(self): return my_urls + urls def get_queryset(self, request): - qs = super(FoiMessageAdmin, self).get_queryset(request) - qs = qs.prefetch_related("deliverystatus") - return qs + return self.model.objects.with_drafts(False).prefetch_related("deliverystatus") def save_model(self, request, obj, form, change): if ( @@ -752,6 +750,12 @@ def add_comment( ) +@admin.register(FoiMessageDraft) +class FoiMessageDraftAdmin(FoiMessageAdmin): + def get_queryset(self, request): + return self.model.objects.all().prefetch_related("deliverystatus") + + @admin.register(MessageTag) class MessageTagAdmin(admin.ModelAdmin): prepopulated_fields = {"slug": ("name",)} diff --git a/froide/foirequest/models/message.py b/froide/foirequest/models/message.py index be79a50bf..cf792e5c3 100644 --- a/froide/foirequest/models/message.py +++ b/froide/foirequest/models/message.py @@ -37,10 +37,15 @@ def get_throttle_filter(self, queryset, user, extra_filters=None): qs = qs.filter(**extra_filters) return qs, "timestamp" - def get_drafts(self, drafts=True): + def with_drafts(self, drafts=True): return super().get_queryset().filter(is_draft=drafts) +class FoiMessageDraftManager(FoiMessageManager): + def get_queryset(self): + return self.with_drafts() + + class MessageTag(TagBase): class Meta: verbose_name = _("message tag") @@ -746,6 +751,15 @@ def set_cached_rendered_content(self, authenticated_read, content): FoiMessage.objects.filter(id=self.id).update(**update) +class FoiMessageDraft(FoiMessage): + objects = FoiMessageDraftManager() + + class Meta: + proxy = True + verbose_name = _("Freedom of Information Message Draft") + verbose_name_plural = _("Freedom of Information Message Drafts") + + class Delivery(models.TextChoices): STATUS_UNKNOWN = ("unknown", _("unknown")) STATUS_SENDING = ("sending", _("sending"))