summaryrefslogtreecommitdiff
path: root/archaeological_files
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-03 17:59:35 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-12-03 17:59:35 +0100
commit5e1cafecaabecd5f6dd8d77f5e0ac70e785fdcc3 (patch)
treedb74975f02072b2ecd98acc6c27004117e63adb0 /archaeological_files
parente53dafe0aadc4f20bb05e875e982da65f9b01944 (diff)
downloadIshtar-5e1cafecaabecd5f6dd8d77f5e0ac70e785fdcc3.tar.bz2
Ishtar-5e1cafecaabecd5f6dd8d77f5e0ac70e785fdcc3.zip
Associate template to AdministrativActType - automatically associate the relevant template on administrativeact document generation (refs #1524)
Diffstat (limited to 'archaeological_files')
-rw-r--r--archaeological_files/forms.py22
-rw-r--r--archaeological_files/templates/ishtar/administrativeact_document.html4
-rw-r--r--archaeological_files/views.py12
3 files changed, 7 insertions, 31 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index 9affc0901..6bf2318bb 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -193,28 +193,6 @@ 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 cdb2b45be..8c08519de 100644
--- a/archaeological_files/templates/ishtar/administrativeact_document.html
+++ b/archaeological_files/templates/ishtar/administrativeact_document.html
@@ -12,10 +12,6 @@
<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 e55368e62..456926600 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)
- dct['template_form'] = DocumentGenerationAdminActForm(request.POST)
- if dct['search_form'].is_valid() and dct['template_form'].is_valid():
- doc = dct['template_form'].save(
- dct['search_form'].cleaned_data.get('pk'))
+ if dct['search_form'].is_valid():
+ try:
+ act_file = AdministrativeAct.objects.get(
+ pk=dct['search_form'].cleaned_data.get('pk'))
+ doc = act_file.publish()
+ except AdministrativeAct.DoesNotExist:
+ doc = None
if doc:
MIMES = {'odt':'application/vnd.oasis.opendocument.text',
'ods':'application/vnd.oasis.opendocument.spreadsheet'}
@@ -181,6 +184,5 @@ def file_administrativeactfile_document(request):
return response
else:
dct['search_form'] = AdministrativeActFileFormSelection()
- dct['template_form'] = DocumentGenerationAdminActForm()
return render_to_response('ishtar/administrativeact_document.html', dct,
context_instance=RequestContext(request))