diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-14 16:57:48 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-14 16:57:48 +0200 | 
| commit | 7bff3eb7ca6e7ea59be77e0bd0d0471a5f8ff97a (patch) | |
| tree | 8ccbb16c38a59cf640b490e1d1f5e4b40fa3abe6 | |
| parent | fbd17f27b6a7eeaf8d85ba72cf535dad8c0cc5f1 (diff) | |
| download | Ishtar-7bff3eb7ca6e7ea59be77e0bd0d0471a5f8ff97a.tar.bz2 Ishtar-7bff3eb7ca6e7ea59be77e0bd0d0471a5f8ff97a.zip | |
Container - warehouse form configuration - cache precise localisation
| -rw-r--r-- | archaeological_finds/forms.py | 2 | ||||
| -rw-r--r-- | archaeological_finds/templates/ishtar/sheet_find.html | 2 | ||||
| -rw-r--r-- | archaeological_warehouse/forms.py | 12 | ||||
| -rw-r--r-- | archaeological_warehouse/migrations/0022_container_cached_division.py | 20 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 70 | ||||
| -rw-r--r-- | ishtar_common/forms_common.py | 4 | ||||
| -rw-r--r-- | ishtar_common/migrations/0065_author_cached_label.py | 20 | ||||
| -rw-r--r-- | ishtar_common/models.py | 54 | 
8 files changed, 160 insertions, 24 deletions
| diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 358b12477..c575bc876 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -406,7 +406,7 @@ DatingFormSet.form_admin_name = _(u"Find - 040 - Dating")  DatingFormSet.form_slug = "find-040-dating" -class FindSelect(CustomForm, TableSelect): +class FindSelect(CustomForm, TableSelect):  # OK      _model = models.Find      form_admin_name = _(u"Find - 001 - Search") diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index aa1f9bb12..6c14e5c53 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -210,7 +210,7 @@      {% field_flex "Container ID" item.container.cached_location %}      {% field_flex_detail "Responsible warehouse" item.container.responsible %}      {% field_flex_detail "Location (warehouse)" item.container.location %} -    {% field_flex "Precise localisation" item.container.divisions_lbl %} +    {% field_flex "Precise localisation" item.container.cached_division %}  </div>  {% endif %} diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 09c64a7dc..8192e36df 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -78,14 +78,15 @@ SelectedDivisionFormset.form_admin_name = _(u"Warehouse - 020 - Divisions")  SelectedDivisionFormset.form_slug = "warehouse-020-divisions" -class WarehouseSelect(TableSelect): +class WarehouseSelect(TableSelect):  # OK +    _model = models.Warehouse +      search_vector = forms.CharField(          label=_(u"Full text search"), widget=widgets.SearchWidget(              'archaeological-warehouse', 'warehouse'          ))      name = forms.CharField(label=_(u"Name"))      warehouse_type = forms.ChoiceField(label=_(u"Warehouse type"), choices=[]) -    towns = forms.CharField(label=_(u"Town"))      def __init__(self, *args, **kwargs):          super(WarehouseSelect, self).__init__(*args, **kwargs) @@ -246,12 +247,15 @@ class ContainerModifyForm(ContainerForm):          return cleaned_data -class ContainerSelect(TableSelect): +class ContainerSelect(TableSelect):  # OK +    _model = models.Container +      search_vector = forms.CharField(          label=_(u"Full text search"), widget=widgets.SearchWidget(              'archaeological-warehouse', 'container'          )) -    location = get_warehouse_field() +    location = get_warehouse_field(label=_(u"Current location (warehouse)")) +    responsible = get_warehouse_field(label=_(u"Responsible warehouse"))      container_type = forms.ChoiceField(label=_(u"Container type"), choices=[])      reference = forms.CharField(label=_(u"Ref.")) diff --git a/archaeological_warehouse/migrations/0022_container_cached_division.py b/archaeological_warehouse/migrations/0022_container_cached_division.py new file mode 100644 index 000000000..18d1c14f4 --- /dev/null +++ b/archaeological_warehouse/migrations/0022_container_cached_division.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-14 16:41 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('archaeological_warehouse', '0021_auto_20180601_1555'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='container', +            name='cached_division', +            field=models.TextField(blank=True, db_index=True, null=True, verbose_name='Cached division'), +        ), +    ] diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 9b0ff2e86..5105416d6 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -24,13 +24,13 @@ from django.contrib.gis.db import models  from django.db.models import Q  from django.db.models.signals import post_save, post_delete  from django.template.defaultfilters import slugify -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, pgettext_lazy  from ishtar_common.data_importer import post_importer_action  from ishtar_common.models import Document, GeneralType, get_external_id, \      LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \      ImageModel, DashboardFormItem -from ishtar_common.utils import cached_label_changed +from ishtar_common.utils import cached_label_changed, TXT_SEARCH_COMMENT  class WarehouseType(GeneralType): @@ -51,6 +51,21 @@ class Warehouse(Address, DashboardFormItem, OwnPerms):      BASE_SEARCH_VECTORS = ['name', 'warehouse_type__label', "external_id",                             "town", "comment"] +    EXTRA_REQUEST_KEYS = {} +    # alternative names of fields for searches +    ALT_NAMES = { +        'name': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"name"), +            'name__icontains' +        ), +        'warehouse_type': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"type"), +            'warehouse_type__label__iexact' +        ), +    } +    for v in ALT_NAMES.values(): +        EXTRA_REQUEST_KEYS[v[0]] = v[1] +      name = models.CharField(_(u"Name"), max_length=200)      warehouse_type = models.ForeignKey(WarehouseType,                                         verbose_name=_(u"Warehouse type")) @@ -267,7 +282,7 @@ post_delete.connect(post_save_cache, sender=ContainerType)  class Container(LightHistorizedItem, ImageModel):      TABLE_COLS = ['reference', 'container_type__label', 'cached_location', -                  'divisions_lbl', 'old_reference'] +                  'cached_division', 'old_reference']      IMAGE_PREFIX = 'containers/'      BASE_SEARCH_VECTORS = ['reference', 'container_type__label',                             'cached_location'] @@ -289,10 +304,32 @@ class Container(LightHistorizedItem, ImageModel):      SHOW_URL = 'show-container'      COL_LABELS = {          'cached_location': _(u"Location - index"), -        'divisions_lbl': _(u"Precise localisation"), +        'cached_division': _(u"Precise localisation"),          'container_type__label': _(u"Type")      } -    CACHED_LABELS = ['cached_label', 'cached_location'] +    CACHED_LABELS = ['cached_label', 'cached_location', 'cached_division'] + +    # alternative names of fields for searches +    ALT_NAMES = { +        'location': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"location"), +            'location__name__icontains' +        ), +        'responsible': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"responsible-warehouse"), +            'responsible__name__icontains' +        ), +        'container_type': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"type"), +            'warehouse_type__label__iexact' +        ), +        'reference': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"reference"), +            'reference__icontains' +        ), +    } +    for v in ALT_NAMES.values(): +        EXTRA_REQUEST_KEYS[v[0]] = v[1]      # fields      location = models.ForeignKey( @@ -309,6 +346,8 @@ class Container(LightHistorizedItem, ImageModel):                                      db_index=True)      cached_location = models.TextField(_(u"Cached location"),                                         null=True, blank=True, db_index=True) +    cached_division = models.TextField(_(u"Cached division"), +                                       null=True, blank=True, db_index=True)      index = models.IntegerField(u"Container ID", default=0)      old_reference = models.TextField(_(u"Old reference"), blank=True, null=True)      external_id = models.TextField(_(u"External ID"), blank=True, null=True) @@ -342,6 +381,14 @@ class Container(LightHistorizedItem, ImageModel):          cached_label = u" - ".join(items)          return cached_label +    def _generate_cached_division(self): +        locas = [ +            u"{} {}".format(loca.division.division, loca.reference) +            for loca in ContainerLocalisation.objects.filter( +                container=self) +        ] +        return u" | ".join(locas) +      @classmethod      def get_query_owns(cls, ishtaruser):          return Q(history_creator=ishtaruser.user_ptr) | \ @@ -354,12 +401,12 @@ class Container(LightHistorizedItem, ImageModel):          filename += u'-' + self.reference          filename += u"-" + self.location.name          filename += u"-" + unicode(self.index) -        filename += u"-" + self.divisions_lbl +        filename += u"-" + self.cached_division          return slugify(filename)      @property      def precise_location(self): -        return self.location.name + u" - " + self.divisions_lbl +        return self.location.name + u" - " + (self.cached_division or u"")      def get_localisations(self):          """ @@ -476,15 +523,6 @@ class Container(LightHistorizedItem, ImageModel):      def set_localisation_9(self, context, value):          return self.set_localisation(8, value) -    @property -    def divisions_lbl(self): -        locas = [ -            u"{} {}".format(loca.division.division, loca.reference) -            for loca in ContainerLocalisation.objects.filter( -                container=self) -            ] -        return u" | ".join(locas) -      def pre_save(self):          if not self.index:              q = Container.objects.filter(responsible=self.responsible).order_by( diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index e6f37a794..3745d5f73 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1183,7 +1183,9 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType):          return item -class DocumentSelect(TableSelect): +class DocumentSelect(TableSelect):  # OK +    _model = models.Document +      search_vector = forms.CharField(          label=_(u"Full text search"), widget=widgets.SearchWidget(              'ishtar-common', 'document' diff --git a/ishtar_common/migrations/0065_author_cached_label.py b/ishtar_common/migrations/0065_author_cached_label.py new file mode 100644 index 000000000..adaaed9fa --- /dev/null +++ b/ishtar_common/migrations/0065_author_cached_label.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-14 15:53 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0064_auto_20180808_1116'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='author', +            name='cached_label', +            field=models.TextField(blank=True, db_index=True, null=True, verbose_name='Cached name'), +        ), +    ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e16c4a360..81a391b3b 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3168,6 +3168,8 @@ class Author(FullSearch):      person = models.ForeignKey(Person, verbose_name=_(u"Person"),                                 related_name='author')      author_type = models.ForeignKey(AuthorType, verbose_name=_(u"Author type")) +    cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, +                                    db_index=True)      class Meta:          verbose_name = _(u"Author") @@ -3182,6 +3184,12 @@ class Author(FullSearch):          )      def __unicode__(self): +        if self.cached_label: +            return self.cached_label +        self.save() +        return self.cached_label + +    def _generate_cached_label(self):          return unicode(self.person) + settings.JOINT + \              unicode(self.author_type) @@ -3196,6 +3204,9 @@ class Author(FullSearch):              list(self.contextrecordsource_related.all()) +post_save.connect(cached_label_changed, sender=Author) + +  class SourceType(HierarchicalType):      class Meta:          verbose_name = _(u"Source type") @@ -3276,9 +3287,50 @@ 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__person": "authors__person__pk"      } +    # alternative names of fields for searches +    ALT_NAMES = { +        'authors': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"author"), +            'authors__cached_label__icontains' +        ), +        'title': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"title"), +            'title__icontains' +        ), +        'source_type': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"type"), +            'source_type__label__iexact' +        ), +        'reference': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"reference"), +            'reference__icontains' +        ), +        'internal_reference': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"internal-reference"), +            'internal_reference__icontains' +        ), +        'description': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"description"), +            'description__icontains' +        ), +        'comment': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"comment"), +            'comment__icontains' +        ), +        'additional_information': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"additional-information"), +            'additional_information__icontains' +        ), +        'duplicate': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"has-duplicate"), +            'duplicate' +        ), +    } +    for v in ALT_NAMES.values(): +        EXTRA_REQUEST_KEYS[v[0]] = v[1] +      title = models.TextField(_(u"Title"), blank=True, default='')      associated_file = models.FileField(          upload_to=get_image_path, blank=True, null=True, max_length=255) | 
