summaryrefslogtreecommitdiff
path: root/archaeological_operations/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/forms.py')
-rw-r--r--archaeological_operations/forms.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 52507d748..e52fef927 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -33,7 +33,8 @@ from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
-from ishtar_common.models import valid_id, PersonType, Person, Town
+from ishtar_common.models import valid_id, PersonType, Person, Town, \
+ DocumentTemplate
from archaeological_files.models import File
import models
@@ -614,6 +615,28 @@ class FinalAdministrativeActDeleteForm(FinalForm):
confirm_msg = " "
confirm_end_msg = _(u"Would you like to delete this administrative act?")
+class DocumentGenerationAdminActForm(forms.Form):
+ _associated_model = models.AdministrativeAct
+ document_template = forms.ChoiceField(label=_("Template"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(DocumentGenerationAdminActForm, self).__init__(*args, **kwargs)
+ self.fields['document_template'].choices = DocumentTemplate.get_tuples(
+ dct={'associated_object_name':
+ 'archaeological_operations.models.AdministrativeAct'})
+
+ def save(self, object_pk):
+ try:
+ c_object = self._associated_model.objects.get(pk=object_pk)
+ except self._associated_model.DoesNotExist:
+ return
+ try:
+ template = DocumentTemplate.objects.get(
+ pk=self.cleaned_data.get('document_template'))
+ except DocumentTemplate.DoesNotExist:
+ return
+ return template.publish(c_object)
+
class GenerateDocForm(forms.Form):
form_label = _("Doc generation")
doc_generation = forms.ChoiceField(required=False, choices=[],