diff options
Diffstat (limited to 'archaeological_warehouse')
-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 |
3 files changed, 82 insertions, 20 deletions
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( |