summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_files/forms.py22
-rw-r--r--archaeological_files/templates/ishtar/administrativeact_document.html4
-rw-r--r--archaeological_files/views.py7
3 files changed, 31 insertions, 2 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index 4e0273e77..fcc62b39d 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -195,6 +195,28 @@ 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=[])
diff --git a/archaeological_files/templates/ishtar/administrativeact_document.html b/archaeological_files/templates/ishtar/administrativeact_document.html
index 8c08519de..cdb2b45be 100644
--- a/archaeological_files/templates/ishtar/administrativeact_document.html
+++ b/archaeological_files/templates/ishtar/administrativeact_document.html
@@ -12,6 +12,10 @@
<table>
{{ search_form.as_table }}
</table>
+<h4>{% trans "Choose the type of document" %}</h4>
+<table>
+{{ template_form }}
+</table>
<input type="submit" id="submit_form" name='validate' value="{% trans "Generate" %}"/>
</div>
</form>
diff --git a/archaeological_files/views.py b/archaeological_files/views.py
index 699335a56..3482b99c8 100644
--- a/archaeological_files/views.py
+++ b/archaeological_files/views.py
@@ -162,10 +162,13 @@ def file_administrativeactfile_document(request):
dct = {}
if request.POST:
dct['search_form'] = AdministrativeActFileFormSelection(request.POST)
- if dct['search_form'].is_valid():
+ dct['template_form'] = DocumentGenerationAdminActForm(request.POST)
+ if dct['search_form'].is_valid() and dct['template_form'].is_valid():
return generatedoc_administrativeactop(request,
- dct['search_form'].cleaned_data.get('pk'))
+ dct['search_form'].cleaned_data.get('pk'),
+ dct['template_form'].cleaned_data.get('document_template'))
else:
dct['search_form'] = AdministrativeActFileFormSelection()
+ dct['template_form'] = DocumentGenerationAdminActForm()
return render_to_response('ishtar/administrativeact_document.html', dct,
context_instance=RequestContext(request))