Commit ddc2c6e3 authored by Hugo LEVY-FALK's avatar Hugo LEVY-FALK

Suppression des anciens templates lors de la mise à jour

parent 985a2f4a
......@@ -33,6 +33,7 @@ each.
from __future__ import unicode_literals
from dateutil.relativedelta import relativedelta
import os
from django.db import models
from django.db.models import Q, Max
......@@ -976,3 +977,34 @@ class DocumentTemplate(RevMixin, AclMixin, models.Model):
def __str__(self):
return str(
@receiver(models.signals.post_delete, sender=DocumentTemplate)
def auto_delete_file_on_delete(sender, instance, **kwargs):
Deletes file from filesystem
when corresponding `DocumentTemplate` object is deleted.
if instance.template:
if os.path.isfile(instance.template.path):
@receiver(models.signals.pre_save, sender=DocumentTemplate)
def auto_delete_file_on_change(sender, instance, **kwargs):
Deletes old file from filesystem
when corresponding `DocumentTemplate` object is updated
with new file.
if not
return False
old_file = DocumentTemplate.objects.get(
except DocumentTemplate.DoesNotExist:
return False
new_file = instance.template
if not old_file == new_file:
if os.path.isfile(old_file.path):
......@@ -51,7 +51,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% bootstrap_form_errors discount_form %}
{% endif %}
<form class="form" method="post">
<form class="form" method="post" enctype="multipart/form-data">
{% csrf_token %}
{% bootstrap_form factureform %}
{% if payment_method %}
......@@ -1062,7 +1062,10 @@ def add_document_template(request):
View used to add a document template.
document_template = DocumentTemplateForm(request.POST or None)
document_template = DocumentTemplateForm(
request.POST or None,
request.FILES or None,
if document_template.is_valid():
......@@ -1084,7 +1087,9 @@ def edit_document_template(request, document_template_instance, **_kwargs):
View used to edit a document_template.
document_template = DocumentTemplateForm(
request.POST or None, instance=document_template_instance)
request.POST or None,
request.FILES or None,
if document_template.is_valid():
if document_template.changed_data:
......@@ -333,6 +333,7 @@ copy_templates_files() {
mkdir -p media/templates/
cp cotisations/templates/cotisations/factures.tex media/templates/default_invoice.tex
cp cotisations/templates/cotisations/voucher.tex media/templates/default_voucher.tex
chown -R www-data:www-data media/templates/
echo "Copying LaTeX templates: Done"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment