From 82e78630103d8e40eed2113f09ee1c69fc6841b3 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 6 Sep 2016 10:36:40 +0200 Subject: Context record: can change operation (refs #3080) --- archaeological_context_records/forms.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'archaeological_context_records/forms.py') diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 462300317..225b49bfb 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() @@ -149,6 +161,9 @@ class RecordFormGeneral(ManageOldType, forms.Form): 'context_record' in kwargs['data']): if 'operation' in kwargs['data']: operation = kwargs['data']['operation'] + # force operation modification + kwargs['data'][kwargs['prefix'] + '-operation_id'] = \ + operation.id if 'context_record' in kwargs['data'] and \ kwargs['data']['context_record']: operation = kwargs['data']['context_record'].operation -- cgit v1.2.3 From 0e5f45823423ffc63efc9b963a04ab8ebcd35a2a Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 6 Sep 2016 11:06:13 +0200 Subject: Fix context records creation (refs #3080) --- archaeological_context_records/forms.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'archaeological_context_records/forms.py') 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 -- cgit v1.2.3