summaryrefslogtreecommitdiff
path: root/archaeological_warehouse
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r--archaeological_warehouse/ishtar_menu.py12
-rw-r--r--archaeological_warehouse/locale/django.pot153
-rw-r--r--archaeological_warehouse/migrations/0023_auto_20181017_1642.py41
-rw-r--r--archaeological_warehouse/migrations/0024_auto_20181017_1854.py30
-rw-r--r--archaeological_warehouse/models.py22
-rw-r--r--archaeological_warehouse/urls.py11
-rw-r--r--archaeological_warehouse/views.py36
7 files changed, 204 insertions, 101 deletions
diff --git a/archaeological_warehouse/ishtar_menu.py b/archaeological_warehouse/ishtar_menu.py
index bcbfe881b..20544db2d 100644
--- a/archaeological_warehouse/ishtar_menu.py
+++ b/archaeological_warehouse/ishtar_menu.py
@@ -58,16 +58,20 @@ MENU_SECTIONS = [
childs=[
MenuItem('container_search', _(u"Search"),
model=models.Warehouse,
- access_controls=['change_warehouse',]),
+ access_controls=['view_container',
+ 'view_own_container']),
MenuItem('container_creation', _(u"Creation"),
model=models.Warehouse,
- access_controls=['change_warehouse',]),
+ access_controls=['add_container',
+ 'add_own_container']),
MenuItem('container_modification', _(u"Modification"),
model=models.Warehouse,
- access_controls=['change_warehouse',]),
+ access_controls=['change_container',
+ 'change_own_container']),
MenuItem('container_deletion', _(u"Deletion"),
model=models.Warehouse,
- access_controls=['change_warehouse',]),
+ access_controls=['change_container',
+ 'change_own_container']),
])
]))
]
diff --git a/archaeological_warehouse/locale/django.pot b/archaeological_warehouse/locale/django.pot
index f45ea6e23..139895395 100644
--- a/archaeological_warehouse/locale/django.pot
+++ b/archaeological_warehouse/locale/django.pot
@@ -9,16 +9,16 @@
msgid ""
msgstr ""
-#: forms.py:41 forms.py:113 ishtar_menu.py:40 models.py:88 models.py:230
+#: forms.py:41 forms.py:113 ishtar_menu.py:40 models.py:94 models.py:258
#: templates/ishtar/sheet_warehouse.html:4
msgid "Warehouse"
msgstr ""
-#: forms.py:50 forms.py:55 models.py:576
+#: forms.py:50 forms.py:55 models.py:622
msgid "Division"
msgstr ""
-#: forms.py:57 models.py:256
+#: forms.py:57 models.py:286
msgid "Order"
msgstr ""
@@ -26,7 +26,7 @@ msgstr ""
msgid "There are identical divisions."
msgstr ""
-#: forms.py:76 models.py:77
+#: forms.py:76 models.py:83
msgid "Divisions"
msgstr ""
@@ -38,15 +38,15 @@ msgstr ""
msgid "Full text search"
msgstr ""
-#: forms.py:88 forms.py:119 models.py:69 models.py:227
+#: forms.py:88 forms.py:119 models.py:75 models.py:255
msgid "Name"
msgstr ""
-#: forms.py:89 forms.py:121 models.py:38 models.py:71
+#: forms.py:89 forms.py:121 models.py:39 models.py:77
msgid "Warehouse type"
msgstr ""
-#: forms.py:101 views.py:97
+#: forms.py:101 views.py:108
msgid "Warehouse search"
msgstr ""
@@ -54,11 +54,11 @@ msgstr ""
msgid "Warehouse - 010 - General"
msgstr ""
-#: forms.py:124 models.py:74
+#: forms.py:124 models.py:80
msgid "Person in charge"
msgstr ""
-#: forms.py:130 forms.py:198 models.py:75 models.py:344
+#: forms.py:130 forms.py:198 models.py:81 models.py:381
msgid "Comment"
msgstr ""
@@ -94,7 +94,7 @@ msgstr ""
msgid "Would you like to delete this warehouse?"
msgstr ""
-#: forms.py:172 models.py:358 models.py:573
+#: forms.py:172 models.py:395 models.py:619
#: templates/ishtar/sheet_container.html:4
msgid "Container"
msgstr ""
@@ -103,23 +103,23 @@ msgstr ""
msgid "Container - 010 - General"
msgstr ""
-#: forms.py:179 forms.py:260 models.py:271
+#: forms.py:179 forms.py:261 models.py:301
msgid "Ref."
msgstr ""
-#: forms.py:180 models.py:352
+#: forms.py:180 models.py:389
msgid "Old reference"
msgstr ""
-#: forms.py:182 forms.py:259 models.py:274 models.py:342
+#: forms.py:182 forms.py:260 models.py:304 models.py:379
msgid "Container type"
msgstr ""
-#: forms.py:184 forms.py:257
+#: forms.py:184 forms.py:258
msgid "Current location (warehouse)"
msgstr ""
-#: forms.py:190 forms.py:258 models.py:339
+#: forms.py:190 forms.py:259 models.py:376
msgid "Responsible warehouse"
msgstr ""
@@ -135,43 +135,43 @@ msgstr ""
msgid "This ID already exists for this warehouse."
msgstr ""
-#: forms.py:271 forms.py:277 views.py:139
+#: forms.py:272 forms.py:278 views.py:150
msgid "Container search"
msgstr ""
-#: forms.py:273 forms.py:279
+#: forms.py:274 forms.py:280
msgid "You should select a container."
msgstr ""
-#: forms.py:274
+#: forms.py:275
msgid "Add a new container"
msgstr ""
-#: forms.py:284 ishtar_menu.py:36 views.py:92
+#: forms.py:285 ishtar_menu.py:36 views.py:103
msgid "Packaging"
msgstr ""
-#: forms.py:290
+#: forms.py:291
msgid "Packager"
msgstr ""
-#: forms.py:296
+#: forms.py:297
msgid "Date"
msgstr ""
-#: forms.py:300
+#: forms.py:301
msgid "Packaged finds"
msgstr ""
-#: forms.py:304
+#: forms.py:305
msgid "Container - 020 - Localisation"
msgstr ""
-#: forms.py:306 models.py:345
+#: forms.py:307 models.py:382
msgid "Localisation"
msgstr ""
-#: forms.py:330 forms.py:331
+#: forms.py:331 forms.py:332
msgid "Would you like to delete this container?"
msgstr ""
@@ -183,141 +183,141 @@ msgstr ""
msgid "Search"
msgstr ""
-#: ishtar_menu.py:47 ishtar_menu.py:62
+#: ishtar_menu.py:47 ishtar_menu.py:63
msgid "Creation"
msgstr ""
-#: ishtar_menu.py:50 ishtar_menu.py:65
+#: ishtar_menu.py:50 ishtar_menu.py:67
msgid "Modification"
msgstr ""
-#: ishtar_menu.py:53 ishtar_menu.py:68
+#: ishtar_menu.py:53 ishtar_menu.py:71
msgid "Deletion"
msgstr ""
-#: ishtar_menu.py:57 models.py:359 templates/ishtar/sheet_warehouse.html:37
-#: templates/ishtar/sheet_warehouse.html:68
+#: ishtar_menu.py:57 models.py:396 templates/ishtar/sheet_warehouse.html:42
+#: templates/ishtar/sheet_warehouse.html:87
msgid "Containers"
msgstr ""
-#: models.py:39
+#: models.py:40
msgid "Warehouse types"
msgstr ""
-#: models.py:58
+#: models.py:60
msgctxt "key for text search"
msgid "name"
msgstr ""
-#: models.py:62 models.py:323
+#: models.py:64 models.py:356
msgctxt "key for text search"
msgid "type"
msgstr ""
-#: models.py:81
+#: models.py:87
msgid "Documents"
msgstr ""
-#: models.py:83 models.py:353
+#: models.py:89 models.py:390
msgid "External ID"
msgstr ""
-#: models.py:85 models.py:355
+#: models.py:91 models.py:392
msgid "External ID is set automatically"
msgstr ""
-#: models.py:89
+#: models.py:95
msgid "Warehouses"
msgstr ""
-#: models.py:229
+#: models.py:257
msgid "Description"
msgstr ""
-#: models.py:234 models.py:235
+#: models.py:262 models.py:263
msgid "Collection"
msgstr ""
-#: models.py:244
+#: models.py:272
msgid "Warehouse division type"
msgstr ""
-#: models.py:245
+#: models.py:273
msgid "Warehouse division types"
msgstr ""
-#: models.py:267
+#: models.py:297
msgid "Length (mm)"
msgstr ""
-#: models.py:268
+#: models.py:298
msgid "Width (mm)"
msgstr ""
-#: models.py:269
+#: models.py:299
msgid "Height (mm)"
msgstr ""
-#: models.py:270
+#: models.py:300
msgid "Volume (l)"
msgstr ""
-#: models.py:275
+#: models.py:305
msgid "Container types"
msgstr ""
-#: models.py:306
+#: models.py:339
msgid "Location - index"
msgstr ""
-#: models.py:307
+#: models.py:340
msgid "Precise localisation"
msgstr ""
-#: models.py:308
+#: models.py:341
msgid "Type"
msgstr ""
-#: models.py:315
+#: models.py:348
msgctxt "key for text search"
msgid "location"
msgstr ""
-#: models.py:319
+#: models.py:352
msgctxt "key for text search"
msgid "responsible-warehouse"
msgstr ""
-#: models.py:327
+#: models.py:360
msgctxt "key for text search"
msgid "reference"
msgstr ""
-#: models.py:336
+#: models.py:373
msgid "Location (warehouse)"
msgstr ""
-#: models.py:343
+#: models.py:380
msgid "Container ref."
msgstr ""
-#: models.py:347
+#: models.py:384
msgid "Cached location"
msgstr ""
-#: models.py:349
+#: models.py:386
msgid "Cached division"
msgstr ""
-#: models.py:577
+#: models.py:623
msgid "Reference"
msgstr ""
-#: models.py:580
+#: models.py:626
msgid "Container localisation"
msgstr ""
-#: models.py:581
+#: models.py:627
msgid "Container localisations"
msgstr ""
@@ -325,39 +325,44 @@ msgstr ""
msgid "Content"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:42
+#: templates/ishtar/sheet_warehouse.html:47
msgid "Attached containers"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:46
+#: templates/ishtar/sheet_warehouse.html:51
msgid "Statistics"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:47
+#: templates/ishtar/sheet_warehouse.html:52
msgid "These numbers are updated hourly"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:49
+#: templates/ishtar/sheet_warehouse.html:54
msgid "Finds"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:51
+#: templates/ishtar/sheet_warehouse.html:56
msgid "Number of attached finds"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:53
+#: templates/ishtar/sheet_warehouse.html:58
msgid "Number of hosted finds"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:58
+#: templates/ishtar/sheet_warehouse.html:63
msgid "Finds by location in the warehouse"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:70
+#: templates/ishtar/sheet_warehouse.html:71
+#: templates/ishtar/sheet_warehouse.html:102
+msgid "Total"
+msgstr ""
+
+#: templates/ishtar/sheet_warehouse.html:89
msgid "Number of containers"
msgstr ""
-#: templates/ishtar/sheet_warehouse.html:75
+#: templates/ishtar/sheet_warehouse.html:94
msgid "Containers by location in the warehouse"
msgstr ""
@@ -373,26 +378,26 @@ msgid ""
"change divisions."
msgstr ""
-#: views.py:109
+#: views.py:120
msgid "Warehouse creation"
msgstr ""
-#: views.py:118
+#: views.py:129
msgid "Warehouse modification"
msgstr ""
-#: views.py:134
+#: views.py:145
msgid "Warehouse deletion"
msgstr ""
-#: views.py:150
+#: views.py:161
msgid "Container creation"
msgstr ""
-#: views.py:159
+#: views.py:170
msgid "Container modification"
msgstr ""
-#: views.py:174
+#: views.py:185
msgid "Container deletion"
msgstr ""
diff --git a/archaeological_warehouse/migrations/0023_auto_20181017_1642.py b/archaeological_warehouse/migrations/0023_auto_20181017_1642.py
new file mode 100644
index 000000000..340b1911e
--- /dev/null
+++ b/archaeological_warehouse/migrations/0023_auto_20181017_1642.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-10-17 16:42
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import virtualtime
+
+from ishtar_common.utils_migrations import reinit_last_modified
+
+
+def migrate_codes(apps, schema_editor):
+ models = ['Warehouse', 'Container', 'Collection']
+ reinit_last_modified(
+ apps, 'archaeological_warehouse', models
+ )
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_warehouse', '0022_container_cached_division'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='collection',
+ name='last_modified',
+ field=models.DateTimeField(default=virtualtime.virtual_datetime.now),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='last_modified',
+ field=models.DateTimeField(default=virtualtime.virtual_datetime.now),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='last_modified',
+ field=models.DateTimeField(default=virtualtime.virtual_datetime.now),
+ ),
+ migrations.RunPython(migrate_codes)
+ ]
diff --git a/archaeological_warehouse/migrations/0024_auto_20181017_1854.py b/archaeological_warehouse/migrations/0024_auto_20181017_1854.py
new file mode 100644
index 000000000..e17a4474e
--- /dev/null
+++ b/archaeological_warehouse/migrations/0024_auto_20181017_1854.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-10-17 18:54
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_warehouse', '0023_auto_20181017_1642'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='collection',
+ name='last_modified',
+ field=models.DateTimeField(auto_now=True),
+ ),
+ migrations.AlterField(
+ model_name='container',
+ name='last_modified',
+ field=models.DateTimeField(auto_now=True),
+ ),
+ migrations.AlterField(
+ model_name='warehouse',
+ name='last_modified',
+ field=models.DateTimeField(auto_now=True),
+ ),
+ ]
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index b1b6467ae..a40bfd321 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -30,7 +30,7 @@ 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, ExternalIdManager
+ ImageModel, DashboardFormItem, ExternalIdManager, ShortMenuItem
from ishtar_common.utils import cached_label_changed
@@ -45,7 +45,8 @@ post_save.connect(post_save_cache, sender=WarehouseType)
post_delete.connect(post_save_cache, sender=WarehouseType)
-class Warehouse(Address, DashboardFormItem, OwnPerms):
+class Warehouse(Address, DashboardFormItem, OwnPerms,
+ ShortMenuItem):
SLUG = 'warehouse'
SHOW_URL = 'show-warehouse'
TABLE_COLS = ['name', 'warehouse_type']
@@ -124,7 +125,12 @@ class Warehouse(Address, DashboardFormItem, OwnPerms):
@classmethod
def get_query_owns(cls, ishtaruser):
- return Q(person_in_charge__ishtaruser=ishtaruser)
+ return cls._construct_query_own(
+ '', cls._get_query_owns_dicts(ishtaruser))
+
+ @classmethod
+ def _get_query_owns_dicts(cls, ishtaruser):
+ return [{'person_in_charge__ishtaruser': ishtaruser}]
@property
def number_of_finds(self):
@@ -334,7 +340,7 @@ class Container(LightHistorizedItem, ImageModel):
'cached_division': _(u"Precise localisation"),
'container_type__label': _(u"Type")
}
- CACHED_LABELS = ['cached_label', 'cached_location', 'cached_division']
+ CACHED_LABELS = ['cached_division', 'cached_label', 'cached_location', ]
# alternative names of fields for searches
ALT_NAMES = {
@@ -399,8 +405,7 @@ class Container(LightHistorizedItem, ImageModel):
)
def __unicode__(self):
- lbl = u"{} ({})".format(self.reference, self.container_type)
- return lbl
+ return self.cached_label
def natural_key(self):
return (self.external_id, )
@@ -444,7 +449,10 @@ class Container(LightHistorizedItem, ImageModel):
@property
def precise_location(self):
- return self.location.name + u" - " + (self.cached_division or u"")
+ location = self.location.name
+ if self.cached_division:
+ location += u" " + self.cached_division
+ return location
def get_localisations(self):
"""
diff --git a/archaeological_warehouse/urls.py b/archaeological_warehouse/urls.py
index 26fe4698e..fa895b7c4 100644
--- a/archaeological_warehouse/urls.py
+++ b/archaeological_warehouse/urls.py
@@ -43,6 +43,9 @@ urlpatterns = [
name='get-container'),
url(r'get-warehouse/(?P<type>.+)?$', views.get_warehouse,
name='get-warehouse'),
+ url(r'get-warehouse-shortcut/(?P<type>.+)?$',
+ views.get_warehouse, name='get-warehouse-shortcut',
+ kwargs={'full': 'shortcut'}),
url(r'autocomplete-container/?$',
views.autocomplete_container, name='autocomplete-container'),
url(r'^show-container(?:/(?P<pk>.+))?/(?P<type>.+)?$', views.show_container,
@@ -65,19 +68,19 @@ urlpatterns = [
views.warehouse_modify, name='warehouse_modify'),
url(r'^container_search/(?P<step>.+)?$',
- check_rights(['view_container'])(
+ check_rights(['view_container', 'view_own_container'])(
views.container_search_wizard),
name='container_search'),
url(r'^container_creation/(?P<step>.+)?$',
- check_rights(['change_container'])(
+ check_rights(['add_container', 'add_own_container'])(
views.container_creation_wizard),
name='container_creation'),
url(r'^container_modification/(?P<step>.+)?$',
- check_rights(['change_container'])(
+ check_rights(['change_container', 'change_own_container'])(
views.container_modification_wizard),
name='container_modification'),
url(r'^container_deletion/(?P<step>.+)?$',
- check_rights(['change_container'])(
+ check_rights(['change_container', 'change_own_container'])(
views.container_deletion_wizard),
name='container_deletion'),
url(r'container-modify/(?P<pk>.+)/$',
diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py
index a1b1ffbe2..9b83fd829 100644
--- a/archaeological_warehouse/views.py
+++ b/archaeological_warehouse/views.py
@@ -68,19 +68,31 @@ def autocomplete_container(request):
return HttpResponse(content_type='text/plain')
if not request.GET.get('term'):
return HttpResponse(content_type='text/plain')
- q = request.GET.get('term')
+ term = request.GET.get('term')
+ limit = 15
query = Q()
- for q in q.split(' '):
- extra = Q(container_type__label__icontains=q) | \
- Q(container_type__reference__icontains=q) | \
- Q(reference__icontains=q) | \
- Q(location__name=q) | \
- Q(location__town=q)
+ for q in term.split(' '):
+ extra = Q(reference__iexact=q)
query = query & extra
- limit = 15
- containers = models.Container.objects.filter(query)[:limit]
- data = json.dumps([{'id': container.pk, 'value': unicode(container)}
- for container in containers])
+ containers = list(models.Container.objects.filter(
+ query).values('id', 'cached_label')[:limit])
+ limit = 15 - len(containers)
+ if limit > 0:
+ query = Q()
+ for q in term.split(' '):
+ extra = Q(container_type__label__icontains=q) | \
+ Q(container_type__reference__icontains=q) | \
+ Q(reference__icontains=q) | \
+ Q(location__name=q) | \
+ Q(location__town=q)
+ query = query & extra
+ containers += list(
+ models.Container.objects.filter(query).exclude(
+ pk__in=[c['id'] for c in containers]
+ ).values('id', 'cached_label')[:limit])
+ data = json.dumps(
+ [{'id': container['id'], 'value': container['cached_label']}
+ for container in containers])
return HttpResponse(data, content_type='text/plain')
warehouse_packaging_wizard = PackagingWizard.as_view([
@@ -133,7 +145,7 @@ warehouse_deletion_wizard = WarehouseDeletionWizard.as_view([
label=_(u"Warehouse deletion"),
url_name='warehouse_deletion',)
-container_search_wizard = ContainerWizard.as_view([
+container_search_wizard = ContainerSearch.as_view([
('selec-container_search', MainContainerFormSelection)],
label=_(u"Container search"),
url_name='container_search',