Add schedule publishing success messages in generic and snippets create/edit views

pull/8812/head
Sage Abdullah 2022-08-11 12:55:30 +07:00 zatwierdzone przez Matt Westcott
rodzic 5112da98bb
commit e9e1ad8cf7
3 zmienionych plików z 39 dodań i 7 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ from django.forms import Media
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils import timezone
from django.utils.safestring import mark_safe
from django.utils.text import capfirst
from django.utils.translation import gettext as _
@ -209,11 +210,16 @@ class RevisionsRevertMixin:
message = _(
"{model_name} '{instance}' has been replaced with version from {timestamp}."
)
if self.action == "publish":
if self.draftstate_enabled and self.action == "publish":
message = _(
"Version from {timestamp} of {model_name} '{instance}' has been published."
)
if self.object.go_live_at and self.object.go_live_at > timezone.now():
message = _(
"Version from {timestamp} of {model_name} '{instance}' has been scheduled for publishing."
)
return message.format(
model_name=capfirst(self.model._meta.verbose_name),
instance=self.object,

Wyświetl plik

@ -8,6 +8,7 @@ from django.forms import Form
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy
from django.views.generic import TemplateView
@ -399,8 +400,11 @@ class CreateView(
return reverse(self.index_url_name)
def get_success_message(self, instance):
if self.action == "publish":
return _("'{0}' has been created and published.").format(str(instance))
if isinstance(instance, DraftStateMixin) and self.action == "publish":
if instance.go_live_at and instance.go_live_at > timezone.now():
return _("'{0}' created and scheduled for publishing.").format(instance)
return _("'{0}' created and published.").format(instance)
if self.success_message is None:
return None
return self.success_message.format(instance)
@ -622,8 +626,13 @@ class EditView(
return None
def get_success_message(self):
if self.action == "publish":
return _("'{0}' has been published.").format(str(self.object))
if self.draftstate_enabled and self.action == "publish":
if self.object.go_live_at and self.object.go_live_at > timezone.now():
return _("'{0}' updated and scheduled for publishing.").format(
self.object
)
return _("'{0}' updated and published.").format(self.object)
if self.success_message is None:
return None
return self.success_message.format(self.object)

Wyświetl plik

@ -10,6 +10,7 @@ from django.db import transaction
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect
from django.urls import path, re_path, reverse
from django.utils import timezone
from django.utils.text import capfirst
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy, ngettext
@ -243,8 +244,13 @@ class CreateView(generic.CreateView):
def get_success_message(self, instance):
message = _("%(snippet_type)s '%(instance)s' created.")
if self.action == "publish":
if isinstance(instance, DraftStateMixin) and self.action == "publish":
message = _("%(snippet_type)s '%(instance)s' created and published.")
if instance.go_live_at and instance.go_live_at > timezone.now():
message = _(
"%(snippet_type)s '%(instance)s' created and scheduled for publishing."
)
return message % {
"snippet_type": capfirst(self.model._meta.verbose_name),
"instance": instance,
@ -371,9 +377,20 @@ class EditView(generic.EditView):
def get_success_message(self):
message = _("%(snippet_type)s '%(instance)s' updated.")
if self.action == "publish":
if self.draftstate_enabled and self.action == "publish":
message = _("%(snippet_type)s '%(instance)s' updated and published.")
if self.object.go_live_at and self.object.go_live_at > timezone.now():
message = _(
"%(snippet_type)s '%(instance)s' has been scheduled for publishing."
)
if self.object.live:
message = _(
"%(snippet_type)s '%(instance)s' is live and this version has been scheduled for publishing."
)
return message % {
"snippet_type": capfirst(self.model._meta.verbose_name),
"instance": self.object,