diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-12-23 13:13:40 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-12-23 13:13:40 +0100 |
commit | d5ef58137407b12c91fcf4db479dcd9662efd88d (patch) | |
tree | 30aba2cf351641d5fe1effb49c82a60612e5c742 /archaeological_operations/forms.py | |
parent | f567254115d33ab88ef331d21435166b9d5c813a (diff) | |
download | Ishtar-d5ef58137407b12c91fcf4db479dcd9662efd88d.tar.bz2 Ishtar-d5ef58137407b12c91fcf4db479dcd9662efd88d.zip |
Work on operation document generation
Diffstat (limited to 'archaeological_operations/forms.py')
-rw-r--r-- | archaeological_operations/forms.py | 25 |
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=[], |