summaryrefslogtreecommitdiff
path: root/archaeological_operations/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-10-01 15:10:07 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-10-24 12:06:08 +0200
commit95f9959de49ab5271e95451831837c87ead88237 (patch)
tree8d6e00ce0a1a19b41869b6b6b2ebc5afbb133b64 /archaeological_operations/models.py
parentf0e8bab97707a729bada5b7fa17d81202ab8eaa8 (diff)
downloadIshtar-95f9959de49ab5271e95451831837c87ead88237.tar.bz2
Ishtar-95f9959de49ab5271e95451831837c87ead88237.zip
Manage site and warehouse in shortcut menu - Many fixes on pin
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r--archaeological_operations/models.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index a6b6daf71..1d7f17fa8 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -184,6 +184,14 @@ class ArchaeologicalSite(BaseHistorizedItem, OwnPerms, ValueGetter,
pgettext_lazy("key for text search", u"discovery-area"),
'discovery_area__iexact'
),
+ 'operation': (
+ pgettext_lazy("key for text search", u"operation"),
+ 'operations__cached_label__icontains'
+ ),
+ 'top_operation': (
+ pgettext_lazy("key for text search", u"top-operation"),
+ 'top_operation__cached_label__icontains'
+ ),
}
for v in ALT_NAMES.values():
for language_code, language_lbl in settings.LANGUAGES:
@@ -192,6 +200,14 @@ class ArchaeologicalSite(BaseHistorizedItem, OwnPerms, ValueGetter,
deactivate()
objects = SiteManager()
+ UP_MODEL_QUERY = {
+ "operation": (pgettext_lazy("key for text search", u"operation"),
+ 'cached_label'),
+ }
+ RELATIVE_SESSION_NAMES = [
+ ('operation', 'operations__pk'),
+ ]
+
reference = models.CharField(_(u"Reference"), max_length=200, unique=True)
name = models.CharField(_(u"Name"), max_length=200,
null=True, blank=True)
@@ -258,6 +274,32 @@ class ArchaeologicalSite(BaseHistorizedItem, OwnPerms, ValueGetter,
self.save()
return self.cached_label
+ @property
+ def short_class_name(self):
+ return _(u"SITE")
+
+ @classmethod
+ def get_query_owns(cls, ishtaruser):
+ q = cls._construct_query_own(
+ 'operations__', Operation._get_query_owns_dicts(ishtaruser)
+ ) | cls._construct_query_own('', [
+ {'history_creator': ishtaruser.user_ptr},
+ ])
+ return q
+
+ @classmethod
+ def get_owns(cls, user, menu_filtr=None, limit=None, values=None,
+ get_short_menu_class=None):
+ replace_query = None
+ if menu_filtr and 'operation' in menu_filtr:
+ replace_query = Q(operations=menu_filtr['operation'])
+
+ owns = super(ArchaeologicalSite, cls).get_owns(
+ user, replace_query=replace_query,
+ limit=limit, values=values,
+ get_short_menu_class=get_short_menu_class)
+ return cls._return_get_owns(owns, values, get_short_menu_class)
+
def _generate_cached_label(self):
name = self.reference
if self.name:
@@ -409,7 +451,6 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
'excavation_end_date__gte', 'documentation_deadline__lte',
'documentation_deadline__gte', 'finds_deadline__lte',
'finds_deadline__gte']
- RELATIVE_SESSION_NAMES = [('file', 'associated_file__pk')]
EXTRA_REQUEST_KEYS = {
'common_name': 'common_name__icontains',
'cached_label': 'cached_label__icontains',
@@ -650,6 +691,17 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
EXTRA_REQUEST_KEYS[unicode(v[0])] = v[1]
deactivate()
+ UP_MODEL_QUERY = {
+ "site": (pgettext_lazy("key for text search", u"site"),
+ 'cached_label'),
+ "file": (pgettext_lazy("key for text search", u"file"),
+ 'cached_label'),
+ }
+ RELATIVE_SESSION_NAMES = [
+ ('file', 'associated_file__pk'),
+ ('site', 'archaeological_sites__pk'),
+ ]
+
POST_PROCESS_REQUEST = {
'towns__numero_insee__startswith': '_get_department_code',
}