diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-06 15:52:40 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-06 15:52:40 +0200 |
commit | e2027c3b2c4bcc2356ec06b5fb6dc8d5bf780e50 (patch) | |
tree | ced06e4a3e0ef4600d2dbbf2741f001125c162bf /archaeological_context_records/forms.py | |
parent | 180d93d47cfae279ef927ea5fa736fa1fc37c553 (diff) | |
parent | b7a7183cdb07c7782abac7fe01d86cc2beb1411e (diff) | |
download | Ishtar-e2027c3b2c4bcc2356ec06b5fb6dc8d5bf780e50.tar.bz2 Ishtar-e2027c3b2c4bcc2356ec06b5fb6dc8d5bf780e50.zip |
Merge branch 'master' into v0.9
Diffstat (limited to 'archaeological_context_records/forms.py')
-rw-r--r-- | archaeological_context_records/forms.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 462300317..daaf5f5ed 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -43,6 +43,18 @@ from archaeological_operations.forms import OperationSelect, ParcelField,\ RecordRelationsForm as OpeRecordRelationsForm +class OperationFormSelection(forms.Form): + form_label = _("Operation") + associated_models = {'operation': Operation} + currents = {'operation': Operation} + operation = forms.IntegerField( + label=_(u"Operation"), required=False, + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-operation'), + associated_model=Operation), + validators=[valid_id(Operation)]) + + class RecordSelect(TableSelect): label = forms.CharField(label=_(u"ID"), max_length=100) parcel__town = get_town_field() @@ -148,7 +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 + # 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 |