summaryrefslogtreecommitdiff
path: root/archaeological_finds/wizards.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/wizards.py')
-rw-r--r--archaeological_finds/wizards.py138
1 files changed, 133 insertions, 5 deletions
diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py
index f897969c4..dab4a76d4 100644
--- a/archaeological_finds/wizards.py
+++ b/archaeological_finds/wizards.py
@@ -17,11 +17,15 @@
# 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
from ishtar_common.wizards import Wizard, DeletionWizard, SourceWizard
+from archaeological_operations.wizards import OperationAdministrativeActWizard
+
+from archaeological_operations.models import AdministrativeAct
+from archaeological_context_records.models import ContextRecord
import models
@@ -37,7 +41,7 @@ class FindWizard(Wizard):
main_form_key = 'selecrecord-' + self.url_name
try:
idx = int(self.session_get_value(main_form_key, 'pk'))
- current_cr = models.ContextRecord.objects.get(pk=idx)
+ current_cr = ContextRecord.objects.get(pk=idx)
return current_cr
except(TypeError, ValueError, ObjectDoesNotExist):
pass
@@ -63,7 +67,7 @@ class FindWizard(Wizard):
def get_extra_model(self, dct, form_list):
dct = super(FindWizard, self).get_extra_model(dct, form_list)
dct['order'] = 1
- if 'pk' in dct and type(dct['pk']) == models.ContextRecord:
+ if 'pk' in dct and type(dct['pk']) == ContextRecord:
dct['base_finds__context_record'] = dct.pop('pk')
return dct
@@ -84,15 +88,125 @@ class FindDeletionWizard(DeletionWizard):
class TreatmentWizard(Wizard):
model = models.Treatment
+ wizard_done_window = reverse_lazy('show-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:
+ basket = dct.pop('basket')
+ if basket.user.pk != dct['history_modifier'].pk:
+ raise PermissionDenied
+ dct['items'] = list(basket.items.all())
+ return dct
+
+
+class TreatmentModificationWizard(TreatmentWizard):
+ modification = True
+
+
+class TreatmentDeletionWizard(DeletionWizard):
+ model = models.Treatment
+ fields = ['label', 'other_reference', 'year', 'index',
+ 'treatment_types', 'location', 'person', 'organization',
+ 'external_id', 'comment', 'description',
+ 'goal', 'start_date', 'end_date', 'container']
+
+
+class TreatmentAdministrativeActWizard(OperationAdministrativeActWizard):
+ model = models.Treatment
+ current_obj_slug = 'administrativeacttreatment'
+ ref_object_key = 'treatment'
+
+ def get_reminder(self):
+ return
+
+
+class TreatmentEditAdministrativeActWizard(TreatmentAdministrativeActWizard):
+ model = AdministrativeAct
+ edit = True
+
+ def get_associated_item(self, dct):
+ return self.get_current_object().treatment
+
+
+class TreatmentFileWizard(Wizard):
+ model = models.TreatmentFile
+ wizard_done_window = reverse_lazy('show-treatmentfile')
+
+
+class TreatmentFileModificationWizard(TreatmentFileWizard):
+ modification = True
+
+
+class TreatmentFileDeletionWizard(DeletionWizard):
+ model = models.TreatmentFile
+ fields = ['name', 'internal_reference', 'external_id', 'year',
+ 'index', 'type', 'in_charge', 'reception_date',
+ 'creation_date', 'end_date', 'comment']
+
+
+class TreatmentFileAdministrativeActWizard(
+ OperationAdministrativeActWizard):
+ model = models.TreatmentFile
+ current_obj_slug = 'administrativeacttreatmentfile'
+ ref_object_key = 'treatment_file'
+
+ def get_reminder(self):
+ form_key = 'selec-' + self.url_name
+ if self.url_name.endswith('_administrativeactop'):
+ # modification and deletion are suffixed with '_modification'
+ # and '_deletion' so it is creation
+ pk = self.session_get_value(form_key, "pk")
+ try:
+ return (
+ (_(u"Treatment request"),
+ unicode(models.TreatmentFile.objects.get(pk=pk))),
+ )
+ except models.TreatmentFile.DoesNotExist:
+ return
+ else:
+ admin_id = self.session_get_value(form_key, "pk")
+ try:
+ admin = AdministrativeAct.objects.get(pk=admin_id)
+ if not admin.operation:
+ return
+ return (
+ (_(u"Operation"), unicode(admin.operation)),
+ )
+ except AdministrativeAct.DoesNotExist:
+ return
+ return
+
+
+class TreatmentFileEditAdministrativeActWizard(
+ TreatmentFileAdministrativeActWizard):
+ model = AdministrativeAct
+ edit = True
+
+ def get_associated_item(self, dct):
+ return self.get_current_object().treatment_file
+
class FindSourceWizard(SourceWizard):
wizard_done_window = reverse_lazy('show-findsource')
@@ -106,3 +220,17 @@ class FindSourceDeletionWizard(DeletionWizard):
class TreatmentSourceWizard(SourceWizard):
model = models.TreatmentSource
+
+
+class TreatmentSourceDeletionWizard(DeletionWizard):
+ model = models.TreatmentSource
+ fields = ['treatment', 'title', 'source_type', 'authors']
+
+
+class TreatmentFileSourceWizard(SourceWizard):
+ model = models.TreatmentFileSource
+
+
+class TreatmentFileSourceDeletionWizard(DeletionWizard):
+ model = models.TreatmentFileSource
+ fields = ['treatment_file', 'title', 'source_type', 'authors']