summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-11-30 13:20:53 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-11-30 13:20:53 +0100
commit8b666443667f92e014d70a4247c7885375bba610 (patch)
tree7e216f7c036ae568407d46359dea361f2a641098 /archaeological_finds
parent62cac0ec03a96d5f358148cf6dff2a21ccf20854 (diff)
downloadIshtar-8b666443667f92e014d70a4247c7885375bba610.tar.bz2
Ishtar-8b666443667f92e014d70a4247c7885375bba610.zip
Simple treatment form. Treatment listing. (refs #3365)
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/forms.py23
-rw-r--r--archaeological_finds/ishtar_menu.py36
-rw-r--r--archaeological_finds/models.py15
-rw-r--r--archaeological_finds/tests.py54
-rw-r--r--archaeological_finds/urls.py14
-rw-r--r--archaeological_finds/views.py15
-rw-r--r--archaeological_finds/wizards.py25
7 files changed, 163 insertions, 19 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 800fba34f..e25d52805 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -460,6 +460,8 @@ class UpstreamFindFormSelection(FindFormSelection):
def __init__(self, *args, **kwargs):
super(UpstreamFindFormSelection, self).__init__(*args, **kwargs)
self.fields['pk'].required = True
+ self.fields['resulting_pk'] = self.fields.pop('pk')
+
##############################################
# Source management for archaeological finds #
@@ -576,6 +578,18 @@ class FindBasketAddItemForm(forms.Form):
return basket
+class TreatmentFormSelection(forms.Form):
+ form_label = _("Treatment search")
+ associated_models = {'pk': models.Treatment}
+ currents = {'pk': models.Treatment}
+ pk = forms.IntegerField(
+ label="", required=False,
+ widget=widgets.JQueryJqGrid(
+ reverse_lazy('get-treatment'),
+ FindSelect, models.Treatment),
+ validators=[valid_id(models.Treatment)])
+
+
class BaseTreatmentForm(ManageOldType, SelectFindBasketForm):
form_label = _(u"Base treatment")
associated_models = {'treatment_type': models.TreatmentType,
@@ -606,12 +620,17 @@ class BaseTreatmentForm(ManageOldType, SelectFindBasketForm):
super(BaseTreatmentForm, self).__init__(*args, **kwargs)
self.fields['treatment_type'].choices = models.TreatmentType.get_types(
initial=self.init_data.get('treatment_type'),
- exclude=['packaging'])
+ dct={'upstream_is_many': False, 'downstream_is_many': False}
+ )
self.fields['treatment_type'].help_text = \
- models.TreatmentType.get_help(exclude=['packaging'])
+ models.TreatmentType.get_help(
+ dct={'upstream_is_many': False, 'downstream_is_many': False})
self.fields['basket'].required = False
self.fields['basket'].help_text = \
_(u"Leave it blank if you want to select a single item")
+ self.fields.keyOrder.pop(self.fields.keyOrder.index('basket'))
+ self.fields.keyOrder.insert(self.fields.keyOrder.index('description'),
+ 'basket')
def clean(self, *args, **kwargs):
try:
diff --git a/archaeological_finds/ishtar_menu.py b/archaeological_finds/ishtar_menu.py
index f638a60b2..1ab0cb575 100644
--- a/archaeological_finds/ishtar_menu.py
+++ b/archaeological_finds/ishtar_menu.py
@@ -46,11 +46,6 @@ MENU_SECTIONS = [
model=models.Find,
access_controls=['change_find',
'change_own_find']),
- # MenuItem(
- # 'treatment_creation', _(u"Add a treatment"),
- # model=models.Treatment,
- # access_controls=['change_find',
- # 'change_own_find']),
MenuItem(
'find_deletion', _(u"Deletion"),
model=models.Find,
@@ -99,6 +94,35 @@ MENU_SECTIONS = [
model=models.FindSource,
access_controls=['change_find',
'change_own_find']),
- ])
+ ]),
+ # MenuItem(
+ # 'treatment_creation', _(u"Add a treatment"),
+ # model=models.Treatment,
+ # access_controls=['change_find',
+ # 'change_own_find']),
+ SectionItem(
+ 'find_treatments', _(u"Treatments"),
+ childs=[
+ MenuItem('treatment_search',
+ _(u"Search"),
+ model=models.Treatment,
+ access_controls=['view_find',
+ 'view_own_find']),
+ MenuItem('treatment_creation',
+ _(u"Creation"),
+ model=models.Treatment,
+ access_controls=['change_find',
+ 'change_own_find']),
+ MenuItem('treatment_modification',
+ _(u"Modification"),
+ model=models.Treatment,
+ access_controls=['change_find',
+ 'change_own_find']),
+ MenuItem('treatment_deletion',
+ _(u"Deletion"),
+ model=models.Treatment,
+ access_controls=['change_find',
+ 'change_own_find']),
+ ]),
]))
]
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index b7637ba3b..a886485b5 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -793,6 +793,7 @@ post_delete.connect(post_save_cache, sender=TreatmentType)
class Treatment(BaseHistorizedItem, OwnPerms):
+ SHOW_URL = 'show-treatment'
external_id = models.CharField(_(u"External ID"), blank=True, null=True,
max_length=120)
container = models.ForeignKey(Container, verbose_name=_(u"Container"),
@@ -814,6 +815,16 @@ class Treatment(BaseHistorizedItem, OwnPerms):
start_date = models.DateField(_(u"Start date"), blank=True, null=True)
end_date = models.DateField(_(u"End date"), blank=True, null=True)
history = HistoricalRecords()
+ TABLE_COLS = ('treatment_type__label', 'person', 'start_date',
+ 'downstream_cached_label', 'upstream_cached_label')
+ EXTRA_REQUEST_KEYS = {
+ "downstream_cached_label": "downstream__cached_label",
+ "upstream_cached_label": "upstream__cached_label",
+ }
+ TABLE_COLS_LBL = {
+ "downstream_cached_label": _(u"Downstream find"),
+ "upstream_cached_label": _(u"Upstream find"),
+ }
class Meta:
verbose_name = _(u"Treatment")
@@ -844,10 +855,8 @@ class Treatment(BaseHistorizedItem, OwnPerms):
super(Treatment, self).save(*args, **kwargs)
if not is_new or not items:
return
- basket = None
if hasattr(items, "items"):
- basket = items
- items = basket.items.all()
+ items = items.items.all()
for item in items:
new = item.duplicate(user)
item.downstream_treatment = self
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index a0a9f0a8a..fdced4bd4 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -23,12 +23,14 @@ from django.test import TestCase
from ishtar_common.models import ImporterType, IshtarUser, ImporterColumn,\
FormaterType, ImportTarget
-from archaeological_finds import models
+from archaeological_finds import models, views
+from archaeological_warehouse.models import Warehouse, WarehouseType
from archaeological_context_records.tests import ImportContextRecordTest, \
ContextRecordInit
from ishtar_common import forms_common
+from ishtar_common.tests import WizardTest, WizardTestFormData as FormData
class ImportFindTest(ImportContextRecordTest):
@@ -216,3 +218,53 @@ class PackagingTest(FindInit, TestCase):
self.assertNotIn(
item, self.finds,
msg="Other basket have not been upgraded after packaging")
+
+
+class TreatmentWizardCreationTest(WizardTest, FindInit, TestCase):
+ fixtures = [settings.ROOT_PATH +
+ '../fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../ishtar_common/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_files/fixtures/initial_data.json',
+ settings.ROOT_PATH +
+ '../archaeological_operations/fixtures/initial_data-fr.json',
+ settings.ROOT_PATH +
+ '../archaeological_finds/fixtures/initial_data-fr.json',
+ settings.ROOT_PATH +
+ '../archaeological_warehouse/fixtures/initial_data-fr.json',
+ ]
+ url_name = 'treatment_creation'
+ wizard_name = 'treatment_wizard'
+ steps = views.treatment_wizard_steps
+ form_datas = [
+ FormData(
+ 'Move treament',
+ form_datas={
+ 'basetreatment-treatment_creation': {
+ 'treatment_type': 4, # move
+ 'person': 1, # doer
+ 'location': 1, # associated warehouse
+ },
+ 'selecfind-treatment_creation': {
+ 'pk': 1
+ }
+ },
+ ignored=('resultfind-treatment_creation',
+ 'resultfinds-treatment_creation'))
+ ]
+
+ def pre_wizard(self):
+ q = Warehouse.objects.filter(pk=1)
+ if not q.count():
+ warehouse = Warehouse.objects.create(
+ name="default", warehouse_type=WarehouseType.objects.all()[0])
+ warehouse.id = 1
+ warehouse.save()
+ self.treatment_number = models.Treatment.objects.count()
+ super(TreatmentWizardCreationTest, self).pre_wizard()
+
+ def post_wizard(self):
+ self.assertEqual(models.Treatment.objects.count(),
+ self.treatment_number + 1)
+ pass
diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py
index 17cc4028f..bbb123d09 100644
--- a/archaeological_finds/urls.py
+++ b/archaeological_finds/urls.py
@@ -17,7 +17,7 @@
# See the file COPYING for details.
-from django.conf.urls.defaults import *
+from django.conf.urls import *
from ishtar_common.wizards import check_rights
import views
@@ -89,7 +89,11 @@ urlpatterns = patterns(
check_rights(['change_find', 'change_own_find'])(
views.DeleteFindBasketView.as_view()), name='delete_findbasket'),
url(r'treatment_creation/(?P<step>.+)?$',
- views.treatment_creation_wizard, name='treatment_creation'),
+ check_rights(['change_find', 'change_own_find'])(
+ views.treatment_creation_wizard), name='treatment_creation'),
+ url(r'treatment_search/(?P<step>.+)?$',
+ check_rights(['view_find', 'view_own_find'])(
+ views.treatment_search_wizard), name='treatment_search'),
url(r'get-upstreamtreatment/(?P<type>.+)?$', views.get_upstreamtreatment,
name='get-upstreamtreatment'),
url(r'get-downstreamtreatment/(?P<type>.+)?$',
@@ -137,4 +141,10 @@ urlpatterns += patterns(
'show_find', name='show-historized-find'),
url(r'revert-find/(?P<pk>.+)/(?P<date>.+)$',
'revert_find', name='revert-find'),
+ url(r'get-treatment/(?P<type>.+)?$',
+ 'get_treatment', name='get-treatment'),
+ url(r'show-treatment(?:/(?P<pk>.+))?/(?P<type>.+)?$', 'show_treatment',
+ name=models.Treatment.SHOW_URL),
+ # url(r'get-treatment/(?P<type>.+)?$', 'get_treatment',
+ # name='get-treatment'),
)
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index 89babe9b7..f0c67c231 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -45,6 +45,9 @@ get_find = get_item(models.Find, 'get_find', 'find')
get_find_for_ope = get_item(models.Find, 'get_find', 'find',
own_table_cols=models.Find.TABLE_COLS_FOR_OPE)
+show_treatment = show_item(models.Treatment, 'treatment')
+get_treatment = get_item(models.Treatment, 'get_treatement', 'treatment')
+
show_findsource = show_item(models.FindSource, 'findsource')
get_findsource = get_item(models.FindSource, 'get_findsource', 'findsource')
@@ -282,12 +285,20 @@ get_downstreamtreatment = get_item(
models.FindDownstreamTreatments, 'get_downstreamtreatment',
'downtreatment')
-treatment_creation_wizard = TreatmentWizard.as_view([
+treatment_wizard_steps = [
('basetreatment-treatment_creation', BaseTreatmentForm),
('selecfind-treatment_creation', UpstreamFindFormSelection),
('resultfind-treatment_creation', ResultFindForm),
('resultfinds-treatment_creation', ResultFindFormSet),
- ('final-treatment_creation', FinalForm)],
+ ('final-treatment_creation', FinalForm)]
+
+treatment_search_wizard = SearchWizard.as_view([
+ ('general-treatment_search', TreatmentFormSelection)],
+ label=_(u"Treatment search"),
+ url_name='treatment_search',)
+
+treatment_creation_wizard = TreatmentWizard.as_view(
+ treatment_wizard_steps,
condition_dict={
'selecfind-treatment_creation':
check_not_exist('basetreatment-treatment_creation',
diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py
index f897969c4..e97c4518e 100644
--- a/archaeological_finds/wizards.py
+++ b/archaeological_finds/wizards.py
@@ -17,7 +17,7 @@
# See the file COPYING for details.
-from django.core.exceptions import ObjectDoesNotExist
+from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.utils.translation import ugettext_lazy as _
from ishtar_common.forms import reverse_lazy
@@ -85,14 +85,33 @@ class FindDeletionWizard(DeletionWizard):
class TreatmentWizard(Wizard):
model = models.Treatment
basket_step = 'basetreatment-treatment_creation'
+ saved_args = {"items": []}
- def get_form_kwargs(self, step):
- kwargs = super(TreatmentWizard, self).get_form_kwargs(step)
+ def get_form_kwargs(self, step, **kwargs):
+ kwargs = super(TreatmentWizard, self).get_form_kwargs(step, **kwargs)
if self.basket_step not in step:
return kwargs
kwargs['user'] = self.request.user
return kwargs
+ def get_extra_model(self, dct, form_list):
+ """
+ Remove basket ID to the result dict
+ """
+ dct = super(TreatmentWizard, self).get_extra_model(dct, form_list)
+ if 'resulting_pk' in dct:
+ try:
+ find = models.Find.objects.get(pk=dct.pop('resulting_pk'))
+ if 'own' in self.current_right \
+ and not find.is_own(dct['history_modifier']):
+ raise PermissionDenied
+ dct['items'] = [find]
+ except (models.Find.DoesNotExist):
+ raise PermissionDenied
+ if 'basket' in dct:
+ dct.pop('basket')
+ return dct
+
class FindSourceWizard(SourceWizard):
wizard_done_window = reverse_lazy('show-findsource')