diff options
| author | Étienne Loks <etienne.loks@proxience.com> | 2014-10-22 12:13:53 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@proxience.com> | 2014-10-22 12:13:53 +0200 | 
| commit | b767774f85e5b0a9b32e58c9feba4ec8c9dc0498 (patch) | |
| tree | a077820cc605f6159417146e4f6cba312f856e1d | |
| parent | e96320dc97ee2befd7deed6e518b9237a1441727 (diff) | |
| download | Ishtar-b767774f85e5b0a9b32e58c9feba4ec8c9dc0498.tar.bz2 Ishtar-b767774f85e5b0a9b32e58c9feba4ec8c9dc0498.zip | |
Decoupling archaeological files
| -rw-r--r-- | archaeological_finds/models.py | 6 | ||||
| -rw-r--r-- | archaeological_operations/admin.py | 20 | ||||
| -rw-r--r-- | archaeological_operations/ishtar_menu.py | 73 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 317 | ||||
| -rw-r--r-- | archaeological_operations/templates/ishtar/sheet_operation.html | 2 | 
5 files changed, 222 insertions, 196 deletions
| diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 26eb4cbd1..8c93a733d 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -29,10 +29,13 @@ from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \  from archaeological_operations.models import AdministrativeAct  from archaeological_context_records.models import ContextRecord, Dating +  WAREHOUSE_AVAILABLE = 'archaeological_warehouse' in settings.INSTALLED_APPS  if WAREHOUSE_AVAILABLE:      from archaeological_warehouse.models import Warehouse, Container +FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS +  class MaterialType(GeneralType):      code = models.CharField(_(u"Code"), max_length=10, blank=True, null=True)      recommendation = models.TextField(_(u"Recommendation")) @@ -386,7 +389,8 @@ class TreatmentSource(Source):  class Property(LightHistorizedItem):      find = models.ForeignKey(Find, verbose_name=_(u"Find")) -    administrative_act = models.ForeignKey(AdministrativeAct, +    if FILES_AVAILABLE: +        administrative_act = models.ForeignKey(AdministrativeAct,                                           verbose_name=_(u"Administrative act"))      person = models.ForeignKey(Person, verbose_name=_(u"Person"),                                 related_name='properties') diff --git a/archaeological_operations/admin.py b/archaeological_operations/admin.py index e0d33a13e..3374bcef7 100644 --- a/archaeological_operations/admin.py +++ b/archaeological_operations/admin.py @@ -24,13 +24,17 @@ from ishtar_common.admin import HistorizedObjectAdmin, GeneralTypeAdmin  import models -class AdministrativeActAdmin(HistorizedObjectAdmin): -    list_display = ('year', 'index', 'operation', 'associated_file', 'act_type') -    list_filter = ('act_type',) -    search_fields = ('year', 'index') -    model = models.AdministrativeAct +FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS -admin.site.register(models.AdministrativeAct, AdministrativeActAdmin) +if FILES_AVAILABLE: +    class AdministrativeActAdmin(HistorizedObjectAdmin): +        list_display = ('year', 'index', 'operation', 'associated_file', +                        'act_type') +        list_filter = ('act_type',) +        search_fields = ('year', 'index') +        model = models.AdministrativeAct + +    admin.site.register(models.AdministrativeAct, AdministrativeActAdmin)  class PeriodAdmin(admin.ModelAdmin):      list_display = ('label', 'start_date', 'end_date', 'parent', 'available', @@ -69,7 +73,9 @@ class OperationSourceAdmin(admin.ModelAdmin):  admin.site.register(models.OperationSource, OperationSourceAdmin)  class ParcelAdmin(HistorizedObjectAdmin): -    list_display = ('section', 'parcel_number', 'operation', 'associated_file') +    list_display = ['section', 'parcel_number', 'operation',] +    if FILES_AVAILABLE: +        list_display.append('associated_file')      search_fields = ('operation__name',)      model = models.Parcel diff --git a/archaeological_operations/ishtar_menu.py b/archaeological_operations/ishtar_menu.py index 7549bf72b..05f3d2a68 100644 --- a/archaeological_operations/ishtar_menu.py +++ b/archaeological_operations/ishtar_menu.py @@ -17,12 +17,15 @@  # See the file COPYING for details. +from django.conf import settings  from django.utils.translation import ugettext_lazy as _, pgettext_lazy  from ishtar_common.menu_base import SectionItem, MenuItem  import models +FILES_AVAILABLE = 'archaeological_files' in settings.INSTALLED_APPS +  MENU_SECTIONS = [      (30, SectionItem('operation_management', _(u"Operation"),          childs=[ @@ -45,29 +48,6 @@ MENU_SECTIONS = [                model=models.Operation,                access_controls=['change_operation',                                 'change_own_operation']), -            SectionItem('admin_act_operations', -                        _(u"Administrative act"), -            childs=[ -                MenuItem('operation_administrativeactop', -                         _(u"Add"), -                  model=models.Operation, -                  access_controls=['change_operation', -                                   'change_own_operation']), -                MenuItem('operation_administrativeactop_modification', -                         _(u"Modification"), -                  model=models.AdministrativeAct, -                  access_controls=['change_operation', -                                   'change_own_operation']), -                MenuItem('operation_administrativeactop_deletion', -                         _(u"Deletion"), -                  model=models.AdministrativeAct, -                  access_controls=['operation_deletion', -                                   'delete_own_operation']), -                MenuItem('operation_administrativeact_document', -                         _(u"Documents"), -                  model=models.AdministrativeAct, -                  access_controls=['change_operation', 'change_own_operation']), -                ],),              SectionItem('operation_source', _(u"Documentation"),                  childs=[                      MenuItem('operation_source_creation', @@ -88,15 +68,6 @@ MENU_SECTIONS = [                  ])          ]),      ), -    (35, SectionItem('administrativact_management', _(u"Administrative Act"), -        childs=[ -            MenuItem('administrativact_register', -                pgettext_lazy('admin act register',u"Register"), -                model=models.AdministrativeAct, -                access_controls=['view_administrativeact', -                                 'view_own_administrativeact']), -               ]) -    ),      (102, SectionItem('dashboard', _(u"Dashboard"),          childs=[                  MenuItem('dashboard_main', _(u"General informations"), @@ -108,3 +79,41 @@ MENU_SECTIONS = [          ]),      ),  ] + +if FILES_AVAILABLE: +    MENU_SECTIONS.insert(1,  +      (35, SectionItem('administrativact_management', _(u"Administrative Act"), +        childs=[ +            MenuItem('administrativact_register', +                pgettext_lazy('admin act register',u"Register"), +                model=models.AdministrativeAct, +                access_controls=['view_administrativeact', +                                 'view_own_administrativeact']), +               ]) +      ) +    ) +    MENU_SECTIONS.insert(5, +            SectionItem('admin_act_operations', +                        _(u"Administrative act"), +            childs=[ +                MenuItem('operation_administrativeactop', +                         _(u"Add"), +                  model=models.Operation, +                  access_controls=['change_operation', +                                   'change_own_operation']), +                MenuItem('operation_administrativeactop_modification', +                         _(u"Modification"), +                  model=models.AdministrativeAct, +                  access_controls=['change_operation', +                                   'change_own_operation']), +                MenuItem('operation_administrativeactop_deletion', +                         _(u"Deletion"), +                  model=models.AdministrativeAct, +                  access_controls=['operation_deletion', +                                   'delete_own_operation']), +                MenuItem('operation_administrativeact_document', +                         _(u"Documents"), +                  model=models.AdministrativeAct, +                  access_controls=['change_operation', 'change_own_operation']), +                ],) +    ) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index c7a8c94ac..9f81a0e1c 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -134,8 +134,9 @@ class ArchaeologicalSite(BaseHistorizedItem):  class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):      TABLE_COLS = ['year_index', 'operation_type', 'remains', 'towns', -                  'associated_file_short_label', 'start_date', -                  'excavation_end_date'] +                  'start_date', 'excavation_end_date'] +    if FILES_AVAILABLE: +        TABLE_COLS.insert(4, 'associated_file_short_label')      start_date = models.DateField(_(u"Start date"), null=True, blank=True)      excavation_end_date = models.DateField(_(u"Excavation end date"), null=True,                                             blank=True) @@ -322,7 +323,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem):      associated_file_short_label_lbl = _(u"Archaeological file")      @property      def associated_file_short_label(self): -        if not self.associated_file: +        if not FILES_AVAILABLE or not self.associated_file:              return ""          return self.associated_file.short_label @@ -434,7 +435,7 @@ def operation_post_save(sender, **kwargs):          operation.fnap_financing = fnap_percent          operation.save()      cached_label_changed(sender, **kwargs) -    if operation.associated_file: +    if FILES_AVAILABLE and operation.associated_file:          operation.associated_file.update_short_menu_class()  post_save.connect(operation_post_save, sender=Operation) @@ -491,161 +492,163 @@ class ActType(GeneralType):          verbose_name_plural = _(u"Act types")          ordering = ('label',) -class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): -    TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'signature_date', -                  'associated_file', 'operation'] -    TABLE_COLS_FILE = ['full_ref', 'year', 'index', 'act_type', 'associated_file', -                       'associated_file.towns',] -    TABLE_COLS_OPE = ['full_ref', 'year', 'index', 'act_type', 'operation', -                      'operation.towns'] -    act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type")) -    in_charge = models.ForeignKey(Person, blank=True, null=True, -        related_name='adminact_operation_in_charge', -        verbose_name=_(u"Person in charge of the operation"), -        on_delete=models.SET_NULL,) -    index = models.IntegerField(verbose_name=_(u"Index"), blank=True, null=True) -    operator = models.ForeignKey(Organization, blank=True, null=True, -                    verbose_name=_(u"Archaeological preventive operator"), -                    related_name='adminact_operator', -                    on_delete=models.SET_NULL) -    scientist = models.ForeignKey(Person, blank=True, null=True, -                related_name='adminact_scientist', on_delete=models.SET_NULL, -                verbose_name=_(u"Scientist in charge")) -    signatory = models.ForeignKey(Person, blank=True, null=True, -                    related_name='signatory', verbose_name=_(u"Signatory"), -                    on_delete=models.SET_NULL,) -    operation = models.ForeignKey(Operation, blank=True, null=True, -                related_name='administrative_act', verbose_name=_(u"Operation")) -    if FILES_AVAILABLE: -        associated_file = models.ForeignKey('archaeological_files.File', -            blank=True, null=True, -            related_name='administrative_act', -            verbose_name=_(u"Archaelogical file")) -    signature_date = models.DateField(_(u"Signature date"), blank=True, +AdministrativeAct = None +if FILES_AVAILABLE: +    class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): +        TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'signature_date', +                      'associated_file', 'operation'] +        TABLE_COLS_FILE = ['full_ref', 'year', 'index', 'act_type', 'associated_file', +                           'associated_file.towns',] +        TABLE_COLS_OPE = ['full_ref', 'year', 'index', 'act_type', 'operation', +                          'operation.towns'] +        act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type")) +        in_charge = models.ForeignKey(Person, blank=True, null=True, +            related_name='adminact_operation_in_charge', +            verbose_name=_(u"Person in charge of the operation"), +            on_delete=models.SET_NULL,) +        index = models.IntegerField(verbose_name=_(u"Index"), blank=True, null=True) +        operator = models.ForeignKey(Organization, blank=True, null=True, +                        verbose_name=_(u"Archaeological preventive operator"), +                        related_name='adminact_operator', +                        on_delete=models.SET_NULL) +        scientist = models.ForeignKey(Person, blank=True, null=True, +                    related_name='adminact_scientist', on_delete=models.SET_NULL, +                    verbose_name=_(u"Scientist in charge")) +        signatory = models.ForeignKey(Person, blank=True, null=True, +                        related_name='signatory', verbose_name=_(u"Signatory"), +                        on_delete=models.SET_NULL,) +        operation = models.ForeignKey(Operation, blank=True, null=True, +                    related_name='administrative_act', verbose_name=_(u"Operation")) +        if FILES_AVAILABLE: +            associated_file = models.ForeignKey('archaeological_files.File', +                blank=True, null=True, +                related_name='administrative_act', +                verbose_name=_(u"Archaelogical file")) +        signature_date = models.DateField(_(u"Signature date"), blank=True, +                                          null=True) +        year = models.IntegerField(_(u"Year"), blank=True, null=True) +        act_object = models.TextField(_(u"Object"), max_length=300, blank=True,                                        null=True) -    year = models.IntegerField(_(u"Year"), blank=True, null=True) -    act_object = models.TextField(_(u"Object"), max_length=300, blank=True, -                                  null=True) -    if settings.COUNTRY == 'fr': -        ref_sra = models.CharField(u"Référence SRA", max_length=15, blank=True, -                                      null=True) -    history = HistoricalRecords() -    _prefix = 'adminact_' - -    class Meta: -        ordering = ('year', 'index', 'act_type') -        verbose_name = _(u"Administrative act") -        verbose_name_plural = _(u"Administrative acts") -        permissions = ( -            ("view_administrativeact", -             ugettext(u"Can view all Administrative act")), -            ("view_own_administrativeact", -             ugettext(u"Can view own Administrative act")), -            ("add_own_administrativeact", -             ugettext(u"Can add own Administrative act")), -            ("change_own_administrativeact", -             ugettext(u"Can change own Administrative act")), -            ("delete_own_administrativeact", -             ugettext(u"Can delete own Administrative act")), -        ) - -    def __unicode__(self): -        return settings.JOINT.join([unicode(item) -          for item in [self.operation, self.associated_file, self.act_object] -          if item]) - -    full_ref_lbl = _(u"Ref.") -    @property -    def full_ref(self): -        lbl = [] -        if self.year: -            lbl.append(unicode(self.year)) -        if self.index: -            lbl.append(u"n°%d" %self.index) -        if settings.COUNTRY == 'fr' and self.ref_sra: -            lbl.append(u"[%s]" % self.ref_sra) -        return u" ".join(lbl) - -    @property -    def towns(self): -        if self.associated_file: -            return self.associated_file.towns.all() -        elif self.operation: -            return self.operation.towns.all() -        return [] -    towns_lbl = _(u"Towns") +        if settings.COUNTRY == 'fr': +            ref_sra = models.CharField(u"Référence SRA", max_length=15, blank=True, +                                          null=True) +        history = HistoricalRecords() +        _prefix = 'adminact_' + +        class Meta: +            ordering = ('year', 'index', 'act_type') +            verbose_name = _(u"Administrative act") +            verbose_name_plural = _(u"Administrative acts") +            permissions = ( +                ("view_administrativeact", +                 ugettext(u"Can view all Administrative act")), +                ("view_own_administrativeact", +                 ugettext(u"Can view own Administrative act")), +                ("add_own_administrativeact", +                 ugettext(u"Can add own Administrative act")), +                ("change_own_administrativeact", +                 ugettext(u"Can change own Administrative act")), +                ("delete_own_administrativeact", +                 ugettext(u"Can delete own Administrative act")), +            ) -    @property -    def related_item(self): -        return self.operation if self.operation else self.associated_file - -    def get_filename(self): -        filename = self.related_item.associated_filename -        filename = u"-".join(filename.split('-')[:-1]) # remove date -        if self.act_type.code: -            filename += u"-" + self.act_type.code -        if self.signature_date and self.index: -            filename += u"-%d-%d" % (self.signature_date.year, -                                     self.index) -        if self.signature_date: -            filename += u"-" + self.signature_date.strftime('%Y%m%d') -        return filename - -    def publish(self, template_pk=None): -        if not self.act_type.associated_template.count(): -            return -        if not template_pk: -            template = self.act_type.associated_template.all()[0] -        else: -            q = self.act_type.associated_template.filter(pk=template_pk) -            if not q.count(): +        def __unicode__(self): +            return settings.JOINT.join([unicode(item) +              for item in [self.operation, self.associated_file, self.act_object] +              if item]) + +        full_ref_lbl = _(u"Ref.") +        @property +        def full_ref(self): +            lbl = [] +            if self.year: +                lbl.append(unicode(self.year)) +            if self.index: +                lbl.append(u"n°%d" %self.index) +            if settings.COUNTRY == 'fr' and self.ref_sra: +                lbl.append(u"[%s]" % self.ref_sra) +            return u" ".join(lbl) + +        @property +        def towns(self): +            if self.associated_file: +                return self.associated_file.towns.all() +            elif self.operation: +                return self.operation.towns.all() +            return [] +        towns_lbl = _(u"Towns") + +        @property +        def related_item(self): +            return self.operation if self.operation else self.associated_file + +        def get_filename(self): +            filename = self.related_item.associated_filename +            filename = u"-".join(filename.split('-')[:-1]) # remove date +            if self.act_type.code: +                filename += u"-" + self.act_type.code +            if self.signature_date and self.index: +                filename += u"-%d-%d" % (self.signature_date.year, +                                         self.index) +            if self.signature_date: +                filename += u"-" + self.signature_date.strftime('%Y%m%d') +            return filename + +        def publish(self, template_pk=None): +            if not self.act_type.associated_template.count():                  return -            template = q.all()[0] -        return template.publish(self) - -    def _get_index(self): -        if not self.index: -            c_index = 1 -            q = AdministrativeAct.objects.filter(act_type__indexed=True, -                                  signature_date__year=self.year, -                                  index__isnull=False).order_by("-index") -            if q.count(): -                c_index = q.all()[0].index + 1 -            self.index = c_index -        conflict = AdministrativeAct.objects.filter(act_type__indexed=True, -                                              signature_date__year=self.year, -                                              index=self.index) -        if self.pk: -            conflict = conflict.exclude(pk=self.pk) -        if conflict.count(): -            if self.pk: -                raise ValidationError(_(u"This index already exists for " -                                        u"this year")) +            if not template_pk: +                template = self.act_type.associated_template.all()[0]              else: -                self._get_index() - -    def clean(self, *args, **kwargs): -        if not self.signature_date: -            return super(AdministrativeAct, self).clean(*args, **kwargs) -        self.year = self.signature_date.year -        if not self.act_type.indexed: -            return super(AdministrativeAct, self).clean(*args, **kwargs) -        self._get_index() -        super(AdministrativeAct, self).clean(*args, **kwargs) - -    def save(self, *args, **kwargs): -        if not self.signature_date: -            return super(AdministrativeAct, self).save(*args, **kwargs) -        self.year = self.signature_date.year - -        if not self.act_type.indexed: -            return super(AdministrativeAct, self).save(*args, **kwargs) - -        self._get_index() -        super(AdministrativeAct, self).save(*args, **kwargs) -        if hasattr(self, 'associated_file') and self.associated_file: -            self.associated_file.update_has_admin_act() -            self.associated_file.update_short_menu_class() +                q = self.act_type.associated_template.filter(pk=template_pk) +                if not q.count(): +                    return +                template = q.all()[0] +            return template.publish(self) + +        def _get_index(self): +            if not self.index: +                c_index = 1 +                q = AdministrativeAct.objects.filter(act_type__indexed=True, +                                      signature_date__year=self.year, +                                      index__isnull=False).order_by("-index") +                if q.count(): +                    c_index = q.all()[0].index + 1 +                self.index = c_index +            conflict = AdministrativeAct.objects.filter(act_type__indexed=True, +                                                  signature_date__year=self.year, +                                                  index=self.index) +            if self.pk: +                conflict = conflict.exclude(pk=self.pk) +            if conflict.count(): +                if self.pk: +                    raise ValidationError(_(u"This index already exists for " +                                            u"this year")) +                else: +                    self._get_index() + +        def clean(self, *args, **kwargs): +            if not self.signature_date: +                return super(AdministrativeAct, self).clean(*args, **kwargs) +            self.year = self.signature_date.year +            if not self.act_type.indexed: +                return super(AdministrativeAct, self).clean(*args, **kwargs) +            self._get_index() +            super(AdministrativeAct, self).clean(*args, **kwargs) + +        def save(self, *args, **kwargs): +            if not self.signature_date: +                return super(AdministrativeAct, self).save(*args, **kwargs) +            self.year = self.signature_date.year + +            if not self.act_type.indexed: +                return super(AdministrativeAct, self).save(*args, **kwargs) + +            self._get_index() +            super(AdministrativeAct, self).save(*args, **kwargs) +            if hasattr(self, 'associated_file') and self.associated_file: +                self.associated_file.update_has_admin_act() +                self.associated_file.update_short_menu_class()  def strip_zero(value):      for idx, nb in enumerate(value): @@ -720,7 +723,9 @@ class Parcel(LightHistorizedItem):          return res      def long_label(self): -        items = [unicode(self.operation or self.associated_file)] +        items = [unicode(self.operation) or +                (FILES_AVAILABLE and unicode(self.associated_file)) or +                ""]          items += [unicode(item) for item in [self.section, self.parcel_number]                                            if item]          return settings.JOINT.join(items) diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index 0b5e58d56..138a94d14 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -84,8 +84,10 @@  {% trans "Associated parcels" as parcels_label %}  {% include "ishtar/blocks/window_tables/parcels.html" %} +{% if item.administrative_act %}  {% trans "Administrativ acts" as administrativeacts_label %}  {% table_administrativact administrativeacts_label item.administrative_act.all %} +{% endif %}  {% trans "Document from this operation" as operation_docs %}  {% if item.source.count %} {% table_document operation_docs item.source.all %}{% endif %} | 
