summaryrefslogtreecommitdiff
path: root/archaeological_context_records/wizards.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2012-10-20 21:52:43 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2012-10-20 21:52:43 +0200
commit5b8c7201eefa8b404afb0cb89b389fd3e8f92899 (patch)
tree1f1887c1153c40cd4323c482856e5f281ec1dc97 /archaeological_context_records/wizards.py
parent111fb54c79daf2a1bcfe624f103f02da650e8741 (diff)
downloadIshtar-5b8c7201eefa8b404afb0cb89b389fd3e8f92899.tar.bz2
Ishtar-5b8c7201eefa8b404afb0cb89b389fd3e8f92899.zip
Djangoization - Major refactoring (step 6)
Work on wizard, views and forms to dispatch logic in a more relevant way.
Diffstat (limited to 'archaeological_context_records/wizards.py')
-rw-r--r--archaeological_context_records/wizards.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/archaeological_context_records/wizards.py b/archaeological_context_records/wizards.py
new file mode 100644
index 000000000..b14272e16
--- /dev/null
+++ b/archaeological_context_records/wizards.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# See the file COPYING for details.
+
+from django.conf import settings
+from django.core.exceptions import ObjectDoesNotExist
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.utils.translation import ugettext_lazy as _
+
+from ishtar_common.wizards import Wizard, DeletionWizard, SourceWizard
+import models
+
+class RecordWizard(Wizard):
+ model = models.ContextRecord
+ edit = False
+
+ def get_current_operation(self, request, storage):
+ step = storage.get_current_step()
+ if not step:
+ return
+ if step.endswith('_creation'): # an operation has been selected
+ main_form_key = 'selec-' + self.url_name
+ try:
+ idx = int(self.session_get_value(request, storage,
+ main_form_key, 'operation_id'))
+ current_ope = models.Operation.objects.get(pk=idx)
+ return current_ope
+ except(TypeError, ValueError, ObjectDoesNotExist):
+ pass
+ current_cr = self.get_current_object(request, storage)
+ if current_cr:
+ return current_cr.parcel.operation
+
+ def get_template_context(self, request, storage, form=None):
+ """
+ Get the operation "reminder" on top of wizard forms
+ """
+ context = super(RecordWizard, self).get_template_context(request,
+ storage, form)
+ operation = self.get_current_operation(request, storage)
+ if not operation:
+ return context
+ items = []
+ if hasattr(operation, 'code_patriarche') and operation.code_patriarche:
+ items.append(unicode(operation.code_patriarche))
+ items.append("-".join((unicode(operation.year),
+ unicode(operation.operation_code))))
+ context['reminder'] = _("Current operation: ") + " - ".join(items)
+ return context
+
+ def get_form(self, request, storage, step=None, data=None, files=None):
+ """
+ Get associated operation
+ """
+ if data:
+ data = data.copy()
+ else:
+ data = {}
+ if not step:
+ step = self.determine_step(request, storage)
+ form = self.get_form_list(request, storage)[step]
+
+ general_form_key = 'general-' + self.url_name
+ if step.startswith('general-'):
+ if step.endswith('_creation'): # an operation has been selected
+ main_form_key = 'selec-' + self.url_name
+ try:
+ idx = int(self.session_get_value(request, storage,
+ main_form_key, 'operation_id'))
+ current_obj = models.Operation.objects.get(pk=idx)
+ data['operation'] = current_obj
+ except(TypeError, ValueError, ObjectDoesNotExist):
+ pass
+ else:
+ current_object = self.get_current_object(request, storage)
+ data['context_record'] = current_object
+ form = super(RecordWizard, self).get_form(request, storage, step, data,
+ files)
+ return form
+
+class RecordModifWizard(RecordWizard):
+ modification = True
+ model = models.ContextRecord
+
+class RecordDeletionWizard(DeletionWizard):
+ model = models.ContextRecord
+ fields = ['label', 'parcel', 'description', 'length', 'width', 'thickness',
+ 'depth', 'location', 'datings', 'units', 'has_furniture',
+ 'filling', 'interpretation', 'taq', 'taq_estimated', 'tpq',
+ 'tpq_estimated']
+
+class RecordSourceWizard(SourceWizard):
+ model = models.ContextRecordSource
+
+class RecordSourceDeletionWizard(DeletionWizard):
+ model = models.ContextRecordSource
+ fields = ['context_record', 'title', 'source_type', 'authors',]
+