summaryrefslogtreecommitdiff
path: root/ishtar_common/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-03 17:59:35 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-03 17:59:35 +0100
commitdfc53677e6fec7269e5383c410ac1cc7f259b7ea (patch)
treedb74975f02072b2ecd98acc6c27004117e63adb0 /ishtar_common/forms.py
parent586031c40bdc132b8069f3d644cb03ce22d16043 (diff)
downloadIshtar-dfc53677e6fec7269e5383c410ac1cc7f259b7ea.tar.bz2
Ishtar-dfc53677e6fec7269e5383c410ac1cc7f259b7ea.zip
Associate template to AdministrativActType - automatically associate the relevant template on administrativeact document generation (refs #1524)
Diffstat (limited to 'ishtar_common/forms.py')
-rw-r--r--ishtar_common/forms.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index e82a6e86d..5faa232fb 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -145,3 +145,29 @@ def get_form_selection(class_name, label, key, model, base_form, get_url,
return cleaned_data
attrs['clean'] = clean
return type(class_name, (forms.Form,), attrs)
+
+class DocumentGenerationForm(forms.Form):
+ """
+ Form to generate document by choosing the template
+ """
+ _associated_model = None # ex: AdministrativeAct
+ _associated_object_name = '' # ex: 'archaeological_operations.models.AdministrativeAct'
+ document_template = forms.ChoiceField(label=_("Template"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(DocumentGenerationForm, self).__init__(*args, **kwargs)
+ self.fields['document_template'].choices = \
+ models.DocumentTemplate.get_tuples(
+ dct={'associated_object_name':self._associated_object_name})
+
+ def save(self, object_pk):
+ try:
+ c_object = self._associated_model.objects.get(pk=object_pk)
+ except self._associated_model.DoesNotExist:
+ return
+ try:
+ template = models.DocumentTemplate.objects.get(
+ pk=self.cleaned_data.get('document_template'))
+ except models.DocumentTemplate.DoesNotExist:
+ return
+ return template.publish(c_object)