diff options
| -rw-r--r-- | archaeological_context_records/models.py | 7 | ||||
| -rw-r--r-- | archaeological_files/models.py | 7 | ||||
| -rw-r--r-- | archaeological_finds/models_treatments.py | 4 | ||||
| -rw-r--r-- | archaeological_operations/management/commands/regenerate_cached_label_ope.py | 38 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 35 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 1 | ||||
| -rw-r--r-- | ishtar_common/models.py | 6 | ||||
| -rw-r--r-- | ishtar_common/views_item.py | 11 | 
8 files changed, 54 insertions, 55 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 6061ad09c..080fa54da 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -213,7 +213,7 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,      EXTERNAL_ID_KEY = 'context_record_external_id'      EXTERNAL_ID_DEPENDENCIES = ['base_finds']      TABLE_COLS = ['label', 'operation__common_name', 'town__name', -                  'parcel__short_label', 'unit'] +                  'parcel__cached_label', 'unit']      if settings.COUNTRY == 'fr':          TABLE_COLS.insert(1, 'operation__code_patriarche')      TABLE_COLS_FOR_OPE = ['label', 'parcel', 'unit', @@ -229,6 +229,7 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,          'town': _(u"Town"),          'parcel__year': _(u"Parcel (year)"),          'section__parcel_number': _(u"Parcel"), +        'parcel__cached_label': _(u"Parcel"),      }      CONTEXTUAL_TABLE_COLS = {          'full': { @@ -239,11 +240,13 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,      # search parameters      EXTRA_REQUEST_KEYS = {          'town': 'town__pk', -        'parcel__short_label': 'parcel__short_label', +        'town__name': 'town__name', +        'parcel__cached_label': 'parcel__cached_label',          'operation__year': 'operation__year__contains',          'year': 'operation__year__contains',          'operation__code_patriarche': 'operation__code_patriarche',          'operation__operation_code': 'operation__operation_code', +        'operation__common_name': 'operation__common_name',          'datings__period': 'datings__period__pk',          'parcel_0': 'operation__parcels__section',          'parcel_1': 'operation__parcels__parcel_number', diff --git a/archaeological_files/models.py b/archaeological_files/models.py index a60e01f64..a4de6e0e4 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -87,7 +87,7 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,      SLUG = 'file'      SHOW_URL = 'show-file'      TABLE_COLS = ['numeric_reference', 'year', 'internal_reference', -                  'file_type', 'saisine_type', 'towns', ] +                  'file_type', 'saisine_type', 'towns_label', ]      # search parameters      BOOL_FIELDS = ['end_date__isnull'] @@ -109,6 +109,7 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,              'general_contractor__attached_to__pk',          'history_creator': 'history_creator__ishtaruser__person__pk',          'history_modifier': 'history_modifier__ishtaruser__person__pk', +        'towns_label': 'towns',      }      BASE_SEARCH_VECTORS = [          'name', 'internal_reference', 'file_type__label', 'saisine_type__label', @@ -122,6 +123,10 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          'scientist'      ] +    COL_LABELS = { +        'towns_label': _(u"Towns"), +    } +      # alternative names of fields for searches      ALT_NAMES = {          'year': ( diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index cd52791e7..5506afae0 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -54,19 +54,21 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem,      SHOW_URL = 'show-treatment'      TABLE_COLS = ('year', 'index', 'treatment_types__label',                    'treatment_state__label', -                  'label', 'person', +                  'label', 'person__cached_label',                    'start_date', 'downstream_cached_label',                    'upstream_cached_label')      REVERSED_BOOL_FIELDS = ['documents__image__isnull']      EXTRA_REQUEST_KEYS = {          "downstream_cached_label": "downstream__cached_label",          "upstream_cached_label": "upstream__cached_label", +        'person__cached_label': 'person__cached_label',      }      COL_LABELS = {          "downstream_cached_label": _(u"Downstream find"),          "upstream_cached_label": _(u"Upstream find"),          "treatment_types__label": _(u"Type"),          "treatment_state__label": _(u"State"), +        'person__cached_label': _(u"Responsible"),      }      # extra keys than can be passed to save method      EXTRA_SAVED_KEYS = ('items', 'user') diff --git a/archaeological_operations/management/commands/regenerate_cached_label_ope.py b/archaeological_operations/management/commands/regenerate_cached_label_ope.py deleted file mode 100644 index 4eee0b623..000000000 --- a/archaeological_operations/management/commands/regenerate_cached_label_ope.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2014 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program.  If not, see <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - -import sys - -from django.db import models -from django.core.management.base import BaseCommand, CommandError -from django.core.exceptions import ValidationError - -from archaeological_operations import models - -class Command(BaseCommand): -    args = '' -    help = 'Regenerate cached label' - -    def handle(self, *args, **options): -        q = models.Operation.objects -        ln = q.count() -        sys.stdout.write("\n* regeneration\n") -        for idx, operation in enumerate(q.all()): -            operation.save() -            sys.stdout.write("\r* %d/%d" % (idx, ln)) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 004ee8d06..1ff66e195 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -100,7 +100,7 @@ post_delete.connect(post_save_cache, sender=RecordQualityType)  class ArchaeologicalSite(BaseHistorizedItem):      SHOW_URL = 'show-site' -    TABLE_COLS = ['reference', 'name', 'towns', 'periods', 'remains'] +    TABLE_COLS = ['reference', 'name', 'towns_label', 'periods', 'remains']      SLUG = 'site'      BASE_SEARCH_VECTORS = [ @@ -119,7 +119,9 @@ class ArchaeologicalSite(BaseHistorizedItem):      DATED_FIELDS = ['sinking_date'] -    EXTRA_REQUEST_KEYS = {} +    COL_LABELS = {'towns_label': _(u"Towns")} + +    EXTRA_REQUEST_KEYS = {'towns_label': 'towns'}      # alternative names of fields for searches      ALT_NAMES = { @@ -263,6 +265,9 @@ class ArchaeologicalSite(BaseHistorizedItem):          return [u"{} ({})".format(town.name, town.numero_insee) for town in                  self.towns.all()] +    def towns_label(self): +        return u" - ".join(self.towns_codes()) +      def create_or_update_top_operation(self, create=False):          """          Create a virtual operation to associate with the site. @@ -368,7 +373,7 @@ class ClosedItem(object):  class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,                  ShortMenuItem, DashboardFormItem, RelationItem):      SHOW_URL = 'show-operation' -    TABLE_COLS = ['year', 'towns', 'common_name', 'operation_type', +    TABLE_COLS = ['year', 'towns_label', 'common_name', 'operation_type',                    'start_date', 'excavation_end_date', 'remains']      SLUG = 'operation' @@ -405,11 +410,12 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          'finds_deadline_before': 'finds_deadline__lte',          'finds_deadline_after': 'finds_deadline__gte',          'related_treatment': -        'context_record__base_finds__find__upstream_treatment__id' +        'context_record__base_finds__find__upstream_treatment__id', +        'towns_label': 'towns'      }      COL_LABELS = { -        'full_code_patriarche': u"Code patriarche", +        'code_patriarche': u"Code patriarche",          'associated_file_short_label': _(u"Associated file (label)"),          'operator__name': _(u"Operator name"),          'scientist__raw_name': _(u"Scientist (full name)"), @@ -428,6 +434,7 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,                                                u"Organisation (nom)",          'archaeological_sites__reference': _(u"Archaeological sites ("                                               u"reference)"), +        'towns_label': _(u"Towns"),      }      BASE_SEARCH_VECTORS = [          "abstract", @@ -678,7 +685,7 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,      if settings.COUNTRY == 'fr':          code_patriarche = models.TextField(u"Code PATRIARCHE", null=True,                                             blank=True, unique=True) -        TABLE_COLS = ['full_code_patriarche'] + TABLE_COLS +        TABLE_COLS = ['code_patriarche'] + TABLE_COLS          BASE_SEARCH_VECTORS = ['code_patriarche'] + BASE_SEARCH_VECTORS          # preventive          fnap_financing = models.FloatField(u"Financement FNAP (%)", @@ -825,6 +832,9 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          return [u"{} ({})".format(town.name, town.numero_insee) for town in                  self.towns.all()] +    def towns_label(self): +        return u" - ".join(self.towns_codes()) +      def has_finds(self):          from archaeological_finds.models import BaseFind          return BaseFind.objects.filter(context_record__operation=self).count() @@ -1332,9 +1342,10 @@ post_delete.connect(post_save_cache, sender=ActType)  class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): -    TABLE_COLS = ['full_ref', 'year', 'index', 'act_type', 'act_object', -                  'signature_date', 'associated_file', 'operation', -                  'towns_label'] +    TABLE_COLS = ['full_ref', 'signature_date__year', 'index', 'act_type', +                  'act_object', 'signature_date', +                  'associated_file__cached_label', +                  'operation__cached_label', 'towns_label']      TABLE_COLS_FILE = [          'full_ref', 'year', 'index', 'act_type',          'act_object', 'associated_file', 'towns_label', @@ -1391,7 +1402,11 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):      REVERSED_BOOL_FIELDS = ['index__isnull']      RELATIVE_SESSION_NAMES = [('operation', 'operation__pk'),                                ('file', 'associated_file__pk')] -    COL_LABELS = {'full_ref': _(u"Ref.")} +    COL_LABELS = { +        'full_ref': _(u"Ref."), 'signature_date__year': _(u"Year"), +        'associated_file__cached_label': _(u"Archaeological file"), +        'operation__cached_label': _(u"Operation"), +    }      BASE_SEARCH_VECTORS = ['act_type__label', 'act_object',                             'towns_label']      INT_SEARCH_VECTORS = ["year", "index"] diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index bbcdd93d7..15d51aca1 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -314,6 +314,7 @@ class Container(LightHistorizedItem, ImageModel):          'finds__base_finds__context_record':              'finds__base_finds__context_record',          'finds': 'finds', +        'container_type__label': 'container_type__label',      }      SHOW_URL = 'show-container'      COL_LABELS = { diff --git a/ishtar_common/models.py b/ishtar_common/models.py index dfcf503af..8d0545885 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3317,7 +3317,8 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported):      SLUG = 'document'      LINK_SPLIT = u"<||>" -    TABLE_COLS = ['title', 'source_type', 'cache_related_label', 'authors', +    TABLE_COLS = ['title', 'source_type', 'cache_related_label', +                  'authors__cached_label',                    'associated_url']      COL_LINK = ['associated_url']      BASE_SEARCH_VECTORS = ['title', 'source_type__label', 'external_id', @@ -3327,6 +3328,8 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported):      BOOL_FIELDS = ['duplicate'] +    COL_LABELS = {"authors__cached_label": _(u"Authors")} +      CACHED_LABELS = ['cache_related_label']      EXTRA_REQUEST_KEYS = {          "operations": "operations__pk", @@ -3337,6 +3340,7 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported):              "finds__base_finds__context_record__pk",          "finds__base_finds__context_record__operation":              "finds__base_finds__context_record__operation__pk", +        'authors__cached_label': 'authors__cached_label',      }      # alternative names of fields for searches diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 1b6d1e724..374dc3927 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -1120,8 +1120,15 @@ def get_item(model, func_name, default_name, extra_request_keys=[],                      for k in ks:                          if k.endswith("__pk"):                              k = k[:-len("__pk")] + "__label" -                        if '__' in k: -                            k = k.split('__')[0] +                        if k.endswith("towns"): +                            k = k + "__cached_label" +                        if k.endswith("__icontains") or \ +                                k.endswith("__contains") or \ +                                k.endswith("__iexact") or \ +                                k.endswith("__exact"): +                            k = '__'.join(k.split('__')[:-1]) +                        # if '__' in k: +                        #     k = k.split('__')[0]                          orders.append(signe + k)                  else:                      # not a standard request key | 
