diff options
Diffstat (limited to 'archaeological_finds/models_finds.py')
| -rw-r--r-- | archaeological_finds/models_finds.py | 134 |
1 files changed, 121 insertions, 13 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 1ef9d5846..5ded360a8 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -39,10 +39,12 @@ from ishtar_common.models import Document, GeneralType, \ HierarchicalType, BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \ HistoricalRecords, OwnPerms, Person, Basket, post_save_cache, \ ValueGetter, get_current_profile, IshtarSiteProfile, PRIVATE_FIELDS, \ - SpatialReferenceSystem, BulkUpdatedItem, ExternalIdManager + SpatialReferenceSystem, BulkUpdatedItem, ExternalIdManager, QuickAction, \ + MainItem from archaeological_operations.models import AdministrativeAct, Operation from archaeological_context_records.models import ContextRecord, Dating +from archaeological_warehouse.models import Warehouse class MaterialType(HierarchicalType): @@ -564,9 +566,34 @@ WEIGHT_UNIT = (('g', _(u"g")), ('kg', _(u"kg")),) -class FindBasket(Basket): +class FindBasket(Basket, OwnPerms): items = models.ManyToManyField('Find', blank=True, related_name='basket') + class Meta: + permissions = ( + ("view_find", u"Can view all Finds"), + ("view_own_find", u"Can view own Find"), + ) + + @classmethod + def get_query_owns(cls, ishtaruser): + return Q(user=ishtaruser) + + def get_extra_actions(self, request): + """ + For sheet template: return "Manage basket" action + """ + # url, base_text, icon, extra_text, extra css class, is a quick action + + # no particular rights: if you can view an itm you can add it to your + # own basket + actions = [ + (reverse("select_itemsinbasket", args=[self.pk]), + _(u"Manage basket"), + "fa fa-shopping-basket", "", "", False), + ] + return actions + class FirstBaseFindView(object): CREATE_SQL = """ @@ -605,7 +632,7 @@ class FBulkView(object): class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, - ShortMenuItem): + MainItem): EXTERNAL_ID_KEY = 'find_external_id' SHOW_URL = 'show-find' SLUG = 'find' @@ -678,11 +705,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, 'cr_relation_types': 'base_finds__context_record__', } - RELATIVE_SESSION_NAMES = [ - ('contextrecord', 'base_finds__context_record__pk'), - ('operation', 'base_finds__context_record__operation__pk'), - ('file', 'base_finds__context_record__operation__associated_file__pk') - ] + + DATED_FIELDS = ['last_modified__gte'] BASE_REQUEST = {'downstream_treatment__isnull': True} EXTRA_REQUEST_KEYS = { 'base_finds__context_record': @@ -709,7 +733,7 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, 'base_finds__find__description': 'base_finds__find__description__icontains', 'base_finds__batch': 'base_finds__batch', - 'basket': 'basket', + 'basket_id': 'basket__pk', 'denomination': 'denomination', 'cached_label': 'cached_label__icontains', 'documents__image__isnull': 'documents__image__isnull', @@ -857,7 +881,20 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, ), 'basket': ( pgettext_lazy("key for text search", u"basket"), - 'basket__label__exact' + 'basket__label__iexact' + ), + 'base_finds__context_record__operation__cached_label': ( + pgettext_lazy("key for text search", u"operation"), + 'base_finds__context_record__operation__cached_label__icontains' + ), + 'history_modifier': ( + pgettext_lazy("key for text search", u"last-modified-by"), + 'history_modifier__ishtaruser__person__cached_label__icontains' + ), + 'modified_since': ( + pgettext_lazy("key for text search", u"modified-since"), + 'last_modified__gte' + ), } for v in ALT_NAMES.values(): @@ -876,6 +913,45 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, M2M_SEARCH_VECTORS = [ "datings__period__label", "object_types__label", "integrities__label", "remarkabilities__label", "material_types__label"] + + QA_EDIT = QuickAction( + url="find-qa-bulk-update", icon_class="fa fa-pencil", + text=_(u"Bulk update"), target="many", + rights=['change_find', 'change_own_find']) + + QUICK_ACTIONS = [ + QA_EDIT, + QuickAction( + url="find-qa-basket", icon_class="fa fa-shopping-basket", + text=_(u"Basket"), target="many", + rights=['change_find', 'change_own_find']), + QuickAction( + url="find-qa-packaging", icon_class="fa fa-gift", + text=_(u"Packaging"), target="many", + rights=['change_find', 'change_own_find'], + module='warehouse' + ), + ] + UP_MODEL_QUERY = { + "operation": (pgettext_lazy("key for text search", u"operation"), + 'cached_label'), + "contextrecord": ( + pgettext_lazy("key for text search", u"context-record"), + 'cached_label'), + "warehouse": ( + pgettext_lazy("key for text search", u"location"), + 'name'), + "site": ( + pgettext_lazy("key for text search", u"context-record-site"), + 'cached_label'), + } + RELATIVE_SESSION_NAMES = [ + ('contextrecord', 'base_finds__context_record__pk'), + ('operation', 'base_finds__context_record__operation__pk'), + ('file', 'base_finds__context_record__operation__associated_file__pk'), + ('warehouse', 'container__location__pk'), + ('site', 'base_finds__context_record__archaeological_site__pk') + ] objects = ExternalIdManager() # fields @@ -1084,6 +1160,27 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, return "00" return bf.short_id() + def get_extra_actions(self, request): + """ + For sheet template: return "Add to basket" action + """ + # url, base_text, icon, extra_text, extra css class, is a quick action + + # no particular rights: if you can view an itm you can add it to your + # own basket + actions = [ + (reverse("find-qa-basket", args=[self.pk]), + _(u"Add to basket"), + "fa fa-shopping-basket", "", "", True), + ] + if get_current_profile().warehouse: + actions.append( + (reverse("find-qa-packaging", args=[self.pk]), + _(u"Packaging"), + "fa fa-gift", "", "", True) + ) + return actions + def _get_base_image_path(self): bf = None if self.id: @@ -1263,6 +1360,12 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, @classmethod def get_query_owns(cls, ishtaruser): q = cls._construct_query_own( + 'container__location__', + Warehouse._get_query_owns_dicts(ishtaruser) + ) | cls._construct_query_own( + 'container__responsible__', + Warehouse._get_query_owns_dicts(ishtaruser) + ) | cls._construct_query_own( 'base_finds__context_record__operation__', Operation._get_query_owns_dicts(ishtaruser) ) | cls._construct_query_own('', [ @@ -1337,6 +1440,12 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, profile = get_current_profile() + index = "" + if profile.find_use_index: + index = """|| '-' || + to_char(find_cached_bulk_update.index, 'fm{zeros}') + """.format(zeros=settings.ISHTAR_FINDS_INDEX_ZERO_LEN * "0") + sql = """ UPDATE "archaeological_finds_find" AS f SET cached_label = @@ -1359,8 +1468,7 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, '{main_ope_prefix}' || find_cached_bulk_update.main_ope_code END - || '-' || - to_char(find_cached_bulk_update.index, 'fm{zeros}') + {index} || '{join}' || find_cached_bulk_update.label @@ -1374,7 +1482,7 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, """.format(main_ope_prefix=profile.operation_prefix, ope_prefix=profile.default_operation_prefix, join=settings.JOINT, filters=filters, - zeros=settings.ISHTAR_FINDS_INDEX_ZERO_LEN * "0") + index=index) with connection.cursor() as c: c.execute(sql, args) |
