diff options
| -rw-r--r-- | ishtar/furnitures/forms.py | 5 | ||||
| -rw-r--r-- | ishtar/furnitures/models.py | 56 | ||||
| -rw-r--r-- | ishtar/templates/sheet_contextrecord.html | 4 | ||||
| -rw-r--r-- | ishtar/templates/sheet_operation.html | 4 | 
4 files changed, 55 insertions, 14 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index 0f93a94bc..2449ede98 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -365,6 +365,9 @@ class Wizard(NamedUrlSessionFormWizard):              obj.save()              for k in adds:                  getattr(obj, k).add(adds[k]) +            # necessary to manage interaction between models like +            # material_index management for baseitems +            obj.save()          m2m_items = {}          for key, value in m2m:              if key not in m2m_items: @@ -387,6 +390,8 @@ class Wizard(NamedUrlSessionFormWizard):                      value = model.objects.create(**value)                      value.save()                  getattr(obj, key+'s').add(value) +                # necessary to manage interaction between models like +                # material_index management for baseitems                  obj.save()          res = render_to_response('wizard_done.html', {},                                    context_instance=RequestContext(request)) diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py index 44e0e9391..1e0072c45 100644 --- a/ishtar/furnitures/models.py +++ b/ishtar/furnitures/models.py @@ -27,7 +27,7 @@ from django.core.validators import validate_slug  from django.utils.translation import ugettext_lazy as _, ugettext  from django.db.utils import DatabaseError  from django.utils.safestring import SafeUnicode -from django.db.models import Q +from django.db.models import Q, Max  from django.contrib.auth.models import User  from django.contrib.gis.db import models @@ -804,6 +804,8 @@ class BaseItem(BaseHistorizedItem, OwnPerms):                related_name='base_items', verbose_name=_(u"Context Record"))      is_isolated = models.NullBooleanField(_(u"Is isolated?"), blank=True,                                            null=True) +    index = models.IntegerField(u"Index", default=0) +    material_index = models.IntegerField(u"Material index", default=0)      documentations = models.ManyToManyField(Source)      history = HistoricalRecords() @@ -822,25 +824,45 @@ class BaseItem(BaseHistorizedItem, OwnPerms):      def get_last_item(self):          #TODO: manage virtuals - property(last_item) ? -        return self.item.filter().order_by("-order").all()[0] +        items = self.item.filter().order_by("-order").all() +        return items and items[0]      def full_label(self):          return self._real_label() or self._temp_label() +    def material_type_label(self): +        item = self.get_last_item() +        lbl = item and (unicode(item.material_type) + unicode(_(": "))) or '' +        if self.context_record.parcel.operation.code_patriarche: +            return lbl + JOINT.join([unicode(it) for it in ( +                           self.context_record.parcel.operation.code_patriarche, +                           self.context_record.label, +                           self.material_index, +                           self.label)]) +        return lbl + JOINT.join([unicode(it) for it in ( +                           self.context_record.parcel.year, +                           self.index, +                           self.context_record.label, +                           self.material_index, +                           self.label)]) + +      def _real_label(self):          if not self.context_record.parcel.operation.code_patriarche:              return -        return JOINT.join((self.context_record.parcel.operation.code_patriarche, +        return JOINT.join([unicode(it) for it in ( +                           self.context_record.parcel.operation.code_patriarche,                             self.context_record.label, -                           self.label)) +                           self.label)])      def _temp_label(self):          if self.context_record.parcel.operation.code_patriarche:              return -        return JOINT.join((self.context_record.parcel.year, -                           #TODO:self.index +        return JOINT.join([unicode(it) for it in ( +                           self.context_record.parcel.year, +                           self.index,                             self.context_record.label, -                           self.label)) +                           self.label)])  class Item(BaseHistorizedItem, OwnPerms):      TABLE_COLS = ['base_items.context_record.parcel.town', @@ -881,9 +903,23 @@ class Item(BaseHistorizedItem, OwnPerms):      def __unicode__(self):          return self.label -    def material_type_label(self): -        #TODO to complete cf. #372 and sheet_contextrecord template -        return unicode(self.material_type) +    def save(self, *args, **kwargs): +        if not self.pk: +            super(Item, self).save(*args, **kwargs) +        for base_item in self.base_items.all(): +            if not base_item.index: +                idx = BaseItem.objects.filter(context_record=\ +                      base_item.context_record).aggregate(Max('index')) +                base_item.index = idx and idx['index__max'] + 1 or 1 +            if not base_item.material_index: +                idx = BaseItem.objects.filter(context_record=\ +                        base_item.context_record, +                        item__material_type=self.material_type).aggregate( +                                                      Max('material_index')) +                base_item.material_index = idx and \ +                                        idx['material_index__max'] + 1 or 1 +            base_item.save() +        super(Item, self).save(*args, **kwargs)  class ParcelOwner(LightHistorizedItem): diff --git a/ishtar/templates/sheet_contextrecord.html b/ishtar/templates/sheet_contextrecord.html index 0f7259f3a..76b76183f 100644 --- a/ishtar/templates/sheet_contextrecord.html +++ b/ishtar/templates/sheet_contextrecord.html @@ -115,11 +115,11 @@      <td>{{ find.full_label }}</td>  {# Displayed as (Patriarche operation code)-(Record unit label)-(Finds label). #}  {# or displayed as (Year)-(index)-(Record unit label)-(Finds label). #} -    <td>{{ find.get_last_item.material_type_label }}</td> +    <td>{{ find.material_type_label }}</td>  {# Displayed as (Patriarche operation code)-(Record unit label)-(material code)-(Finds label indexed by material type). #}  {# or displayed as (Year)-(index)-(Record unit label)-(material code)-(Finds label indexed by material type) #} -    <td class='string'>{{find.context_record.short_label}}</td> +    <td class='string'>{{find.context_record}}</td>      <td>{{ find.get_last_item.dating}}</td>{# TODO .all|join:", " ? #}      <td>{{ find.get_last_item.description }}</td>      <td>{{ find.get_last_item.weight }}</td> diff --git a/ishtar/templates/sheet_operation.html b/ishtar/templates/sheet_operation.html index 7cf6554b4..3a76ccf4e 100644 --- a/ishtar/templates/sheet_operation.html +++ b/ishtar/templates/sheet_operation.html @@ -166,11 +166,11 @@      <td>{{ find.full_label }}</td>  {# Displayed as (Patriarche operation code)-(Record unit label)-(Finds label). #}  {# or displayed as (Year)-(index)-(Record unit label)-(Finds label). #} -    <td>{{ find.get_last_item.material_type_label }}</td> +    <td>{{ find.material_type_label }}</td>  {# Displayed as (Patriarche operation code)-(Record unit label)-(material code)-(Finds label indexed by material type). #}  {# or displayed as (Year)-(index)-(Record unit label)-(material code)-(Finds label indexed by material type) #} -    <td class='string'>{{find.context_record.short_label}}</td> +    <td class='string'>{{find.context_record}}</td>      <td>{{ find.get_last_item.dating}}</td>{# TODO .all|join:", " ? #}      <td>{{ find.get_last_item.description }}</td>      <td>{{ find.get_last_item.weight }}</td>  | 
