diff options
author | Magnus Hagander | 2020-05-11 19:47:59 +0000 |
---|---|---|
committer | Magnus Hagander | 2020-05-11 19:47:59 +0000 |
commit | 82be16363b06f95b392af24ecae77c6c4c80a7ec (patch) | |
tree | 27da0b8e14a2c1b5a1a3f48621c9e9716802d508 /postgresqleu/util/backendviews.py | |
parent | bad6b69dcbd877843b935189bd5120c93a4f9481 (diff) |
Add field and widget to support a custom submit button in backend forms
This form will not do a regular save, and instead call a callback
function defined on the field.
Diffstat (limited to 'postgresqleu/util/backendviews.py')
-rw-r--r-- | postgresqleu/util/backendviews.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/postgresqleu/util/backendviews.py b/postgresqleu/util/backendviews.py index 61c29108..d5544265 100644 --- a/postgresqleu/util/backendviews.py +++ b/postgresqleu/util/backendviews.py @@ -108,7 +108,7 @@ def backend_process_form(request, urlname, formclass, id, cancel_url='../', save if request.method == 'POST' and not nopostprocess: extra_error = None - if allow_delete and request.POST['submit'] == 'Delete': + if allow_delete and request.POST.get('submit', None) == 'Delete': if instance.pk: if hasattr(instance, 'validate_object_delete'): try: @@ -141,6 +141,15 @@ def backend_process_form(request, urlname, formclass, id, cancel_url='../', save if extra_error: form.add_error(None, extra_error) + # Figure out if a custom submit button was pressed + for k, v in request.POST.items(): + if k.startswith('submit_id_'): + # We do! + f = form.fields[k[10:]] + if f.callback: + f.callback(request) + return HttpResponseRedirect(".") + if form.is_valid(): # We don't want to use form.save(), because it actually saves all # fields on the model, including those we don't care about. |