diff --git a/printer/migrations/0008_auto_20181012_1242.py b/printer/migrations/0008_auto_20181012_1242.py index 4ac92372..916bcb87 100644 --- a/printer/migrations/0008_auto_20181012_1242.py +++ b/printer/migrations/0008_auto_20181012_1242.py @@ -18,6 +18,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='jobwithoptions', name='file', - field=models.FileField(storage=django.core.files.storage.FileSystemStorage(location='/var/impressions'), upload_to=printer.utils.user_printing_path, validators=[printer.validators.FileValidator(allowed_types=['application/pdf'], max_size=26214400)]), + field=models.FileField(storage=django.core.files.storage.FileSystemStorage(location='/var/impressions'), upload_to=printer.models.user_printing_path, validators=[printer.validators.FileValidator(allowed_types=['application/pdf'], max_size=26214400)]), ), ] diff --git a/printer/models.py b/printer/models.py index 4bcb98e4..349d2301 100644 --- a/printer/models.py +++ b/printer/models.py @@ -7,6 +7,9 @@ Author : Maxime Bombar . from __future__ import unicode_literals +from numpy.random import randint +import unidecode + from django.core.files.storage import FileSystemStorage from django.db import models @@ -43,10 +46,13 @@ import math - ```Job``` is the main model of a printer job. His parent is the ```user``` model. """ - def user_printing_path(instance, filename): + """ + Defines the path where will be uploaded the files + """ # File will be uploaded to MEDIA_ROOT/printings/user_/ - return 'printings/user_{0}/{1}'.format(instance.user.id, filename) + return 'printings/user_{0}/{1}'.format(instance.user.id, unidecode.unidecode(filename)) + class JobWithOptions(RevMixin, models.Model): """