diff options
author | Magnus Hagander | 2024-01-17 10:10:30 +0000 |
---|---|---|
committer | Magnus Hagander | 2024-01-17 10:21:43 +0000 |
commit | aedb4188505b7e4e7af48e04d76aa42af9fb2309 (patch) | |
tree | 6358122c3bdde8ffc75b34608c138bc7149e20ca /postgresqleu/util/backendviews.py | |
parent | 06ed2510742a89893c1c5b7a0bf8fdd0b3874204 (diff) |
Make actual assignment of assignable column overridable
In doing so, allow for the override function to raise a ValidationError
on an individual object, in which case this object is not updated and
the error is shown to the user, but other objects are still processed.
Diffstat (limited to 'postgresqleu/util/backendviews.py')
-rw-r--r-- | postgresqleu/util/backendviews.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/postgresqleu/util/backendviews.py b/postgresqleu/util/backendviews.py index 94a273c4..8be4d1cc 100644 --- a/postgresqleu/util/backendviews.py +++ b/postgresqleu/util/backendviews.py @@ -280,19 +280,22 @@ def backend_list_editor(request, urlname, formclass, resturl, allow_new=True, al with transaction.atomic(): for obj in objects.filter(id__in=request.POST.get('idlist').split(',')): - if isinstance(getattr(obj, what), bool): - # Special-case booleans, they can only be set to true or false, and clearfing - # means the same as set to false. - if setval: - setattr(obj, what, True) + try: + if isinstance(getattr(obj, what), bool): + # Special-case booleans, they can only be set to true or false, and clearfing + # means the same as set to false. + if setval: + formclass.assign_assignable_column(obj, what, True) + else: + formclass.assign_assignable_column(obj, what, False) else: - setattr(obj, what, False) - else: - if setval is not None: - setattr(obj, what, setval) - else: - setattr(obj, what, None) - obj.save() + if setval is not None: + formclass.assign_assignable_column(obj, what, setval) + else: + formclass.assign_assignable_column(obj, what, None) + obj.save() + except ValidationError as e: + messages.warning(request, 'Could not update "{}": {}'.format(obj, e.message)) return HttpResponseRedirect('.') else: raise Http404() |