diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-07-03 20:01:56 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-07-03 20:01:56 +0200 | 
| commit | 64dedcf926d23a2574f800c5db1fb66ecb109ed6 (patch) | |
| tree | 5e510cca9ace14ca3f51c1107f702931d4f74211 | |
| parent | f16f5ee1a62d2698379e5083c7bfc91cdfe2e299 (diff) | |
| download | Ishtar-64dedcf926d23a2574f800c5db1fb66ecb109ed6.tar.bz2 Ishtar-64dedcf926d23a2574f800c5db1fb66ecb109ed6.zip | |
Correct Context records creation (closes #496)
| -rw-r--r-- | ishtar/ishtar_base/forms.py | 1 | ||||
| -rw-r--r-- | ishtar/ishtar_base/forms_context_records.py | 18 | ||||
| -rw-r--r-- | ishtar/ishtar_base/models.py | 7 | ||||
| -rw-r--r-- | ishtar/templates/sheet_file.html | 2 | ||||
| -rw-r--r-- | 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 %}<p><label>{%trans "Complement:"%}</label> <span class='value'>{{ item.address_complement }}</span></p>{%endif%}  {% if item.postal_code %}<p><label>{%trans "Postal code:"%}</label> <span class='value'>{{ item.postal_code }}</span></p>{%endif%} -<p><label>{%trans "Surface:"%}</label> <span class='value'>{{ item.total_surface }} m<sup>2</sup> ({{ item.total_surface_ha }} ha)</span></p> +<p><label>{%trans "Surface:"%}</label>{% if item.total_surface %} <span class='value'>{{ item.total_surface }} m<sup>2</sup> ({{ item.total_surface_ha }} ha)</span>{%endif%}</p> 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 @@    </tr>    {% for context_record in item.context_record.all %}    <tr> -    <td>{{ context_record.label }}</td> -    <td class='string'>{{context_record.unit}}</td> +    <td class='string'>{{ context_record.label }}</td> +    <td class='string'>{{context_record.unit|default:""}}</td>      <td class='string'>{{ context_record.datings.all|join:", " }}</td>{# periods ?#}      <td class='string'>{{ context_record.description }}</td>      <td class='string'>{{ context_record.parcel.section }} - {{context_record.parcel.parcel_number}}</td> | 
