summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-13 21:07:50 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-13 21:07:50 +0200
commit41d9fc9697fd627d8fcb8af5ceee5fa130745252 (patch)
tree37647de999f544fc91635fbff2d89aae7a5ce671
parent95157d76a87f6b48761830cfa7daf9b630537b63 (diff)
downloadIshtar-41d9fc9697fd627d8fcb8af5ceee5fa130745252.tar.bz2
Ishtar-41d9fc9697fd627d8fcb8af5ceee5fa130745252.zip
Reminder of operation and context records for finds (closes #439)
-rw-r--r--ishtar/furnitures/forms_items.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/ishtar/furnitures/forms_items.py b/ishtar/furnitures/forms_items.py
index b3f360db3..f229ec4f2 100644
--- a/ishtar/furnitures/forms_items.py
+++ b/ishtar/furnitures/forms_items.py
@@ -25,6 +25,7 @@ import datetime
from django import forms
from django.core import validators
from django.core.exceptions import ObjectDoesNotExist
+from django.utils.safestring import mark_safe
from django.db.models import Max
from django.utils.translation import ugettext_lazy as _
@@ -40,6 +41,47 @@ from forms_context_records import RecordFormSelection
class ItemWizard(Wizard):
model = models.Item
+ def get_current_contextrecord(self, request, storage):
+ step = storage.get_current_step()
+ if not step:
+ return
+ if step.endswith('_creation'): # a context record has been selected
+ main_form_key = 'selecrecord-' + self.url_name
+ try:
+ idx = int(self.session_get_value(request, storage,
+ main_form_key, 'pk'))
+ current_cr = models.ContextRecord.objects.get(pk=idx)
+ return current_cr
+ except(TypeError, ValueError, ObjectDoesNotExist):
+ pass
+ current_item = self.get_current_object(request, storage)
+ if current_item:
+ base_items = current_item.base_items.all()
+ if base_items:
+ return base_items[0].context_record
+
+ def get_template_context(self, request, storage, form=None):
+ """
+ Get the operation and context record "reminder" on top of wizard forms
+ """
+ context = super(ItemWizard, self).get_template_context(request,
+ storage, form)
+ current_cr = self.get_current_contextrecord(request, storage)
+ if not current_cr:
+ return context
+ # TOCHANGE
+ operation = current_cr.parcel.operation
+ 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))))
+ reminder = unicode(_("Current operation: ")) + u" - ".join(items)
+ reminder += u"<br/>" + unicode(_("Current context record: "))\
+ + unicode(current_cr.label)
+ context['reminder'] = mark_safe(reminder)
+ return context
+
def get_extra_model(self, dct, request, storage, form_list):
dct = super(ItemWizard, self).get_extra_model(dct, request, storage,
form_list)