From dafc097282ea0138f8bd7c0e8a705bd18c90b5df Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 24 Mar 2017 17:48:18 +0100 Subject: Warehouse: divisions forms is readonly if containers are localised in this warehouse (refs #3563) --- .../ishtar/wizard/wizard_containerlocalisation.html | 4 +++- .../ishtar/wizard/wizard_warehouse_divisions.html | 11 +++++++++++ archaeological_warehouse/wizards.py | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html (limited to 'archaeological_warehouse') diff --git a/archaeological_warehouse/templates/ishtar/wizard/wizard_containerlocalisation.html b/archaeological_warehouse/templates/ishtar/wizard/wizard_containerlocalisation.html index 2e817ff41..41be02748 100644 --- a/archaeological_warehouse/templates/ishtar/wizard/wizard_containerlocalisation.html +++ b/archaeological_warehouse/templates/ishtar/wizard/wizard_containerlocalisation.html @@ -3,7 +3,9 @@ {% load url from future %} {% block form_head %} {% if not wizard.form.fields %} -

{% trans "No division set for this warehouse. Define at least one division to localise containers in this warehouse." %}
+

+ + {% trans "No division set for this warehouse. Define at least one division to localise containers in this warehouse." %}
{{wizard.form.warehouse}} diff --git a/archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html b/archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html new file mode 100644 index 000000000..83dbfc0fe --- /dev/null +++ b/archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html @@ -0,0 +1,11 @@ +{% extends "ishtar/wizard/default_wizard.html" %} +{% load i18n %} +{% load url from future %} +{% block form_head %} +{% if wizard.form.readonly %} +

+ + {% trans "Containers with localisation are associated to this warehouse. You cannot change divisions." %}
+

+{% endif %} +{% endblock %} diff --git a/archaeological_warehouse/wizards.py b/archaeological_warehouse/wizards.py index 9ecc16b3f..571e56b1b 100644 --- a/archaeological_warehouse/wizards.py +++ b/archaeological_warehouse/wizards.py @@ -64,6 +64,20 @@ class WarehouseModificationWizard(Wizard): model = models.Warehouse modification = True wizard_done_window = reverse_lazy('show-warehouse') + wizard_templates = { + 'divisions-warehouse_modification': + 'ishtar/wizard/wizard_warehouse_divisions.html', + } + + def get_form_kwargs(self, step=None): + kwargs = super(WarehouseModificationWizard, self).get_form_kwargs(step) + if step == "divisions-warehouse_modification": + current_warehouse = self.get_current_object() + q = models.ContainerLocalisation.objects.filter( + division__warehouse=current_warehouse) + if q.count(): + kwargs['readonly'] = True + return kwargs class WarehouseDeletionWizard(DeletionWizard): -- cgit v1.2.3 From 02136acb286d0f6b97dcbc715138f085d59767ea Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 28 Mar 2017 13:17:29 +0200 Subject: Access control: fix get owns query for UEs, finds, warehouses and containers --- archaeological_context_records/models.py | 7 ++++--- archaeological_files/models.py | 2 +- archaeological_finds/models_finds.py | 11 ++++++----- archaeological_warehouse/models.py | 11 +++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'archaeological_warehouse') diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 4df56c49f..a16b4cae7 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -365,9 +365,10 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, @classmethod def get_query_owns(cls, user): - return Q(operation__scientist=user.ishtaruser.person) |\ - Q(operation__in_charge=user.ishtaruser.person) |\ - Q(history_creator=user) + return (Q(operation__scientist=user.ishtaruser.person) | + Q(operation__in_charge=user.ishtaruser.person) | + Q(history_creator=user)) \ + & Q(operation__end_date__isnull=True) @classmethod def get_owns(cls, user, menu_filtr=None, limit=None, diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 7f37a298f..52f628817 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2012-2016 Étienne Loks +# Copyright (C) 2012-2017 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index c54fd1ed9..cbd13e925 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -868,11 +868,12 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): @classmethod def get_query_owns(cls, user): - return Q(base_finds__context_record__operation__scientist=user. - ishtaruser.person) | \ - Q(base_finds__context_record__operation__in_charge=user. - ishtaruser.person) | \ - Q(history_creator=user) + return (Q(base_finds__context_record__operation__scientist=user. + ishtaruser.person) | + Q(base_finds__context_record__operation__in_charge=user. + ishtaruser.person) | + Q(history_creator=user)) \ + & Q(base_finds__context_record__operation__end_date__isnull=True) @classmethod def get_owns(cls, user, menu_filtr=None, limit=None, diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index d1918f46a..fe054a37b 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -21,6 +21,7 @@ import datetime from django.conf import settings 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 _, ugettext @@ -78,6 +79,10 @@ class Warehouse(Address, OwnPerms): return datetime.date.today().strftime('%Y-%m-%d') + '-' + \ slugify(unicode(self)) + @classmethod + def get_query_owns(cls, user): + return Q(person_in_charge__ishtaruser=user.ishtaruser) + def save(self, *args, **kwargs): super(Warehouse, self).save(*args, **kwargs) for container in self.containers.all(): @@ -208,6 +213,12 @@ class Container(LightHistorizedItem, ImageModel): cached_label = u" - ".join(items) return cached_label + @classmethod + def get_query_owns(cls, user): + return Q(history_creator=user) | \ + Q(location__person_in_charge__ishtaruser=user.ishtaruser) | \ + Q(responsible__person_in_charge__ishtaruser=user.ishtaruser) + @property def associated_filename(self): filename = datetime.date.today().strftime('%Y-%m-%d') -- cgit v1.2.3 From 2e512bc9dffca5624342aa75ca01b3ff7f390141 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 5 Apr 2017 11:33:54 +0200 Subject: Warehouse sheet: provide statistics (refs #3398) - Number of finds (total and by places) - Number of container (total and by places) --- archaeological_finds/models_finds.py | 8 +- archaeological_operations/models.py | 8 -- .../templates/ishtar/sheet_operation.html | 1 + archaeological_warehouse/models.py | 103 ++++++++++++++++++++- .../templates/ishtar/sheet_warehouse.html | 44 +++++++++ example_project/settings.py | 2 +- ishtar_common/models.py | 13 +++ ishtar_common/static/media/style.css | 6 ++ 8 files changed, 168 insertions(+), 17 deletions(-) (limited to 'archaeological_warehouse') diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 3785267b2..52601c896 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -37,7 +37,6 @@ from archaeological_operations.models import AdministrativeAct from archaeological_context_records.models import ContextRecord, Dating from ishtar_common.models import PRIVATE_FIELDS, SpatialReferenceSystem -from archaeological_warehouse.models import Container, Collection class MaterialType(GeneralType): @@ -637,7 +636,8 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): datings = models.ManyToManyField(Dating, verbose_name=_(u"Dating"), related_name='find') container = models.ForeignKey( - Container, verbose_name=_(u"Container"), blank=True, null=True, + "archaeological_warehouse.Container", verbose_name=_(u"Container"), + blank=True, null=True, related_name='finds', on_delete=models.SET_NULL) is_complete = models.NullBooleanField(_(u"Is complete?"), blank=True, null=True) @@ -671,8 +671,8 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): estimated_value = models.FloatField(_(u"Estimated value"), blank=True, null=True) collection = models.ForeignKey( - Collection, verbose_name=_(u"Collection"), blank=True, null=True, - related_name='finds', on_delete=models.SET_NULL) + "archaeological_warehouse.Collection", verbose_name=_(u"Collection"), + blank=True, null=True, related_name='finds', on_delete=models.SET_NULL) cached_label = models.TextField(_(u"Cached name"), null=True, blank=True) history = HistoricalRecords() BASKET_MODEL = FindBasket diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index bef149b2c..3826678c3 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -593,14 +593,6 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, nb = self.parcels.count() return nb - def _get_or_set_stats(self, funcname, update): - key, val = get_cache(self.__class__, [funcname, self.pk]) - if not update and val is not None: - return val - val = getattr(self, funcname)() - cache.set(key, val, settings.CACHE_TIMEOUT) - return val - @property def nb_acts(self, update=False): _(u"Number of administrative acts") diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index 71f41d8c4..5051c4604 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -142,6 +142,7 @@ {% endif %}

{% trans "Statistics" %}

+{% trans "Theses number are updated hourly" %}

{% trans "Administrative acts" %}