8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 20:33:11 +00:00

[Printer] Move user_printing_path from utils to models (avoid circular import)

This commit is contained in:
Maxime Bombar 2018-10-25 14:19:54 +02:00 committed by root
parent 5d85fd1b74
commit 6b3fa3b15a
2 changed files with 9 additions and 3 deletions

View file

@ -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)]),
),
]

View file

@ -7,6 +7,9 @@ Author : Maxime Bombar <bombar@crans.org>.
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_<id>/<filename>
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):
"""