diff options
| -rw-r--r-- | archaeological_context_records/models.py | 1 | ||||
| -rw-r--r-- | archaeological_context_records/templates/ishtar/sheet_contextrecord.html | 2 | ||||
| -rw-r--r-- | archaeological_context_records/views.py | 34 | ||||
| -rw-r--r-- | archaeological_finds/models.py | 25 | ||||
| -rw-r--r-- | archaeological_finds/urls.py | 2 | ||||
| -rw-r--r-- | archaeological_finds/views.py | 43 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 2 | ||||
| -rw-r--r-- | archaeological_operations/templates/ishtar/sheet_operation.html | 2 | ||||
| -rw-r--r-- | ishtar_common/templatetags/window_tables.py | 2 | ||||
| -rw-r--r-- | ishtar_common/views.py | 18 | ||||
| -rw-r--r-- | ishtar_common/widgets.py | 62 | 
11 files changed, 123 insertions, 70 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 8c80d81ed..eb62029aa 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -113,6 +113,7 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):      TABLE_COLS_FOR_OPE = [          'label', ['parcel.section', 'parcel.parcel_number'], 'unit',          'datings.period', 'description'] +    TABLE_COLS_FOR_OPE_LBL = {'section__parcel_number': _("Parcel")}      external_id = models.CharField(_(u"External ID"), blank=True, null=True,                                     max_length=120)      parcel = models.ForeignKey(Parcel, verbose_name=_(u"Parcel"), diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index a984ef8b5..bca027414 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -128,7 +128,7 @@  {% trans "Finds" as finds %}  {% if item.base_finds.count %} -{% dynamic_table_document finds 'finds' 'base_finds__context_record' item.pk %} +{% dynamic_table_document finds 'finds_for_ope' 'base_finds__context_record' item.pk 'TABLE_COLS_FOR_OPE' %}  {% endif %}  {% trans "Documents from associated finds" as find_docs %} diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index d64adc2a2..cbf34ee07 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -30,32 +30,26 @@ import models  show_contextrecord = show_item(models.ContextRecord, 'contextrecord')  revert_contextrecord = revert_item(models.ContextRecord) + +contextrecord_extra_keys = { +    'parcel__town': 'parcel__town__pk', +    'operation__year': 'operation__year__contains', +    'operation__code_patriarche': 'operation__code_patriarche', +    'operation__operation_code': 'operation__operation_code', +    'datings__period': 'datings__period__pk', +    'parcel_0': 'operation__parcels__section', +    'parcel_1': 'operation__parcels__parcel_number', +    'label': 'label__icontains' +} +  get_contextrecord = get_item(      models.ContextRecord,      'get_contextrecord', 'contextrecord', -    extra_request_keys={ -        'parcel__town': 'parcel__town__pk', -        'operation__year': 'operation__year__contains', -        'operation__code_patriarche': 'operation__code_patriarche', -        'operation__operation_code': 'operation__operation_code', -        'datings__period': 'datings__period__pk', -        'parcel_0': 'operation__parcels__section', -        'parcel_1': 'operation__parcels__parcel_number', -        'label': 'label__icontains' -    },) +    extra_request_keys=contextrecord_extra_keys,)  get_contextrecord_for_ope = get_item(      models.ContextRecord,      'get_contextrecord', 'contextrecord', -    extra_request_keys={ -        'parcel__town': 'parcel__town__pk', -        'operation__year': 'operation__year__contains', -        'operation__code_patriarche': 'operation__code_patriarche', -        'operation__operation_code': 'operation__operation_code', -        'datings__period': 'datings__period__pk', -        'parcel_0': 'operation__parcels__section', -        'parcel_1': 'operation__parcels__parcel_number', -        'label': 'label__icontains' -    }, +    extra_request_keys=contextrecord_extra_keys,      own_table_cols=models.ContextRecord.TABLE_COLS_FOR_OPE)  get_contextrecordsource = get_item(      models.ContextRecordSource, diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 03e54b8f2..1d59c59b1 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -213,6 +213,31 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):      if settings.COUNTRY == 'fr':          TABLE_COLS.insert(              6, 'base_finds.context_record.operation.code_patriarche') +    if settings.COUNTRY == 'fr': +        TABLE_COLS_FOR_OPE = [ +            ['base_finds.context_record.operation.code_patriarche', ], +            ['base_finds.context_record.operation.code_patriarche', ], +        ] +    else: +        TABLE_COLS_FOR_OPE = [ +            ['base_finds.context_record.operation.year', +             'base_finds.context_record.operation.operation_code'], +            ['base_finds.context_record.operation.year', +             'base_finds.context_record.operation.operation_code'] +        ] +    TABLE_COLS_FOR_OPE[0] += ['index'] +    TABLE_COLS_FOR_OPE[1] += [ +        'material_types.code', +        'base_finds.context_record.label', +        'index'] +    TABLE_COLS_FOR_OPE += [ +        'previous_id', 'label', 'material_types', +        'dating.period', 'find_number', 'object_types', +        'description'] + +    TABLE_COLS_FOR_OPE_LBL = { +        'code_patriarche__index': _("Short Id"), +        'code_patriarche__code__label__index': _("Complete ID")}      base_finds = models.ManyToManyField(BaseFind, verbose_name=_(u"Base find"),                                          related_name='find')      external_id = models.CharField(_(u"External ID"), blank=True, null=True, diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index 0e337b519..a5232d2a9 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -51,6 +51,8 @@ urlpatterns += patterns(          name='autocomplete-materialtype'),      url(r'get-find/(?P<type>.+)?$', 'get_find',          name='get-find'), +    url(r'get-find-for-ope/(?P<type>.+)?$', 'get_find_for_ope', +        name='get-find-for-ope'),      url(r'get-find-full/(?P<type>.+)?$', 'get_find',          name='get-find-full', kwargs={'full': True}),      url(r'get-findsource/(?P<type>.+)?$', diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index 5caaae64d..6ca09feb8 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -34,27 +34,38 @@ from wizards import *  from forms import *  import models +find_extra_keys = { +    'base_finds__context_record': +        'base_finds__context_record__pk', +    'base_finds__context_record__parcel__town': +        'base_finds__context_record__parcel__town', +    'base_finds__context_record__operation__year': +        'base_finds__context_record__operation__year__contains', +    'base_finds__context_record__operation': +        'base_finds__context_record__operation__pk', +    'base_finds__context_record__operation__code_patriarche': +        'base_finds__context_record__operation__code_patriarche', +    'dating__period': 'dating__period__pk', +    'base_finds__find__description': +        'base_finds__find__description__icontains', +    'base_finds__is_isolated': 'base_finds__is_isolated', +    'image': 'image__isnull'} +  get_find = get_item(      models.Find, 'get_find', 'find',      bool_fields=['base_finds__is_isolated'],      reversed_bool_fields=['image__isnull'],      base_request={'downstream_treatment__isnull': True}, -    extra_request_keys={ -        'base_finds__context_record': -            'base_finds__context_record__pk', -        'base_finds__context_record__parcel__town': -            'base_finds__context_record__parcel__town', -        'base_finds__context_record__operation__year': -            'base_finds__context_record__operation__year__contains', -        'base_finds__context_record__operation': -            'base_finds__context_record__operation__pk', -        'base_finds__context_record__operation__code_patriarche': -            'base_finds__context_record__operation__code_patriarche', -        'dating__period': 'dating__period__pk', -        'base_finds__find__description': -            'base_finds__find__description__icontains', -        'base_finds__is_isolated': 'base_finds__is_isolated', -        'image': 'image__isnull'}) +    extra_request_keys=find_extra_keys) + +get_find_for_ope = get_item( +    models.Find, 'get_find', 'find', +    bool_fields=['base_finds__is_isolated'], +    reversed_bool_fields=['image__isnull'], +    base_request={'downstream_treatment__isnull': True}, +    extra_request_keys=find_extra_keys, +    own_table_cols=models.Find.TABLE_COLS_FOR_OPE) +  get_findsource = get_item(      models.FindSource, 'get_findsource', 'findsource',      extra_request_keys={ diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 90af1bd62..e5c22c909 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -320,7 +320,7 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,      def get_reference(self, full=False):          ref = "" -        if self.code_patriarche: +        if settings.COUNTRY == 'fr' and self.code_patriarche:              ref = "OA" + unicode(self.code_patriarche)              if not full:                  return ref diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index 9d22657c3..56b5115d6 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -108,7 +108,7 @@  {% trans "Finds" as finds %}  {% if item.finds %} -{% dynamic_table_document finds 'finds' 'base_finds__context_record__operation' item.pk %} +{% dynamic_table_document finds 'finds_for_ope' 'base_finds__context_record__operation' item.pk 'TABLE_COLS_FOR_OPE' %}  {% endif %}  {% comment %} diff --git a/ishtar_common/templatetags/window_tables.py b/ishtar_common/templatetags/window_tables.py index 0b744c1e5..32a3076c5 100644 --- a/ishtar_common/templatetags/window_tables.py +++ b/ishtar_common/templatetags/window_tables.py @@ -39,6 +39,8 @@ except:  try:      from archaeological_finds.models import Find      ASSOCIATED_MODELS['finds'] = (Find, 'get-find', 'get-find-full') +    ASSOCIATED_MODELS['finds_for_ope'] = ( +        Find, 'get-find-for-ope', 'get-find-full')  except:      pass diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 10c62d465..efd7a9de1 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -525,9 +525,14 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                          my_vals = [format_val(v) for v in vals]                      else:                          new_vals = [] -                        for idx, v in enumerate(vals): -                            new_vals.append("{}{}{}".format( -                                my_vals[idx], settings.JOINT, format_val(v))) +                        if not vals: +                            for idx, my_v in enumerate(my_vals): +                                new_vals.append(u"{}{}{}".format( +                                    my_v, u' - ', '')) +                        else: +                            for idx, v in enumerate(vals): +                                new_vals.append(u"{}{}{}".format( +                                    my_vals[idx], u' - ', format_val(v)))                          my_vals = new_vals[:]                  data.append(", ".join(my_vals) or u"")              datas.append(data) @@ -563,9 +568,10 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                  for idx, value in enumerate(data[1:]):                      if value:                          table_col = table_cols[idx] -                        if type(table_col) in (list, tuple): -                            table_col = table_col[0] -                        res[table_col.split('.')[-1]] = value +                        if type(table_col) not in (list, tuple): +                            table_col = [table_col] +                        k = "__".join([tc.split('.')[-1] for tc in table_col]) +                        res[k] = value                  rows.append(res)              data = json.dumps({                  "records": items_nb, diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 509907034..2aa9b12f6 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -525,34 +525,46 @@ class JQueryJqGrid(forms.RadioSelect):          self.source_full = source_full      def get_cols(self): -        col_names, extra_cols = [], [] -        for field_name in getattr(self.associated_model, self.table_cols): -            field = self.associated_model -            if type(field_name) in (list, tuple): -                field_name = field_name[0] +        jq_col_names, extra_cols = [], [] +        col_labels = {} +        if hasattr(self.associated_model, self.table_cols + '_LBL'): +            col_labels = getattr(self.associated_model, +                                 self.table_cols + '_LBL') +        for col_names in getattr(self.associated_model, self.table_cols):              field_verbose_names = [] -            keys = field_name.split('.') -            field_verbose_name = "" -            for key in keys: -                if hasattr(field, 'rel') and field.rel: -                    field = field.rel.to -                try: -                    field = field._meta.get_field(key) -                    field_verbose_name = field.verbose_name -                    field_name = field.name -                except (fields.FieldDoesNotExist, AttributeError): -                    if hasattr(field, key + '_lbl'): -                        field_name = key -                        field_verbose_name = getattr(field, key + '_lbl') -                    else: -                        continue -            field_verbose_names.append(unicode(field_verbose_name)) -            col_names.append(u'"%s"' % settings.JOINT.join( -                [f for f in field_verbose_names if f])) +            field_verbose_name, field_name = "", "" +            if type(col_names) not in (list, tuple): +                col_names = [col_names] +            for col_name in col_names: +                field = self.associated_model +                keys = col_name.split('.') +                f_name = '' +                for key in keys: +                    if hasattr(field, 'rel') and field.rel: +                        field = field.rel.to +                    try: +                        field = field._meta.get_field(key) +                        field_verbose_name = field.verbose_name +                        f_name = field.name +                    except (fields.FieldDoesNotExist, AttributeError): +                        if hasattr(field, key + '_lbl'): +                            f_name = key +                            field_verbose_name = getattr(field, key + '_lbl') +                        else: +                            continue +                if field_name: +                    field_name += "__" +                field_name += f_name +                field_verbose_names.append(unicode(field_verbose_name)) +            if field_name in col_labels: +                jq_col_names.append(u'"%s"' % unicode(col_labels[field_name])) +            else: +                jq_col_names.append(u'"%s"' % settings.JOINT.join( +                    [f for f in field_verbose_names if f]))              extra_cols.append(self.COL_TPL % {'idx': field_name}) -        col_names = col_names and ", ".join(col_names) or "" +        jq_col_names = jq_col_names and ", ".join(jq_col_names) or ""          extra_cols = extra_cols and ", ".join(extra_cols) or "" -        return col_names, extra_cols +        return jq_col_names, extra_cols      def render(self, name, value=None, attrs=None):          t = loader.get_template('blocks/form_snippet.html') | 
