|
@ -1,19 +1,12 @@ |
|
|
# coding: utf-8 |
|
|
# coding: utf-8 |
|
|
|
|
|
|
|
|
from django.db import models |
|
|
from django.db import models |
|
|
import seminar.models |
|
|
#from django.db.models import Q |
|
|
from django.db.models import Q |
|
|
|
|
|
from django.utils import timezone |
|
|
|
|
|
from django.utils.encoding import force_unicode |
|
|
from django.utils.encoding import force_unicode |
|
|
from imagekit.models import ImageSpecField |
|
|
from imagekit.models import ImageSpecField |
|
|
from imagekit.processors import ResizeToFit, Transpose |
|
|
from imagekit.processors import ResizeToFit, Transpose |
|
|
|
|
|
|
|
|
from PIL import Image |
|
|
|
|
|
from PIL.ExifTags import TAGS |
|
|
|
|
|
import os |
|
|
import os |
|
|
from cStringIO import StringIO |
|
|
|
|
|
from django.core.files.base import ContentFile |
|
|
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
|
|
|
from seminar.models import Soustredeni |
|
|
from seminar.models import Soustredeni |
|
|
|
|
|
|
|
@ -26,14 +19,6 @@ VIDITELNOST = ( |
|
|
(NIKDY, 'Nikdy'), |
|
|
(NIKDY, 'Nikdy'), |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def get_exif(fn): |
|
|
|
|
|
ret = {} |
|
|
|
|
|
info = fn._getexif() |
|
|
|
|
|
for tag, value in info.items(): |
|
|
|
|
|
decoded = TAGS.get(tag, tag) |
|
|
|
|
|
ret[decoded] = value |
|
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
|
|
|
# tyhle funkce jsou tady jen kvůli starým migracím, které se na ně odkazují |
|
|
# tyhle funkce jsou tady jen kvůli starým migracím, které se na ně odkazují |
|
|
# až se ty migrace někdy squashnou, tak by mělo být možné funkce smazat |
|
|
# až se ty migrace někdy squashnou, tak by mělo být možné funkce smazat |
|
|
def obrazek_filename_maly(): |
|
|
def obrazek_filename_maly(): |
|
@ -63,23 +48,14 @@ class Obrazek(models.Model): |
|
|
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) |
|
|
datum = models.DateTimeField('Datum pořízení fotografie', blank = True, null = True) |
|
|
|
|
|
galerie = models.ForeignKey('Galerie', blank=True, null=True) |
|
|
galerie = models.ForeignKey('Galerie', blank=True, null=True) |
|
|
poradi = models.IntegerField('Pořadí', blank = True, null = True) |
|
|
poradi = models.IntegerField('Pořadí', blank = True, null = True) |
|
|
def __unicode__(self): |
|
|
def __unicode__(self): |
|
|
return self.nazev + " -- " + unicode(self.obrazek_velky.name) + " (" + str(self.datum) + ")" |
|
|
return self.nazev + " -- " + unicode(self.obrazek_velky.name) |
|
|
class Meta: |
|
|
class Meta: |
|
|
verbose_name = 'Obrázek' |
|
|
verbose_name = 'Obrázek' |
|
|
verbose_name_plural = 'Obrázky' |
|
|
verbose_name_plural = 'Obrázky' |
|
|
ordering = ['datum'] |
|
|
ordering = ['nazev'] |
|
|
def save(self): |
|
|
|
|
|
original = Image.open(self.obrazek_velky) |
|
|
|
|
|
# vycteni EXIFu |
|
|
|
|
|
exif = get_exif(original) |
|
|
|
|
|
if exif['DateTimeOriginal']: |
|
|
|
|
|
datum_ints = map(int, ":".join(exif['DateTimeOriginal'].split(' ')).split(":")) |
|
|
|
|
|
self.datum = datetime(*datum_ints) |
|
|
|
|
|
super(Obrazek, self).save() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Galerie(models.Model): |
|
|
class Galerie(models.Model): |
|
|