diff options
Diffstat (limited to 'archaeological_finds/models.py')
| -rw-r--r-- | archaeological_finds/models.py | 134 | 
1 files changed, 67 insertions, 67 deletions
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index cea9a35f1..c61e22e68 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -39,11 +39,11 @@ class MaterialType(GeneralType):          verbose_name = _(u"Material type")          verbose_name_plural = _(u"Material types") -class BaseItem(BaseHistorizedItem, OwnPerms): +class BaseFind(BaseHistorizedItem, OwnPerms):      label = models.CharField(_(u"ID"), max_length=60)      description = models.TextField(_(u"Description"))      context_record = models.ForeignKey(ContextRecord, -              related_name='base_items', verbose_name=_(u"Context Record")) +              related_name='base_finds', verbose_name=_(u"Context Record"))      is_isolated = models.NullBooleanField(_(u"Is isolated?"), blank=True,                                            null=True)      index = models.IntegerField(u"Index", default=0) @@ -51,40 +51,40 @@ class BaseItem(BaseHistorizedItem, OwnPerms):      history = HistoricalRecords()      class Meta: -        verbose_name = _(u"Base item") -        verbose_name_plural = _(u"Base items") +        verbose_name = _(u"Base find") +        verbose_name_plural = _(u"Base finds")          permissions = ( -            ("view_own_baseitem", ugettext(u"Can view own Base item")), -            ("add_own_baseitem", ugettext(u"Can add own Base item")), -            ("change_own_baseitem", ugettext(u"Can change own Base item")), -            ("delete_own_baseitem", ugettext(u"Can delete own Base item")), +            ("view_own_basefind", ugettext(u"Can view own Base find")), +            ("add_own_basefind", ugettext(u"Can add own Base find")), +            ("change_own_basefind", ugettext(u"Can change own Base find")), +            ("delete_own_basefind", ugettext(u"Can delete own Base find")),          )      def __unicode__(self):          return self.label -    def get_last_item(self): -        #TODO: manage virtuals - property(last_item) ? -        items = self.item.filter().order_by("-order").all() -        return items and items[0] +    def get_last_find(self): +        #TODO: manage virtuals - property(last_find) ? +        finds = self.find.filter().order_by("-order").all() +        return finds and finds[0]      def full_label(self):          return self._real_label() or self._temp_label()      def material_type_label(self): -        item = self.get_last_item() -        items = [item and unicode(item.material_type) or ''] +        find = self.get_last_find() +        finds = [find and unicode(find.material_type) or '']          ope = self.context_record.operation -        items += [ope.code_patriarche or \ +        finds += [ope.code_patriarche or \                    (unicode(ope.year) + "-" + unicode(ope.operation_code))] -        items += [self.context_record.label, unicode(self.material_index)] -        return JOINT.join(items) +        finds += [self.context_record.label, unicode(self.material_index)] +        return JOINT.join(finds)      def _real_label(self):          if not self.context_record.parcel.operation.code_patriarche:              return -        item = self.get_last_item() -        lbl = item.label or self.label +        find = self.get_last_find() +        lbl = find.label or self.label          return JOINT.join([unicode(it) for it in (                             self.context_record.parcel.operation.code_patriarche,                             self.context_record.label, @@ -93,25 +93,25 @@ class BaseItem(BaseHistorizedItem, OwnPerms):      def _temp_label(self):          if self.context_record.parcel.operation.code_patriarche:              return -        item = self.get_last_item() -        lbl = item.label or self.label +        find = self.get_last_find() +        lbl = find.label or self.label          return JOINT.join([unicode(it) for it in (                             self.context_record.parcel.year,                             self.index,                             self.context_record.label,                             lbl) if it]) -class Item(BaseHistorizedItem, OwnPerms): +class Find(BaseHistorizedItem, OwnPerms):      TABLE_COLS = ['label', 'material_type', 'dating.period', -                  'base_items.context_record.parcel.town', -                  'base_items.context_record.parcel.operation.year', -                  'base_items.context_record.parcel.operation.operation_code', -                  'base_items.is_isolated'] +                  'base_finds.context_record.parcel.town', +                  'base_finds.context_record.parcel.operation.year', +                  'base_finds.context_record.parcel.operation.operation_code', +                  'base_finds.is_isolated']      if settings.COUNTRY == 'fr':          TABLE_COLS.insert(6, -                  'base_items.context_record.parcel.operation.code_patriarche') -    base_items = models.ManyToManyField(BaseItem, verbose_name=_(u"Base item"), -                                        related_name='item') +                  'base_finds.context_record.parcel.operation.code_patriarche') +    base_finds = models.ManyToManyField(BaseFind, verbose_name=_(u"Base find"), +                                        related_name='find')      order = models.IntegerField(_(u"Order"))      label = models.CharField(_(u"ID"), max_length=60)      description = models.TextField(_(u"Description"), blank=True, null=True) @@ -119,7 +119,7 @@ class Item(BaseHistorizedItem, OwnPerms):                                verbose_name = _(u"Material type"))      volume = models.FloatField(_(u"Volume (l)"), blank=True, null=True)      weight = models.FloatField(_(u"Weight (g)"), blank=True, null=True) -    item_number = models.IntegerField(_("Item number"), blank=True, null=True) +    find_number = models.IntegerField(_("Find number"), blank=True, null=True)      upstream_treatment = models.ForeignKey("Treatment", blank=True, null=True,        related_name='downstream_treatment', verbose_name=_("Upstream treatment"))      downstream_treatment = models.ForeignKey("Treatment", blank=True, null=True, @@ -127,15 +127,15 @@ class Item(BaseHistorizedItem, OwnPerms):      dating = models.ForeignKey(Dating, verbose_name=_(u"Dating"))      if WAREHOUSE_AVAILABLE:          container = models.ForeignKey(Container, verbose_name=_(u"Container"), -                                  blank=True, null=True, related_name='items') +                                  blank=True, null=True, related_name='finds')      history = HistoricalRecords()      @classmethod      def get_years(cls):          years = set() -        items = cls.objects.filter(downstream_treatment__isnull=True) -        for item in items: -            bi = item.base_items.all() +        finds = cls.objects.filter(downstream_treatment__isnull=True) +        for find in finds: +            bi = find.base_finds.all()              if not bi:                  continue              bi = bi[0] @@ -146,14 +146,14 @@ class Item(BaseHistorizedItem, OwnPerms):      @classmethod      def get_by_year(cls, year):          return cls.objects.filter(downstream_treatment__isnull=True, -                base_items__context_record__operation__start_date__year=year) +                base_finds__context_record__operation__start_date__year=year)      @classmethod      def get_operations(cls):          operations = set() -        items = cls.objects.filter(downstream_treatment__isnull=True) -        for item in items: -            bi = item.base_items.all() +        finds = cls.objects.filter(downstream_treatment__isnull=True) +        for find in finds: +            bi = find.base_finds.all()              if not bi:                  continue              bi = bi[0] @@ -164,7 +164,7 @@ class Item(BaseHistorizedItem, OwnPerms):      @classmethod      def get_by_operation(cls, operation_id):          return cls.objects.filter(downstream_treatment__isnull=True, -                base_items__context_record__operation__pk=operation_id) +                base_finds__context_record__operation__pk=operation_id)      @classmethod      def get_total_number(cls): @@ -173,23 +173,23 @@ class Item(BaseHistorizedItem, OwnPerms):      def duplicate(self, user):          dct = dict([(attr, getattr(self, attr)) for attr in ('order', 'label',                          'description', 'material_type', 'volume', 'weight', -                        'item_number', 'dating')]) +                        'find_number', 'dating')])          dct['order'] += 1          dct['history_modifier'] = user          new = self.__class__(**dct)          new.save() -        for base_item in self.base_items.all(): -            new.base_items.add(base_item) +        for base_find in self.base_finds.all(): +            new.base_finds.add(base_find)          return new      class Meta: -        verbose_name = _(u"Item") -        verbose_name_plural = _(u"Items") +        verbose_name = _(u"Find") +        verbose_name_plural = _(u"Finds")          permissions = ( -            ("view_own_item", ugettext(u"Can view own Item")), -            ("add_own_item", ugettext(u"Can add own Item")), -            ("change_own_item", ugettext(u"Can change own Item")), -            ("delete_own_item", ugettext(u"Can delete own Item")), +            ("view_own_find", ugettext(u"Can view own Find")), +            ("add_own_find", ugettext(u"Can add own Find")), +            ("change_own_find", ugettext(u"Can change own Find")), +            ("delete_own_find", ugettext(u"Can delete own Find")),          )      def __unicode__(self): @@ -197,27 +197,27 @@ class Item(BaseHistorizedItem, OwnPerms):      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( +            super(Find, self).save(*args, **kwargs) +        for base_find in self.base_finds.all(): +            if not base_find.index: +                idx = BaseFind.objects.filter(context_record=\ +                      base_find.context_record).aggregate(Max('index')) +                base_find.index = idx and idx['index__max'] + 1 or 1 +            if not base_find.material_index: +                idx = BaseFind.objects.filter(context_record=\ +                        base_find.context_record, +                        find__material_type=self.material_type).aggregate(                                                        Max('material_index')) -                base_item.material_index = idx and \ +                base_find.material_index = idx and \                                          idx['material_index__max'] + 1 or 1 -            base_item.save() -        super(Item, self).save(*args, **kwargs) +            base_find.save() +        super(Find, self).save(*args, **kwargs) -class ItemSource(Source): +class FindSource(Source):      class Meta: -        verbose_name = _(u"Item documentation") -        verbose_name_plural = _(u"Item documentations") -    item = models.ForeignKey(Item, verbose_name=_(u"Item"), +        verbose_name = _(u"Find documentation") +        verbose_name_plural = _(u"Find documentations") +    find = models.ForeignKey(Find, verbose_name=_(u"Find"),                               related_name="source")  class TreatmentType(GeneralType): @@ -265,7 +265,7 @@ class TreatmentSource(Source):                               related_name="source")  class Property(LightHistorizedItem): -    item = models.ForeignKey(Item, verbose_name=_(u"Item")) +    find = models.ForeignKey(Find, verbose_name=_(u"Find"))      administrative_act = models.ForeignKey(AdministrativeAct,                                           verbose_name=_(u"Administrative act"))      person = models.ForeignKey(Person, verbose_name=_(u"Person")) @@ -277,5 +277,5 @@ class Property(LightHistorizedItem):          verbose_name_plural = _(u"Properties")      def __unicode__(self): -        return self.person + JOINT + self.item +        return self.person + JOINT + self.find  | 
