diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-12-17 01:53:53 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-12-17 01:53:53 +0100 |
commit | 758ee42b4970372d38d620f80c51854abc64a69f (patch) | |
tree | 10b2770b19fde76764d3a028fd01ae3ebe8176f5 /archaeological_operations | |
parent | 7a8588afd998504e4fabf9614d03054b424fe3e7 (diff) | |
download | Ishtar-758ee42b4970372d38d620f80c51854abc64a69f.tar.bz2 Ishtar-758ee42b4970372d38d620f80c51854abc64a69f.zip |
Choose document to generate at the end of create/modif process
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/forms.py | 9 | ||||
-rw-r--r-- | archaeological_operations/models.py | 11 | ||||
-rw-r--r-- | archaeological_operations/urls.py | 2 | ||||
-rw-r--r-- | archaeological_operations/views.py | 4 | ||||
-rw-r--r-- | archaeological_operations/wizards.py | 5 |
5 files changed, 22 insertions, 9 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 955b2f825..0cef41125 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -615,5 +615,12 @@ class FinalAdministrativeActDeleteForm(FinalForm): class GenerateDocForm(forms.Form): form_label = _("Doc generation") - doc_generation = forms.BooleanField(required=False, + doc_generation = forms.ChoiceField(required=False, choices=[], label=_(u"Generate the associated doc?")) + def __init__(self, *args, **kwargs): + choices = [] + if 'choices' in kwargs: + choices = kwargs.pop('choices') + super(GenerateDocForm, self).__init__(*args, **kwargs) + self.fields['doc_generation'].choices = [('', u'-'*9)] + \ + [(choice.pk , unicode(choice)) for choice in choices] diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 125a5d7d1..be09f9923 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -425,11 +425,16 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter): filename += u"-" + self.signature_date.strftime('%Y%m%d') return filename - def publish(self): + def publish(self, template_pk=None): if not self.act_type.associated_template.count(): return - # for administrative_act only one associated_template - template = self.act_type.associated_template.all()[0] + if not template_pk: + template = self.act_type.associated_template.all()[0] + else: + q = self.act_type.associated_template.filter(pk=template_pk) + if not q.count(): + return + template = q.all()[0] return template.publish(self) class Parcel(LightHistorizedItem): diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py index 4453b10ed..8ae835292 100644 --- a/archaeological_operations/urls.py +++ b/archaeological_operations/urls.py @@ -71,7 +71,7 @@ urlpatterns += patterns('archaeological_operations.views', 'show_operation', name='show-historized-operation'), url(r'get-administrativeactop/(?P<type>.+)?$', 'get_administrativeactop', name='get-administrativeactop'), - url(r'generatedoc-administrativeactop/(?P<pk>.+)?$', + url(r'generatedoc-administrativeactop/(?P<pk>.+)?/(?P<template_pk>.+)?$', 'generatedoc_administrativeactop', name='generatedoc-administrativeactop'), url(r'get-operationsource/(?P<type>.+)?$', diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index c899b1c4d..183c80b83 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -260,7 +260,7 @@ operation_administrativeactop_deletion_wizard = \ label=_(u"Operation: administrative act deletion"), url_name='operation_administrativeactop_deletion',) -def generatedoc_administrativeactop(request, pk): +def generatedoc_administrativeactop(request, pk, template_pk=None): if (not request.user.has_perm('ishtar_common.view_operation', models.Operation) and not request.user.has_perm('ishtar_common.view_own_operation', @@ -268,7 +268,7 @@ def generatedoc_administrativeactop(request, pk): return HttpResponse(mimetype='text/plain') try: act_file = models.AdministrativeAct.objects.get(pk=pk) - doc = act_file.publish() + doc = act_file.publish(template_pk) except models.AdministrativeAct.DoesNotExist: doc = None if doc: diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 86af26351..a61452733 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -281,7 +281,8 @@ class OperationAdministrativeActWizard(OperationWizard): except models.ActType.DoesNotExist: pass if act_type and act_type.associated_template.count(): - context['extra_form'] = GenerateDocForm() + context['extra_form'] = GenerateDocForm( + choices=act_type.associated_template.all()) return context def get_associated_item(self, dct): @@ -323,7 +324,7 @@ class OperationAdministrativeActWizard(OperationWizard): if level == len(keys): # the whole tree as been traversed # redirect to the generated doc dct['redirect'] = reverse('generatedoc-administrativeactop', - args=[admact.pk]) + args=[admact.pk, r[0]]) res = render_to_response('ishtar/wizard/wizard_done.html', dct, context_instance=RequestContext(self.request)) |