diff options
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 30 | 
1 files changed, 21 insertions, 9 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 253ea7635..ff51f78e8 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -34,7 +34,8 @@ from ishtar_common.models import GeneralType, BaseHistorizedItem, \      HistoricalRecords, LightHistorizedItem, OwnPerms, Department, Source,\      Person, Organization, Town, Dashboard, IshtarUser, ValueGetter, \      DocumentTemplate, ShortMenuItem, DashboardFormItem, GeneralRelationType,\ -    GeneralRecordRelations, post_delete_record_relation, OperationType +    GeneralRecordRelations, post_delete_record_relation, OperationType, \ +    get_external_id  class RemainType(GeneralType): @@ -231,6 +232,9 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,          _(u"Record quality"), max_length=2, null=True, blank=True,          choices=QUALITY)      abstract = models.TextField(_(u"Abstract"), null=True, blank=True) +    point = models.PointField(_(u"Point"), blank=True, null=True) +    multi_polygon = models.MultiPolygonField(_(u"Multi polygon"), blank=True, +                                             null=True)      history = HistoricalRecords()      class Meta: @@ -251,7 +255,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,          owns = super(Operation, cls).get_owns(user)          # owns = owns.annotate(null_count=Count('operation_code'))          # return owns.order_by("common_name", "-year", "operation_code") -        return sorted(owns.all(), key=lambda x: x.cached_label) +        return sorted(owns, key=lambda x: x.cached_label)      def __unicode__(self):          if self.cached_label: @@ -359,8 +363,6 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,      @classmethod      def get_available_operation_code(cls, year=None): -        if not year: -            year = datetime.date.today().year          max_val = cls.objects.filter(year=year).aggregate(              Max('operation_code'))["operation_code__max"]          return (max_val + 1) if max_val else 1 @@ -464,7 +466,7 @@ class RelationType(GeneralRelationType):      class Meta:          verbose_name = _(u"Operation relation type")          verbose_name_plural = _(u"Operation relation types") -        ordering = ('order',) +        ordering = ('order', 'label')  class RecordRelations(GeneralRecordRelations, models.Model): @@ -516,9 +518,10 @@ class OperationSource(Source):                                    related_name="source")      index = models.IntegerField(verbose_name=_(u"Index"), blank=True,                                  null=True) -    TABLE_COLS = ['operation.year', 'operation.operation_code'] + \ +    TABLE_COLS = ['operation.year', 'operation.operation_code', 'index'] + \          Source.TABLE_COLS      SHOW_URL = 'show-operationsource' +    MODIFY_URL = 'operation_source_modify'      @property      def owner(self): @@ -775,6 +778,8 @@ class Parcel(LightHistorizedItem):                                       null=True, blank=True)      external_id = models.CharField(_(u"External ID"), max_length=100,                                     null=True, blank=True) +    auto_external_id = models.BooleanField( +        _(u"External ID is set automatically"), default=False)      address = models.TextField(_(u"Address - Locality"), null=True, blank=True)      class Meta: @@ -914,11 +919,18 @@ def parcel_post_save(sender, **kwargs):      if not kwargs['instance']:          return      parcel = kwargs['instance'] -    if not parcel.external_id and (parcel.section or parcel.parcel_number): -        parcel.external_id = unicode(parcel.section or "") + \ -            unicode(parcel.parcel_number or "") + +    updated = False +    if not parcel.external_id or parcel.auto_external_id: +        external_id = get_external_id('parcel_external_id', parcel) +        if external_id != parcel.external_id: +            updated = True +            parcel.auto_external_id = True +            parcel.external_id = external_id +    if updated:          parcel.save()          return +      if parcel.operation and parcel.operation.pk and \         parcel.town not in list(parcel.operation.towns.all()):          parcel.operation.towns.add(parcel.town) | 
