summaryrefslogtreecommitdiff
path: root/archaeological_warehouse
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-12-18 18:34:43 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-12-18 18:34:43 +0100
commit2d7e9cd3d49e918f37a30352f35d1ad4c2ace769 (patch)
tree617d32c1aaa8c85a4782aecfa64d075f598af0dc /archaeological_warehouse
parentbd6026dfd15dc58958aff61ffac9ab08da0d49ee (diff)
downloadIshtar-2d7e9cd3d49e918f37a30352f35d1ad4c2ace769.tar.bz2
Ishtar-2d7e9cd3d49e918f37a30352f35d1ad4c2ace769.zip
Containers / Warehouse: actions, sheets and fixes.
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r--archaeological_warehouse/forms.py6
-rw-r--r--archaeological_warehouse/ishtar_menu.py21
-rw-r--r--archaeological_warehouse/models.py38
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_container.html21
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_container_pdf.html18
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_container_window.html3
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_warehouse.html21
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_warehouse_pdf.html18
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_warehouse_window.html3
-rw-r--r--archaeological_warehouse/urls.py5
-rw-r--r--archaeological_warehouse/views.py5
-rw-r--r--archaeological_warehouse/wizards.py14
12 files changed, 151 insertions, 22 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py
index 8e0328880..4ed8e7aed 100644
--- a/archaeological_warehouse/forms.py
+++ b/archaeological_warehouse/forms.py
@@ -200,7 +200,6 @@ class BasePackagingForm(SelectFindBasketForm):
'person': Person,
'location': models.Warehouse,
'basket': FindBasket}
- treatment_type = forms.IntegerField(label="", widget=forms.HiddenInput)
person = forms.IntegerField(
label=_(u"Packager"),
widget=widgets.JQueryAutoComplete(
@@ -210,11 +209,6 @@ class BasePackagingForm(SelectFindBasketForm):
start_date = forms.DateField(
label=_(u"Date"), required=False, widget=widgets.JQueryDate)
- def __init__(self, *args, **kwargs):
- super(BasePackagingForm, self).__init__(*args, **kwargs)
- self.fields['treatment_type'].initial = \
- TreatmentType.objects.get(txt_idx='packaging').pk
-
class FindPackagingFormSelection(FindMultipleFormSelection):
form_label = _(u"Packaged finds")
diff --git a/archaeological_warehouse/ishtar_menu.py b/archaeological_warehouse/ishtar_menu.py
index 4fe84e516..7f182d02b 100644
--- a/archaeological_warehouse/ishtar_menu.py
+++ b/archaeological_warehouse/ishtar_menu.py
@@ -37,16 +37,17 @@ MENU_SECTIONS = [
access_controls=['add_treatment', 'add_own_treatment']),
])),
(80, SectionItem('warehouse', _(u"Warehouse"),
- childs=[
- MenuItem('warehouse_creation', _(u"Creation"),
- model=models.Warehouse,
- access_controls=['add_warehouse',]),
- MenuItem('warehouse_modification', _(u"Modification"),
- model=models.Warehouse,
- access_controls=['change_warehouse',]),
- MenuItem('container_localisation', _(u"Container localisation"),
- model=models.Warehouse,
- access_controls=['change_warehouse',]),
+ profile_restriction='warehouse',
+ childs=[
+ MenuItem('warehouse_creation', _(u"Creation"),
+ model=models.Warehouse,
+ access_controls=['add_warehouse',]),
+ MenuItem('warehouse_modification', _(u"Modification"),
+ model=models.Warehouse,
+ access_controls=['change_warehouse',]),
+ MenuItem('container_localisation', _(u"Container localisation"),
+ model=models.Warehouse,
+ access_controls=['change_warehouse',]),
]))
]
"""
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 57068f374..0872df220 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -17,8 +17,11 @@
# See the file COPYING for details.
-from django.db.models.signals import post_save, post_delete
+import datetime
+
from django.contrib.gis.db import models
+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
from ishtar_common.models import GeneralType, \
@@ -35,6 +38,7 @@ post_delete.connect(post_save_cache, sender=WarehouseType)
class Warehouse(Address, OwnPerms):
+ SHOW_URL = 'show-warehouse'
name = models.CharField(_(u"Name"), max_length=200)
warehouse_type = models.ForeignKey(WarehouseType,
verbose_name=_(u"Warehouse type"))
@@ -63,11 +67,18 @@ class Warehouse(Address, OwnPerms):
def __unicode__(self):
return u"%s (%s)" % (self.name, unicode(self.warehouse_type))
+ @property
+ def associated_filename(self):
+ return datetime.date.today().strftime('%Y-%m-%d') + '-' + \
+ slugify(unicode(self))
+
class WarehouseDivision(GeneralType):
class Meta:
verbose_name = _(u"Warehouse division")
verbose_name_plural = _(u"Warehouse divisions")
+post_save.connect(post_save_cache, sender=WarehouseDivision)
+post_delete.connect(post_save_cache, sender=WarehouseDivision)
class WarehouseDivisionLink(models.Model):
@@ -80,6 +91,9 @@ class WarehouseDivisionLink(models.Model):
ordering = ('warehouse', 'order')
unique_together = ('warehouse', 'division')
+ def __unicode__(self):
+ return u"{} - {}".format(self.warehouse, self.division)
+
class ContainerType(GeneralType):
length = models.IntegerField(_(u"Length (mm)"), blank=True, null=True)
@@ -105,9 +119,11 @@ class Container(LightHistorizedItem):
'container_type': 'container_type__pk',
'reference': 'reference__icontains',
}
+ SHOW_URL = 'show-container'
# fields
- location = models.ForeignKey(Warehouse, verbose_name=_(u"Warehouse"))
+ location = models.ForeignKey(Warehouse, verbose_name=_(u"Warehouse"),
+ related_name='containers')
container_type = models.ForeignKey(ContainerType,
verbose_name=_("Container type"))
reference = models.CharField(_(u"Container ref."), max_length=40)
@@ -122,6 +138,23 @@ class Container(LightHistorizedItem):
unicode(self.location)))
return lbl
+ @property
+ def associated_filename(self):
+ return datetime.date.today().strftime('%Y-%m-%d') + '-' + \
+ "-".join([str(slugify(getattr(self, attr)))
+ for attr in ('location', 'container_type',
+ 'reference')])
+
+ @property
+ def precise_location(self):
+ location = unicode(self.location)
+ locas = [
+ u"{} {}".format(loca.division.division, loca.reference)
+ for loca in ContainerLocalisation.objects.filter(
+ container=self)
+ ]
+ return location + u" - " + u", ".join(locas)
+
class ContainerLocalisation(models.Model):
container = models.ForeignKey(Container, verbose_name=_(u"Container"))
@@ -133,6 +166,7 @@ class ContainerLocalisation(models.Model):
verbose_name = _(u"Container localisation")
verbose_name_plural = _(u"Container localisations")
unique_together = ('container', 'division')
+ ordering = ('container', 'division__order')
def __unicode__(self):
lbl = u" - ".join((unicode(self.container),
diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html
new file mode 100644
index 000000000..fd3c6510a
--- /dev/null
+++ b/archaeological_warehouse/templates/ishtar/sheet_container.html
@@ -0,0 +1,21 @@
+{% extends "ishtar/sheet.html" %}
+{% load i18n window_header window_field window_tables %}
+
+{% block head_title %}{% trans "Container" %}{% endblock %}
+
+{% block content %}
+{% window_nav item window_id 'show-container' '' '' '' previous next 1 %}
+
+<ul class='form-flex'>
+ {% field_li "Reference" item.reference %}
+ {% field_li "Container type" item.container_type %}
+</ul>
+{% field "Comment" item.comment "<pre>" "</pre>" %}
+{% field "Location" item.precise_location %}
+
+{% if item.finds.count %}
+<h4>{% trans "Content" %}</h4>
+{% dynamic_table_document finds 'finds' 'container' item.pk 'TABLE_COLS' output 'large' %}
+{% endif %}
+
+{% endblock %}
diff --git a/archaeological_warehouse/templates/ishtar/sheet_container_pdf.html b/archaeological_warehouse/templates/ishtar/sheet_container_pdf.html
new file mode 100644
index 000000000..5e4947cfa
--- /dev/null
+++ b/archaeological_warehouse/templates/ishtar/sheet_container_pdf.html
@@ -0,0 +1,18 @@
+{% extends "ishtar/sheet_container.html" %}
+{% block header %}
+<link rel="stylesheet" href="{{STATIC_URL}}/media/style_basic.css?ver={{VERSION}}" />
+{% endblock %}
+{% block main_head %}
+{{ block.super }}
+<div id="pdfheader">
+Ishtar &ndash; {{APP_NAME}} &ndash; {{item}}
+</div>
+{% endblock %}
+{%block head_sheet%}{%endblock%}
+{%block main_foot%}
+<div id="pdffooter">
+&ndash; <pdf:pagenumber/> &ndash;
+</div>
+</body>
+</html>
+{%endblock%}
diff --git a/archaeological_warehouse/templates/ishtar/sheet_container_window.html b/archaeological_warehouse/templates/ishtar/sheet_container_window.html
new file mode 100644
index 000000000..28aeaf9aa
--- /dev/null
+++ b/archaeological_warehouse/templates/ishtar/sheet_container_window.html
@@ -0,0 +1,3 @@
+{% extends "ishtar/sheet_container.html" %}
+{% block main_head %}{%endblock%}
+{% block main_foot %}{%endblock%}
diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html
new file mode 100644
index 000000000..6304dc3a5
--- /dev/null
+++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html
@@ -0,0 +1,21 @@
+{% extends "ishtar/sheet.html" %}
+{% load i18n window_header window_field window_tables %}
+
+{% block head_title %}{% trans "Warehouse" %}{% endblock %}
+
+{% block content %}
+{% window_nav item window_id 'show-warehouse' '' '' '' previous next 1 %}
+
+<ul class='form-flex'>
+ {% field_li "Name" item.name %}
+ {% field_li "Warehouse type" item.warehouse_type %}
+ {% field_li "Person in charge" item.person_in_charge %}
+</ul>
+{% field "Comment" item.comment "<pre>" "</pre>" %}
+
+{% if item.containers.count %}
+<h4>{% trans "Containers" %}</h4>
+{% dynamic_table_document '' 'containers' 'location' item.pk 'TABLE_COLS' output 'large' %}
+{% endif %}
+
+{% endblock %}
diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse_pdf.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse_pdf.html
new file mode 100644
index 000000000..260834ac6
--- /dev/null
+++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse_pdf.html
@@ -0,0 +1,18 @@
+{% extends "ishtar/sheet_warehouse.html" %}
+{% block header %}
+<link rel="stylesheet" href="{{STATIC_URL}}/media/style_basic.css?ver={{VERSION}}" />
+{% endblock %}
+{% block main_head %}
+{{ block.super }}
+<div id="pdfheader">
+Ishtar &ndash; {{APP_NAME}} &ndash; {{item}}
+</div>
+{% endblock %}
+{%block head_sheet%}{%endblock%}
+{%block main_foot%}
+<div id="pdffooter">
+&ndash; <pdf:pagenumber/> &ndash;
+</div>
+</body>
+</html>
+{%endblock%}
diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse_window.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse_window.html
new file mode 100644
index 000000000..e77c2c2a3
--- /dev/null
+++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse_window.html
@@ -0,0 +1,3 @@
+{% extends "ishtar/sheet_warehouse.html" %}
+{% block main_head %}{%endblock%}
+{% block main_foot %}{%endblock%}
diff --git a/archaeological_warehouse/urls.py b/archaeological_warehouse/urls.py
index ab1437a04..5c18200db 100644
--- a/archaeological_warehouse/urls.py
+++ b/archaeological_warehouse/urls.py
@@ -21,6 +21,7 @@ from django.conf.urls.defaults import *
from ishtar_common.wizards import check_rights
import views
+from archaeological_warehouse import models
# be carreful: each check_rights must be relevant with ishtar_menu
@@ -35,6 +36,8 @@ urlpatterns += patterns(
'archaeological_warehouse.views',
url(r'new-warehouse/(?P<parent_name>.+)?/$',
'new_warehouse', name='new-warehouse'),
+ url(r'^show-warehouse(?:/(?P<pk>.+))?/(?P<type>.+)?$', 'show_warehouse',
+ name=models.Warehouse.SHOW_URL),
url(r'autocomplete-warehouse/$', 'autocomplete_warehouse',
name='autocomplete-warehouse'),
url(r'new-container/(?P<parent_name>.+)?/$',
@@ -45,6 +48,8 @@ urlpatterns += patterns(
name='get-warehouse'),
url(r'autocomplete-container/?$',
'autocomplete_container', name='autocomplete-container'),
+ url(r'^show-container(?:/(?P<pk>.+))?/(?P<type>.+)?$', 'show_container',
+ name=models.Container.SHOW_URL),
url(r'^warehouse_creation/(?P<step>.+)?$',
check_rights(['add_warehouse'])(
views.warehouse_creation_wizard), name='warehouse_creation'),
diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py
index 1b9288ed1..5366aa53b 100644
--- a/archaeological_warehouse/views.py
+++ b/archaeological_warehouse/views.py
@@ -23,15 +23,18 @@ from django.db.models import Q
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
-from ishtar_common.views import get_item, new_item
import models
+
+from ishtar_common.views import get_item, new_item, show_item
from wizards import *
from ishtar_common.forms import FinalForm
from forms import *
get_container = get_item(models.Container, 'get_container', 'container')
+show_container = show_item(models.Container, 'container')
get_warehouse = get_item(models.Warehouse, 'get_warehouse', 'warehouse')
+show_warehouse = show_item(models.Warehouse, 'warehouse')
new_warehouse = new_item(models.Warehouse, WarehouseForm)
new_container = new_item(models.Container, ContainerForm)
diff --git a/archaeological_warehouse/wizards.py b/archaeological_warehouse/wizards.py
index 407a58ad6..cfe5be4d4 100644
--- a/archaeological_warehouse/wizards.py
+++ b/archaeological_warehouse/wizards.py
@@ -17,13 +17,12 @@
# See the file COPYING for details.
-from django.contrib.formtools.wizard.views import NamedUrlWizardView
from django.shortcuts import render_to_response
from django.template import RequestContext
from ishtar_common.wizards import Wizard
from archaeological_finds.wizards import TreatmentWizard
-from archaeological_finds.models import Treatment
+from archaeological_finds.models import Treatment, TreatmentType
import models
@@ -36,11 +35,20 @@ class PackagingWizard(TreatmentWizard):
dct = self.get_extra_model(dct, form_list)
obj = self.get_current_saved_object()
dct['location'] = dct['container'].location
- items = dct.pop('basket')
+ items = None
+ if 'items' in dct:
+ items = dct.pop('items')
+ if 'basket' in dct:
+ if not items:
+ items = dct.pop('basket')
+ else:
+ dct.pop('basket')
treatment = Treatment(**dct)
extra_args_for_new = {"container": dct['container']}
treatment.save(items=items, user=self.request.user,
extra_args_for_new=extra_args_for_new)
+ packaging = TreatmentType.objects.get(txt_idx='packaging')
+ treatment.treatment_types.add(packaging)
res = render_to_response('ishtar/wizard/wizard_done.html', {},
context_instance=RequestContext(self.request))
return return_object and (obj, res) or res