[Django] #35850: Default success messages for CreateView/UpdateView/DeleteView/...

6 views
Skip to first unread message

Django

unread,
Oct 18, 2024, 7:22:56 AM10/18/24
to django-...@googlegroups.com
#35850: Default success messages for CreateView/UpdateView/DeleteView/...
-------------------------------------+-------------------------------------
Reporter: Willem Van Onsem | Type: New
| feature
Status: new | Component: Generic
| views
Version: 5.0 | Severity: Normal
Keywords: translations, | Triage Stage:
success-message, views | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Hi,

I'm wondering if it would make sense to provide default success messages
for the `CreatView`/`UpdateView`/`DeleteView` that will *not* be enabled
as long as the `SuccessMessageMixin` is not enabled, but are when that is
the case.

In order to do that we would have to split the `SuccessMessageMixin` to
trick the MRO in overriding the message. So that would look like:

{{{
class BaseSuccessMessageMixin:
success_message = ""


class SuccessMessageMixin(BaseSuccessMessageMixin):
"""
Add a success message on successful form submission.
"""

def form_valid(self, form):
response = super().form_valid(form)
success_message = self.get_success_message(form.cleaned_data)
if success_message:
messages.success(self.request, success_message)
return response

def get_success_message(self, cleaned_data):
return self.success_message % cleaned_data
}}}

then we can define a `DeleteView` like:

{{{
class DeleteView(SingleObjectTemplateResponseMixin,
BaseSuccessMessageMixin, BaseDeleteView):
success_message = _('The object has been deleted successfully')
}}}

This would make a simple message easily translatable: people can just add
a custom translation and the other ones are retained.

The `BaseSuccessMessageMixin` is necessary to make sure that if someone
inherits the `SuccessMessageMixin`, it will *not* override the
`success_message` once again by the empty string.
--
Ticket URL: <https://code.djangoproject.com/ticket/35850>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 18, 2024, 8:57:08 AM10/18/24
to django-...@googlegroups.com
#35850: Default success messages for CreateView/UpdateView/DeleteView/...
-------------------------------------+-------------------------------------
Reporter: Willem Van Onsem | Owner: (none)
Type: New feature | Status: closed
Component: Generic views | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: translations, | Triage Stage:
success-message, views | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* resolution: => wontfix
* status: new => closed
* version: 5.0 => dev

Comment:

Hello Willen, thank you for taking the time to create this report.

I feel this feature request is a bit tricky because getting a default
message right is non-trivial, and OTOH setting a success message on a
specific view is very, very straightforward. Adding to that, the solution
proposed adds a complexity that I feel is not worth the minimal gain.

Given the above, I'll close the ticket accordingly, but if you disagree,
you can consider starting a new conversation on the
[https://forum.djangoproject.com/c/internals/5 Django Forum], where you'll
reach a wider audience and likely get extra feedback. More information in
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features].

Have a good weekend!
--
Ticket URL: <https://code.djangoproject.com/ticket/35850#comment:1>
Reply all
Reply to author
Forward
0 new messages