From 953a9dfb33a96dbaa4fa69ad7c43555574764d1c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 3 Jul 2011 20:01:56 +0200 Subject: Correct Context records creation (closes #496) --- ishtar/ishtar_base/forms.py | 1 + ishtar/ishtar_base/forms_context_records.py | 18 ++++++++++++------ ishtar/ishtar_base/models.py | 7 ++++++- ishtar/templates/sheet_file.html | 2 +- ishtar/templates/sheet_operation.html | 4 ++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ishtar/ishtar_base/forms.py b/ishtar/ishtar_base/forms.py index 85c4371d4..f69b5dcd4 100644 --- a/ishtar/ishtar_base/forms.py +++ b/ishtar/ishtar_base/forms.py @@ -368,6 +368,7 @@ class Wizard(NamedUrlSessionFormWizard): dct[dependant_item] = c_item if 'pk' in dct: dct.pop('pk') + print self.get_saved_model() obj = self.get_saved_model()(**dct) obj.save() for k in adds: diff --git a/ishtar/ishtar_base/forms_context_records.py b/ishtar/ishtar_base/forms_context_records.py index 35b7b785c..27b7fc6f2 100644 --- a/ishtar/ishtar_base/forms_context_records.py +++ b/ishtar/ishtar_base/forms_context_records.py @@ -37,7 +37,7 @@ from forms import Wizard, FinalForm, FormSet, SearchWizard, DeletionWizard, \ formset_factory, get_now, reverse_lazy, get_form_selection from forms_common import get_town_field, SourceForm, SourceWizard, \ SourceSelect, AuthorFormset -from forms_operations import OperationFormSelection +from forms_operations import OperationSelect class RecordWizard(Wizard): model = models.ContextRecord @@ -51,7 +51,7 @@ class RecordWizard(Wizard): main_form_key = 'selec-' + self.url_name try: idx = int(self.session_get_value(request, storage, - main_form_key, 'pk')) + main_form_key, 'operation_id')) current_ope = models.Operation.objects.get(pk=idx) return current_ope except(TypeError, ValueError, ObjectDoesNotExist): @@ -95,7 +95,7 @@ class RecordWizard(Wizard): main_form_key = 'selec-' + self.url_name try: idx = int(self.session_get_value(request, storage, - main_form_key, 'pk')) + main_form_key, 'operation_id')) current_obj = models.Operation.objects.get(pk=idx) data['operation'] = current_obj except(TypeError, ValueError, ObjectDoesNotExist): @@ -163,12 +163,12 @@ class RecordFormGeneral(forms.Form): def __init__(self, *args, **kwargs): operation = None if 'data' in kwargs and kwargs['data'] and \ - ('operation' in kwargs['data'] or 'context_record' in kwargs['data']): + ('operation' in kwargs['data'] or 'context_record' in kwargs['data']): if 'operation' in kwargs['data']: operation = kwargs['data']['operation'] if 'context_record' in kwargs['data'] and \ kwargs['data']['context_record']: - operation = kwargs['data']['context_record'].parcel.operation + operation = kwargs['data']['context_record'].operation # clean data if not "real" data prefix_value = kwargs['prefix'] if not [k for k in kwargs['data'].keys() @@ -261,8 +261,14 @@ record_search_wizard = SearchWizard([ ('general-record_search', RecordFormSelection)], url_name='record_search',) +OperationRecordFormSelection = get_form_selection( + 'OperationRecordFormSelection', _(u"Operation search"), 'operation_id', + models.Operation, OperationSelect, 'get-operation', + _(u"You should select an operation.")) + + record_creation_wizard = RecordWizard([ - ('selec-record_creation', OperationFormSelection), + ('selec-record_creation', OperationRecordFormSelection), ('general-record_creation', RecordFormGeneral), ('datings-record_creation', DatingFormSet), ('interpretation-record_creation', RecordFormInterpretation), diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py index 9874460b9..b4745741a 100644 --- a/ishtar/ishtar_base/models.py +++ b/ishtar/ishtar_base/models.py @@ -868,7 +868,12 @@ class ContextRecord(BaseHistorizedItem, OwnPerms): ) def __unicode__(self): - return JOINT.join((unicode(self.parcel), self.label)) + return self.short_label() + + def short_label(self): + return JOINT.join([unicode(item) for item in [self.parcel, + self.label] if item]) + def full_label(self): if not self.parcel.operation: diff --git a/ishtar/templates/sheet_file.html b/ishtar/templates/sheet_file.html index 1ba043239..ea5842991 100644 --- a/ishtar/templates/sheet_file.html +++ b/ishtar/templates/sheet_file.html @@ -47,7 +47,7 @@ {% if item.address_complement %}

{{ item.address_complement }}

{%endif%} {% if item.postal_code %}

{{ item.postal_code }}

{%endif%} -

{{ item.total_surface }} m2 ({{ item.total_surface_ha }} ha)

+

{% if item.total_surface %} {{ item.total_surface }} m2 ({{ item.total_surface_ha }} ha){%endif%}

diff --git a/ishtar/templates/sheet_operation.html b/ishtar/templates/sheet_operation.html index b2713602f..5919d8922 100644 --- a/ishtar/templates/sheet_operation.html +++ b/ishtar/templates/sheet_operation.html @@ -130,8 +130,8 @@ {% for context_record in item.context_record.all %} - {{ context_record.label }} - {{context_record.unit}} + {{ context_record.label }} + {{context_record.unit|default:""}} {{ context_record.datings.all|join:", " }}{# periods ?#} {{ context_record.description }} {{ context_record.parcel.section }} - {{context_record.parcel.parcel_number}} -- cgit v1.2.3