diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-06 11:06:13 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-06 11:06:13 +0200 |
commit | 72d891dd94c72fdb16023e8e712c942135d7e556 (patch) | |
tree | 991f227457cdbb0f8eda15e7616e04800e7c8419 /archaeological_context_records/forms.py | |
parent | 284c18281b50c3c33f4515020568aa75c913f46e (diff) | |
download | Ishtar-72d891dd94c72fdb16023e8e712c942135d7e556.tar.bz2 Ishtar-72d891dd94c72fdb16023e8e712c942135d7e556.zip |
Fix context records creation (refs #3080)
Diffstat (limited to 'archaeological_context_records/forms.py')
-rw-r--r-- | archaeological_context_records/forms.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 225b49bfb..daaf5f5ed 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -160,10 +160,24 @@ class RecordFormGeneral(ManageOldType, forms.Form): ('operation' in kwargs['data'] or 'context_record' in kwargs['data']): if 'operation' in kwargs['data']: - operation = kwargs['data']['operation'] + operation = kwargs['data'].pop('operation') + if type(operation) in (list, tuple): + operation = operation[0] + if not hasattr(operation, 'id'): + operation_id = operation + try: + operation = Operation.objects.get(pk=operation_id) + except Operation.DoesNotExist: + operation = None # force operation modification - kwargs['data'][kwargs['prefix'] + '-operation_id'] = \ - operation.id + # if posted + if operation and kwargs['data']: + if hasattr(operation, 'id'): + kwargs['data'][kwargs['prefix'] + '-operation_id'] = \ + operation.id + else: + kwargs['data'][kwargs['prefix'] + '-operation_id'] = \ + operation if 'context_record' in kwargs['data'] and \ kwargs['data']['context_record']: operation = kwargs['data']['context_record'].operation |