diff options
Diffstat (limited to 'archaeological_files/forms.py')
| -rw-r--r-- | archaeological_files/forms.py | 26 | 
1 files changed, 23 insertions, 3 deletions
| diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index 2adc58ba1..9affc0901 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -33,7 +33,7 @@ from django.utils.translation import ugettext_lazy as _  from django.utils.safestring import mark_safe  from ishtar_common.models import Person, PersonType, Town, Organization, \ -                                 OrganizationType, valid_id, is_unique +                         OrganizationType, valid_id, is_unique, DocumentTemplate  from archaeological_operations.models import ActType, AdministrativeAct  import models  from ishtar_common.forms import FinalForm, FormSet, ClosingDateFormSelection, \ @@ -185,16 +185,36 @@ class FileFormPreventive(forms.Form):          self.fields['permit_type'].choices = models.PermitType.get_types()          self.fields['permit_type'].help_text = models.PermitType.get_help() -  class FinalFileClosingForm(FinalForm):      confirm_msg = " "      confirm_end_msg = _(u"Would you like to close this archaeological file?") -  class FinalFileDeleteForm(FinalForm):      confirm_msg = " "      confirm_end_msg = _(u"Would you like to delete this archaelogical file ?") +class DocumentGenerationAdminActForm(forms.Form): +    _associated_model = 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 AdministrativeActFileSelect(TableSelect):      associated_file__towns = get_town_field()      act_type = forms.ChoiceField(label=_("Act type"), choices=[]) | 
