galerie | ukladani fotek podle soustredeni
This commit is contained in:
parent
89e609f5e4
commit
b1cf79271f
2 changed files with 22 additions and 4 deletions
|
@ -4,6 +4,7 @@ from django.db import models
|
|||
import seminar.models
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_unicode
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
|
@ -21,12 +22,29 @@ VIDITELNOST = (
|
|||
(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):
|
||||
# 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.")
|
||||
obrazek_stredni = models.ImageField(upload_to='Galerie/%Y/%m/%d/stredni', null = True, editable = False)
|
||||
obrazek_maly = models.ImageField(upload_to='Galerie/%Y/%m/%d/male', null = True, editable = False)
|
||||
obrazek_stredni = models.ImageField(upload_to=obrazek_filename_stredni, 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)
|
||||
popis = models.TextField('Popis', blank = True, null = True)
|
||||
datum_vlozeni = models.DateTimeField('Datum vložení', auto_now_add = True)
|
||||
|
|
|
@ -145,7 +145,7 @@ def new_galerie(request, galerie, soustredeni):
|
|||
for obr in request.FILES.getlist('obr'):
|
||||
o = Obrazek()
|
||||
o.obrazek_velky = obr
|
||||
o.nazev = str(gal) + "/" + str(obr)
|
||||
o.nazev = str(obr)
|
||||
o.datum = datetime.now() #TODO vycist z EXIFU
|
||||
o.galerie = gal
|
||||
o.save()
|
||||
|
|
Loading…
Reference in a new issue