13 changed files with 161 additions and 2 deletions
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
from .models import TermsOfUse |
||||
|
||||
|
||||
def terms(request): |
||||
obj = TermsOfUse.objects.order_by('pk').last() |
||||
return {'terms': {'file': obj}} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 2.2.24 on 2021-09-02 15:03 |
||||
|
||||
import benevalibre.instance.validators |
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('instance', '0005_defaultrole_verbose_name'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.CreateModel( |
||||
name='TermsOfUse', |
||||
fields=[ |
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('file', models.FileField(help_text='Format attendu : pdf', upload_to='terms', validators=[benevalibre.instance.validators.validate_is_pdf], verbose_name='Charte')), |
||||
], |
||||
options={'verbose_name': "charte d'utilisation", 'verbose_name_plural': "chartes d'utilisation"}, |
||||
), |
||||
] |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
import os |
||||
|
||||
from django.core.exceptions import ValidationError |
||||
|
||||
import magic |
||||
|
||||
|
||||
def validate_is_pdf(file): |
||||
validation_error = ValidationError( |
||||
'Veuillez sélectionner un fichier au format PDF.' |
||||
) |
||||
valid_mime_types = ['application/pdf'] |
||||
file_mime_type = magic.from_buffer(file.read(1024), mime=True) |
||||
if file_mime_type not in valid_mime_types: |
||||
raise validation_error |
||||
|
||||
valid_file_extensions = ['.pdf'] |
||||
_, ext = os.path.splitext(file.name) |
||||
if ext.lower() not in valid_file_extensions: |
||||
raise validation_error |
Loading…
Reference in new issue