|
@ -4,6 +4,7 @@ from django.db import models |
|
|
import seminar.models |
|
|
import seminar.models |
|
|
from django.db.models import Q |
|
|
from django.db.models import Q |
|
|
from django.utils import timezone |
|
|
from django.utils import timezone |
|
|
|
|
|
from django.utils.encoding import force_unicode |
|
|
|
|
|
|
|
|
from PIL import Image |
|
|
from PIL import Image |
|
|
import os |
|
|
import os |
|
@ -21,12 +22,29 @@ VIDITELNOST = ( |
|
|
(NIKDY, 'Nikdy'), |
|
|
(NIKDY, 'Nikdy'), |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def obrazek_filename(self, filename): |
|
|
|
|
|
return obrazek_filename_obecny(self, filename, "velky") |
|
|
|
|
|
|
|
|
|
|
|
def obrazek_filename_stredni(self, filename): |
|
|
|
|
|
return obrazek_filename_obecny(self, filename, "stredni") |
|
|
|
|
|
|
|
|
|
|
|
def obrazek_filename_maly(self, filename): |
|
|
|
|
|
return obrazek_filename_obecny(self, filename, "maly") |
|
|
|
|
|
|
|
|
|
|
|
def obrazek_filename_obecny(self, filename, typ): |
|
|
|
|
|
gal = self.galerie |
|
|
|
|
|
cesta = "" |
|
|
|
|
|
while(not gal.soustredeni): |
|
|
|
|
|
cesta = os.path.join(cesta, force_unicode(gal.nazev)) |
|
|
|
|
|
gal = gal.galerie_up |
|
|
|
|
|
return os.path.join('Galerie', force_unicode(gal.soustredeni), cesta, typ, force_unicode(self.nazev)) |
|
|
|
|
|
|
|
|
class Obrazek(models.Model): |
|
|
class Obrazek(models.Model): |
|
|
# TODO vkladat do slozek podle soustredeni |
|
|
# TODO vkladat do slozek podle soustredeni |
|
|
obrazek_velky = models.ImageField(upload_to='Galerie/%Y/%m/%d', |
|
|
obrazek_velky = models.ImageField(upload_to=obrazek_filename, |
|
|
help_text = "Lze vložit libovolně velký obrázek. Ideální je, aby alespoň jeden rozměr měl alespoň 500px.") |
|
|
help_text = "Lze vložit libovolně velký obrázek. Ideální je, aby alespoň jeden rozměr měl alespoň 500px.") |
|
|
obrazek_stredni = models.ImageField(upload_to='Galerie/%Y/%m/%d/stredni', null = True, editable = False) |
|
|
obrazek_stredni = models.ImageField(upload_to=obrazek_filename_stredni, null = True, editable = False) |
|
|
obrazek_maly = models.ImageField(upload_to='Galerie/%Y/%m/%d/male', null = True, editable = False) |
|
|
obrazek_maly = models.ImageField(upload_to=obrazek_filename_maly, null = True, editable = False) |
|
|
nazev = models.CharField('Název', max_length=50, blank = True, null = True) |
|
|
nazev = models.CharField('Název', max_length=50, blank = True, null = True) |
|
|
popis = models.TextField('Popis', blank = True, null = True) |
|
|
popis = models.TextField('Popis', blank = True, null = True) |
|
|
datum_vlozeni = models.DateTimeField('Datum vložení', auto_now_add = True) |
|
|
datum_vlozeni = models.DateTimeField('Datum vložení', auto_now_add = True) |
|
|