summaryrefslogtreecommitdiff
path: root/postgresqleu/util
diff options
context:
space:
mode:
authorMagnus Hagander2024-01-17 10:10:30 +0000
committerMagnus Hagander2024-01-17 10:21:43 +0000
commitaedb4188505b7e4e7af48e04d76aa42af9fb2309 (patch)
tree6358122c3bdde8ffc75b34608c138bc7149e20ca /postgresqleu/util
parent06ed2510742a89893c1c5b7a0bf8fdd0b3874204 (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')
-rw-r--r--postgresqleu/util/backendforms.py4
-rw-r--r--postgresqleu/util/backendviews.py27
2 files changed, 19 insertions, 12 deletions
diff --git a/postgresqleu/util/backendforms.py b/postgresqleu/util/backendforms.py
index 8af4ea28..c796b145 100644
--- a/postgresqleu/util/backendforms.py
+++ b/postgresqleu/util/backendforms.py
@@ -172,6 +172,10 @@ class BackendForm(ConcurrentProtectedModelForm):
def get_assignable_columns(cls, conference):
return {}
+ @classmethod
+ def assign_assignable_column(cls, obj, what, setval):
+ setattr(obj, what, setval)
+
def pre_create_item(self):
pass
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()