summaryrefslogtreecommitdiff
path: root/ishtar_common/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-14 23:52:13 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-14 23:52:13 +0100
commitccb709bfa5d06737e70c171202ba85aa5410194c (patch)
treee702a5e335c4366a1e27499a4db51e31b7f5c7b7 /ishtar_common/forms.py
parent9b3ede3e6d5d2b076975c188454a39c2b45d155d (diff)
parent1a1040243a10366b01b9bc2c4d3140f2fbd321e4 (diff)
downloadIshtar-ccb709bfa5d06737e70c171202ba85aa5410194c.tar.bz2
Ishtar-ccb709bfa5d06737e70c171202ba85aa5410194c.zip
Merge branch 'master' of lysithea.proxience.net:/home/proxience/git/ishtar
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)