diff options
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/forms.py | 12 | ||||
-rw-r--r-- | archaeological_operations/models.py | 54 | ||||
-rw-r--r-- | archaeological_operations/urls.py | 3 |
3 files changed, 68 insertions, 1 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 9a54e0d8c..a8c827757 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -1244,6 +1244,18 @@ class SiteSelect(TableSelect): towns = get_town_field() comment = forms.CharField(label=_(u"Comment"), max_length=200, required=False) + top_operation = forms.IntegerField( + label=_(u"Top operation"), required=False, + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-operation'), + associated_model=models.Operation), + validators=[valid_id(models.Operation)]) + operation = forms.IntegerField( + label=_(u"Operation"), required=False, + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-operation'), + associated_model=models.Operation), + validators=[valid_id(models.Operation)]) locality_ngi = forms.CharField( label=_(u"National Geographic Institute locality"), max_length=200, required=False) 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', } diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py index d4fcd578a..fe2480940 100644 --- a/archaeological_operations/urls.py +++ b/archaeological_operations/urls.py @@ -132,6 +132,9 @@ urlpatterns = [ views.get_site, name='get-site'), url(r'get-site-full/(?P<type>.+)?$', views.get_site, name='get-site-full', kwargs={'full': True}), + url(r'get-site-shortcut/(?P<type>.+)?$', + views.get_site, name='get-site-shortcut', + kwargs={'full': 'shortcut'}), url(r'revert-site/(?P<pk>.+)/(?P<date>.+)$', views.revert_site, name='revert-site'), url(r'show-site(?:/(?P<pk>.+))?/(?P<type>.+)?$', |