diff options
| -rw-r--r-- | archaeological_context_records/models.py | 13 | ||||
| -rw-r--r-- | archaeological_finds/models.py | 54 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 22 | ||||
| -rw-r--r-- | ishtar_common/models.py | 13 | ||||
| -rw-r--r-- | ishtar_common/views.py | 11 | 
5 files changed, 80 insertions, 33 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 3f4dc1598..22ff3b095 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -29,7 +29,7 @@ from ishtar_common.utils import cached_label_changed  from ishtar_common.models import GeneralType, BaseHistorizedItem, \      HistoricalRecords, OwnPerms, ShortMenuItem, Source, GeneralRelationType,\      GeneralRecordRelations, post_delete_record_relation, get_external_id, \ -    ImageModel, post_save_cache +    ImageModel, post_save_cache, ValueGetter  from archaeological_operations.models import Operation, Period, Parcel @@ -118,7 +118,8 @@ post_save.connect(post_save_cache, sender=IdentificationType)  post_delete.connect(post_save_cache, sender=IdentificationType) -class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): +class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, +                      ValueGetter, ShortMenuItem):      SHOW_URL = 'show-contextrecord'      SLUG = 'contextrecord'      TABLE_COLS = ['parcel__town', 'operation__year', @@ -155,6 +156,14 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):      RELATIVE_SESSION_NAMES = [          ('operation', 'operation__pk'),          ('file', 'operation__associated_file__pk')] +    EXTRA_FULL_FIELDS_LABELS = { +        'parcel__town': _(u"Parcel (town)"), +        'detailled_related_context_records': _(u"Related context records"), +        'operation__code_patriarche': u"Operation (code patriarche)", +        'parcel__external_id': _(u"Parcel (external ID)"), +        'datings__period': _(u"Datings (period)"), +        'parcel__year': _(u"Parcel (year)"), +    }      # fields      external_id = models.TextField(_(u"External ID"), blank=True, null=True) diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index aa5eacc30..6dcbbce65 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -291,41 +291,41 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):      CHECK_DICT = dict(CHECK_CHOICES)      SHOW_URL = 'show-find'      SLUG = 'find' -    TABLE_COLS = ['label', 'material_types', 'datings.period', -                  'base_finds.context_record.parcel.town', -                  'base_finds.context_record.operation.year', -                  'base_finds.context_record.operation.operation_code', -                  'container.reference', 'container.location', -                  'base_finds.batch', -                  'base_finds.context_record.parcel.town', -                  'base_finds.context_record.parcel', ] +    TABLE_COLS = ['label', 'material_types', 'datings__period', +                  'base_finds__context_record__parcel__town', +                  'base_finds__context_record__operation__year', +                  'base_finds__context_record__operation__operation_code', +                  'container__reference', 'container__location', +                  'base_finds__batch', +                  'base_finds__context_record__parcel__town', +                  'base_finds__context_record__parcel', ]      if settings.COUNTRY == 'fr':          TABLE_COLS.insert( -            6, 'base_finds.context_record.operation.code_patriarche') +            6, 'base_finds__context_record__operation__code_patriarche')      TABLE_COLS_FOR_OPE = [ -        'base_finds.cache_short_id', -        'base_finds.cache_complete_id', +        'base_finds__cache_short_id', +        'base_finds__cache_complete_id',          'previous_id', 'label', 'material_types', -        'datings.period', 'find_number', 'object_types', +        'datings__period', 'find_number', 'object_types',          'description', -        'base_finds.context_record.parcel.town', -        'base_finds.context_record.parcel', ] +        'base_finds__context_record__parcel__town', +        'base_finds__context_record__parcel', ]      EXTRA_FULL_FIELDS = [ -        'base_finds.cache_short_id', 'base_finds.cache_complete_id', -        'base_finds.comment', 'base_finds.description', -        'base_finds.topographic_localisation', -        'base_finds.special_interest', -        'base_finds.discovery_date'] +        'base_finds__cache_short_id', 'base_finds__cache_complete_id', +        'base_finds__comment', 'base_finds__description', +        'base_finds__topographic_localisation', +        'base_finds__special_interest', +        'base_finds__discovery_date']      EXTRA_FULL_FIELDS_LABELS = { -        'base_finds.cache_short_id': _(u"Base find - Short ID"), -        'base_finds.cache_complete_id': _(u"Base find - Complete ID"), -        'base_finds.comment': _(u"Base find - Comment"), -        'base_finds.description': _(u"Base find - Description"), -        'base_finds.topographic_localisation': _(u"Base find - " -                                                 u"Topographic localisation"), -        'base_finds.special_interest': _(u"Base find - Special interest"), -        'base_finds.discovery_date': _(u"Base find - Discovery date"), +        'base_finds__cache_short_id': _(u"Base find - Short ID"), +        'base_finds__cache_complete_id': _(u"Base find - Complete ID"), +        'base_finds__comment': _(u"Base find - Comment"), +        'base_finds__description': _(u"Base find - Description"), +        'base_finds__topographic_localisation': _(u"Base find - " +                                                  u"Topographic localisation"), +        'base_finds__special_interest': _(u"Base find - Special interest"), +        'base_finds__discovery_date': _(u"Base find - Discovery date"),      }      ATTRS_EQUIV = {'get_first_base_find': 'base_finds'} diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 14e5e1f7e..1e108e98c 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -225,6 +225,28 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,          'finds_deadline_before': 'finds_deadline__lte',          'finds_deadline_after': 'finds_deadline__gte',      } +    EXTRA_FULL_FIELDS_LABELS = { +        'full_code_patriarche': u"Code patriarche", +        'year_index': _(u"Year - Index"), +        'associated_file_short_label': _(u"Associated file (label)"), +        'operator__name': _(u"Operator name"), +        'scientist__raw_name': _(u"Scientist (full name)"), +        'associated_file__external_id': _(u"Associated file (external ID)"), +        'scientist__title': _(u"Scientist (title)"), +        'scientist__surname': _(u"Scientist (surname)"), +        'scientist__name': _(u"Scientist (name)"), +        'scientist__attached_to__name': _(u"Scientist - Organization (name)"), +        'in_charge__title': _(u"In charge (title)"), +        'in_charge__surname': _(u"In charge (surname)"), +        'in_charge__name': _(u"In charge (name)"), +        'in_charge__attached_to__name': _(u"In charge - Organization (name)"), +        'cira_rapporteur__surname': u"Rapporteur CIRA (prénom)", +        'cira_rapporteur__name': u"Rapporteur CIRA (nom)", +        'cira_rapporteur__attached_to__name': u"Rapporteur CIRA - " +                                              u"Organisation (nom)", +        'archaeological_sites__reference': _(u"Archaeological sites (" +                                             u"reference)"), +    }      # fields definition      creation_date = models.DateField(_(u"Creation date"), diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 72a3432f8..5b822c7dd 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -25,6 +25,7 @@ import copy  import datetime  from PIL import Image  from importlib import import_module +import logging  import os  import re  import shutil @@ -65,6 +66,9 @@ from ishtar_common.data_importer import Importer, ImportFormater, \      TypeFormater, YearFormater, StrToBoolean, FileFormater +logger = logging.getLogger(__name__) + +  def post_save_user(sender, **kwargs):      user = kwargs['instance']      try: @@ -95,6 +99,7 @@ class Imported(models.Model):  class ValueGetter(object):      _prefix = ""      GET_VALUES_EXTRA = [] +    EXTRA_FULL_FIELDS_LABELS = {}      def get_values(self, prefix=''):          if not prefix: @@ -1607,7 +1612,7 @@ def get_importer_models():                ('archaeological_context_records.models.RecordRelations',                _(u"Context record relations"))] + MODELS      MODELS = [('archaeological_finds.models.BaseFind', -              _(u"Finds")), ] + MODELS +              _(u"Base finds")), ] + MODELS      return MODELS @@ -1995,7 +2000,9 @@ TARGET_MODELS = [      ('archaeological_operations.models.OperationType', _(u"Operation type")),      ('archaeological_operations.models.Period', _(u"Period")),      ('archaeological_operations.models.ReportState', _(u"Report state")), +    ('archaeological_operations.models.RemainType', _(u"Remain type")),      ('archaeological_context_records.models.Unit', _(u"Unit")), +    ('archaeological_context_records.models.ActivityType', _(u"Activity type")),      ('archaeological_finds.models.MaterialType', _(u"Material")),      ('archaeological_finds.models.ConservatoryState',       _(u"Conservatory state")), @@ -2077,7 +2084,9 @@ class FormaterType(models.Model):              kwargs['many_split'] = self.many_split          if self.formater_type == 'TypeFormater':              if self.options not in TARGET_MODELS_KEYS: -                print('%s not in TARGET_MODELS_KEYS' % self.options) +                logger.warning( +                    "**WARN FormaterType.get_formater_type**: {} " +                    "is not in TARGET_MODELS_KEYS".format(self.options))                  return              model = None              if self.options in dir(): diff --git a/ishtar_common/views.py b/ishtar_common/views.py index cd34a2019..8634125cd 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -981,8 +981,8 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                      lnk = link_template % reverse('show-' + default_name,                                                    args=[data[0], ''])                  except NoReverseMatch: -                    print( -                        '"show-' + default_name + "\" args (" +                    logger.warning( +                        '**WARN "show-' + default_name + '" args ('                          + unicode(data[0]) + ") url not available")                      lnk = ''                  res = {'id': data[0], 'link': lnk} @@ -1027,6 +1027,8 @@ def get_item(model, func_name, default_name, extra_request_keys=[],              writer = csv.writer(response, **CSV_OPTIONS)              col_names = []              for field_name in table_cols: +                if type(field_name) in (list, tuple): +                    field_name = " ; ".join(field_name)                  if hasattr(model, 'EXTRA_FULL_FIELDS_LABELS') and\                          field_name in model.EXTRA_FULL_FIELDS_LABELS:                      field = model.EXTRA_FULL_FIELDS_LABELS[field_name] @@ -1037,6 +1039,11 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                          field = model._meta.get_field(field_name)                      except:                          col_names.append(u"".encode(ENCODING)) +                        logger.warning( +                            "**WARN get_item - csv export**: no col name for " +                            "{}\nadd explicit label to " +                            "EXTRA_FULL_FIELDS_LABELS attribute of " +                            "{}".format(field_name, model))                          continue                      col_names.append(                          unicode(field.verbose_name).encode(ENCODING)) | 
