|
|
@ -12,15 +12,10 @@ from django.utils.text import slugify |
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
from django.core.cache import cache |
|
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
|
from django.utils.text import get_valid_filename |
|
|
|
from imagekit.models import ImageSpecField, ProcessedImageField |
|
|
|
from imagekit.processors import ResizeToFit, Transpose |
|
|
|
|
|
|
|
from PIL import Image |
|
|
|
import os |
|
|
|
#from functools import partial |
|
|
|
from cStringIO import StringIO |
|
|
|
from django.core.files.base import ContentFile |
|
|
|
|
|
|
|
from django_countries.fields import CountryField |
|
|
|
from solo.models import SingletonModel |
|
|
|
from taggit.managers import TaggableManager |
|
|
@ -29,6 +24,8 @@ from reversion import revisions as reversion |
|
|
|
|
|
|
|
from seminar.utils import roman |
|
|
|
|
|
|
|
from unidecode import unidecode |
|
|
|
|
|
|
|
|
|
|
|
class SeminarModelBase(models.Model): |
|
|
|
|
|
|
@ -557,28 +554,35 @@ class Reseni(SeminarModelBase): |
|
|
|
super(Reseni, self).save(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
# PrilohaReseni method |
|
|
|
# TODO vyresit partial, tak aby slo migrovat |
|
|
|
#def generate_filename(self, filename, directory): |
|
|
|
# Django 1.9 podporuje partial |
|
|
|
|
|
|
|
def generate_filename(self, filename): |
|
|
|
clean = filename.replace('/','-').replace('\0', '') |
|
|
|
def aux_generate_filename(self, filename): |
|
|
|
"""Pomocná funkce generující ošetřený název souboru v adresáři s datem""" |
|
|
|
clean = get_valid_filename( |
|
|
|
unidecode(filename.replace('/', '-').replace('\0', '')) |
|
|
|
) |
|
|
|
datedir = timezone.now().strftime('%Y-%m') |
|
|
|
fname = "%s_%s" % ( |
|
|
|
timezone.now().strftime('%Y-%m-%d-%H:%M'), |
|
|
|
clean) |
|
|
|
return os.path.join(settings.SEMINAR_RESENI_DIR, datedir, fname) |
|
|
|
return os.path.join(datedir, fname) |
|
|
|
|
|
|
|
# Django neumí jednoduše serializovat partial nebo třídu s __call__ |
|
|
|
# (https://docs.djangoproject.com/en/1.8/topics/migrations/), |
|
|
|
# neprojdou pak migrace. Takže rozlišení funkcí generujících názvy souboru |
|
|
|
# podle adresáře řešíme takto. |
|
|
|
|
|
|
|
|
|
|
|
def generate_filename_konfera(self, filename): |
|
|
|
clean = filename.replace('/','-').replace('\0', '') |
|
|
|
datedir = timezone.now().strftime('%Y-%m') |
|
|
|
fname = "%s_%s" % ( |
|
|
|
timezone.now().strftime('%Y-%m-%d-%H:%M'), |
|
|
|
clean) |
|
|
|
return os.path.join(settings.SEMINAR_KONFERY_DIR, datedir, fname) |
|
|
|
# TODO vyresit partial tak, aby slo migrovat |
|
|
|
# return os.path.join(directory, datedir, fname) |
|
|
|
return os.path.join( |
|
|
|
settings.SEMINAR_KONFERY_DIR, |
|
|
|
aux_generate_filename(self, filename) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def generate_filename(self, filename): |
|
|
|
return os.path.join( |
|
|
|
settings.SEMINAR_RESENI_DIR, |
|
|
|
aux_generate_filename(self, filename) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@reversion.register(ignore_duplicate_revisions=True) |
|
|
|