diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-12-02 14:51:09 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-12-02 14:59:06 +0100 | 
| commit | 6326867adb72dd9ded160769ef09e77b2e482784 (patch) | |
| tree | e7c44902b0dc74675ae3dda5658fc29c14ec71ba /archaeological_files/forms.py | |
| parent | de9fbce423f780a02b73a9e943995b0b7efb0008 (diff) | |
| download | Ishtar-6326867adb72dd9ded160769ef09e77b2e482784.tar.bz2 Ishtar-6326867adb72dd9ded160769ef09e77b2e482784.zip | |
Manage document template
 * ooo_replace: generate a document by mapping ooo variables with
   a given dict
 * DocumentTemplate model: store templates associated with a type
   of objects
 * get_values method: generate a dict of value from a model
 * new form/view to generate document from administrativ acts
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=[]) | 
