summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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()