summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
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
commitd50d5077f9bf5eb6733de1a4a29d3ef1089cdd96 (patch)
tree8ccbb16c38a59cf640b490e1d1f5e4b40fa3abe6 /archaeological_warehouse/models.py
parent10086eb832b17b596ce8db07efd910d353cce514 (diff)
downloadIshtar-d50d5077f9bf5eb6733de1a4a29d3ef1089cdd96.tar.bz2
Ishtar-d50d5077f9bf5eb6733de1a4a29d3ef1089cdd96.zip
Container - warehouse form configuration - cache precise localisation
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py70
1 files changed, 54 insertions, 16 deletions
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(