mirror of https://gitlab.crans.org/bde/nk20
Display form error when a permission is missing rather than display a 403 page
This commit is contained in:
parent
227cb2a801
commit
7d539d44e5
|
@ -20,7 +20,7 @@ from .models import Activity, Entry, Guest
|
||||||
from .tables import ActivityTable, EntryTable, GuestTable
|
from .tables import ActivityTable, EntryTable, GuestTable
|
||||||
|
|
||||||
|
|
||||||
class ActivityCreateView(ProtectedCreateView):
|
class ActivityCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||||
"""
|
"""
|
||||||
View to create a new Activity
|
View to create a new Activity
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -43,6 +43,24 @@ class ProtectQuerysetMixin:
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
"""
|
||||||
|
Submit the form, if the page is a FormView.
|
||||||
|
If a PermissionDenied exception is raised, catch the error and display it at the top of the form.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return super().form_valid(form)
|
||||||
|
except PermissionDenied:
|
||||||
|
if isinstance(self, UpdateView):
|
||||||
|
form.add_error(None, _("You don't have the permission to update this instance of the model \"{model}\""
|
||||||
|
" with these parameters. Please correct your data and retry.")
|
||||||
|
.format(model=self.model._meta.verbose_name))
|
||||||
|
else:
|
||||||
|
form.add_error(None, _("You don't have the permission to create an instance of the model \"{model}\""
|
||||||
|
" with these parameters. Please correct your data and retry.")
|
||||||
|
.format(model=self.model._meta.verbose_name))
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
|
||||||
class ProtectedCreateView(LoginRequiredMixin, CreateView):
|
class ProtectedCreateView(LoginRequiredMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue