mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Suppression des anciens templates lors de la mise à jour
This commit is contained in:
parent
985a2f4a52
commit
ddc2c6e380
4 changed files with 41 additions and 3 deletions
|
@ -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(self.name)
|
||||
|
||||
@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):
|
||||
os.remove(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 instance.pk:
|
||||
return False
|
||||
|
||||
try:
|
||||
old_file = DocumentTemplate.objects.get(pk=instance.pk).template
|
||||
except DocumentTemplate.DoesNotExist:
|
||||
return False
|
||||
|
||||
new_file = instance.template
|
||||
if not old_file == new_file:
|
||||
if os.path.isfile(old_file.path):
|
||||
os.remove(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():
|
||||
document_template.save()
|
||||
messages.success(
|
||||
|
@ -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,
|
||||
instance=document_template_instance)
|
||||
if document_template.is_valid():
|
||||
if document_template.changed_data:
|
||||
document_template.save()
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue