diff --git a/cotisations/admin.py b/cotisations/admin.py index 9eb0f071..4b47ccc8 100644 --- a/cotisations/admin.py +++ b/cotisations/admin.py @@ -30,7 +30,7 @@ from django.contrib import admin from reversion.admin import VersionAdmin from .models import Facture, Article, Banque, Paiement, Cotisation, Vente -from .models import CustomInvoice, CostEstimate, DocumentTemplate +from .models import CustomInvoice, CostEstimate class FactureAdmin(VersionAdmin): @@ -74,11 +74,6 @@ class CotisationAdmin(VersionAdmin): pass -class DocumentTemplateAdmin(VersionAdmin): - """Admin class for DocumentTemplate""" - pass - - admin.site.register(Facture, FactureAdmin) admin.site.register(Article, ArticleAdmin) admin.site.register(Banque, BanqueAdmin) @@ -87,4 +82,3 @@ admin.site.register(Vente, VenteAdmin) admin.site.register(Cotisation, CotisationAdmin) admin.site.register(CustomInvoice, CustomInvoiceAdmin) admin.site.register(CostEstimate, CostEstimateAdmin) -admin.site.register(DocumentTemplate, DocumentTemplateAdmin) diff --git a/cotisations/forms.py b/cotisations/forms.py index 21f8f42f..3f99382b 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -48,7 +48,7 @@ from re2o.field_permissions import FieldPermissionFormMixin from re2o.mixins import FormRevMixin from .models import ( Article, Paiement, Facture, Banque, - CustomInvoice, Vente, CostEstimate, DocumentTemplate + CustomInvoice, Vente, CostEstimate, ) from .payment_methods import balance @@ -316,37 +316,3 @@ class RechargeForm(FormRevMixin, Form): } ) return self.cleaned_data - - -class DocumentTemplateForm(FormRevMixin, ModelForm): - """ - Form used to create a document template. - """ - class Meta: - model = DocumentTemplate - fields = '__all__' - - def __init__(self, *args, **kwargs): - prefix = kwargs.pop('prefix', self.Meta.model.__name__) - super(DocumentTemplateForm, self).__init__( - *args, prefix=prefix, **kwargs) - - -class DelDocumentTemplateForm(FormRevMixin, Form): - """ - Form used to delete one or more document templatess. - The use must choose the one to delete by checking the boxes. - """ - document_templates = forms.ModelMultipleChoiceField( - queryset=DocumentTemplate.objects.none(), - label=_("Available document templates"), - widget=forms.CheckboxSelectMultiple - ) - - def __init__(self, *args, **kwargs): - instances = kwargs.pop('instances', None) - super(DelDocumentTemplateForm, self).__init__(*args, **kwargs) - if instances: - self.fields['document_templates'].queryset = instances - else: - self.fields['document_templates'].queryset = Banque.objects.all() diff --git a/cotisations/migrations/0039_documenttemplate.py b/cotisations/migrations/0039_documenttemplate.py deleted file mode 100644 index ee93da92..00000000 --- a/cotisations/migrations/0039_documenttemplate.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2019-01-03 16:48 -from __future__ import unicode_literals - -from django.db import migrations, models -import re2o.mixins - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0038_auto_20181231_1657'), - ] - - operations = [ - migrations.CreateModel( - name='DocumentTemplate', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('template', models.FileField(upload_to='templates/', verbose_name='template')), - ('name', models.CharField(max_length=255, verbose_name='name')), - ], - options={ - 'verbose_name_plural': 'document templates', - 'verbose_name': 'document template', - }, - bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model), - ), - ] diff --git a/cotisations/migrations/0040_auto_20190120_1708.py b/cotisations/migrations/0040_auto_20190120_1708.py deleted file mode 100644 index b7f5b279..00000000 --- a/cotisations/migrations/0040_auto_20190120_1708.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2019-01-20 23:08 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('cotisations', '0039_documenttemplate'), - ] - - operations = [ - migrations.AlterField( - model_name='documenttemplate', - name='name', - field=models.CharField(max_length=125, unique=True, verbose_name='name'), - ), - ] diff --git a/cotisations/models.py b/cotisations/models.py index 88407d33..7346a634 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -33,7 +33,6 @@ 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 @@ -956,56 +955,3 @@ def cotisation_post_delete(**_kwargs): """ regen('mac_ip_list') regen('mailing') - - -class DocumentTemplate(RevMixin, AclMixin, models.Model): - """Represent a template in order to create documents such as invoice or - subscription voucher. - """ - template = models.FileField( - upload_to='templates/', - verbose_name=_('template') - ) - name = models.CharField( - max_length=125, - verbose_name=_('name'), - unique=True - ) - - class Meta: - verbose_name = _("document template") - verbose_name_plural = _("document templates") - - 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) diff --git a/cotisations/templates/cotisations/facture.html b/cotisations/templates/cotisations/facture.html index 5dddb305..65b05199 100644 --- a/cotisations/templates/cotisations/facture.html +++ b/cotisations/templates/cotisations/facture.html @@ -51,7 +51,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% bootstrap_form_errors discount_form %} {% endif %} -