Merge branch 'bez-exif'
This commit is contained in:
commit
a74575b94f
3 changed files with 27 additions and 29 deletions
22
galerie/migrations/0007_obrazek_odstranen_datum.py
Normal file
22
galerie/migrations/0007_obrazek_odstranen_datum.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('galerie', '0006_django_imagekit'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='obrazek',
|
||||
options={'ordering': ['nazev'], 'verbose_name': 'Obr\xe1zek', 'verbose_name_plural': 'Obr\xe1zky'},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='obrazek',
|
||||
name='datum',
|
||||
),
|
||||
]
|
|
@ -1,19 +1,12 @@
|
|||
# coding: utf-8
|
||||
|
||||
from django.db import models
|
||||
import seminar.models
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
#from django.db.models import Q
|
||||
from django.utils.encoding import force_unicode
|
||||
from imagekit.models import ImageSpecField
|
||||
from imagekit.processors import ResizeToFit, Transpose
|
||||
|
||||
from PIL import Image
|
||||
from PIL.ExifTags import TAGS
|
||||
import os
|
||||
from cStringIO import StringIO
|
||||
from django.core.files.base import ContentFile
|
||||
from datetime import datetime
|
||||
|
||||
from seminar.models import Soustredeni
|
||||
|
||||
|
@ -26,14 +19,6 @@ VIDITELNOST = (
|
|||
(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í
|
||||
# až se ty migrace někdy squashnou, tak by mělo být možné funkce smazat
|
||||
def obrazek_filename_maly():
|
||||
|
@ -63,23 +48,14 @@ class Obrazek(models.Model):
|
|||
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)
|
||||
datum = models.DateTimeField('Datum pořízení fotografie', blank = True, null = True)
|
||||
galerie = models.ForeignKey('Galerie', blank=True, null=True)
|
||||
poradi = models.IntegerField('Pořadí', blank = True, null = True)
|
||||
def __unicode__(self):
|
||||
return self.nazev + " -- " + unicode(self.obrazek_velky.name) + " (" + str(self.datum) + ")"
|
||||
return self.nazev + " -- " + unicode(self.obrazek_velky.name)
|
||||
class Meta:
|
||||
verbose_name = 'Obrázek'
|
||||
verbose_name_plural = 'Obrázky'
|
||||
ordering = ['datum']
|
||||
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()
|
||||
ordering = ['nazev']
|
||||
|
||||
|
||||
class Galerie(models.Model):
|
||||
|
|
|
@ -38,7 +38,7 @@ def nahled(request, pk, soustredeni):
|
|||
if not request.user.is_staff:
|
||||
podgalerie = podgalerie.filter(zobrazit__lt=1)
|
||||
|
||||
obrazky = Obrazek.objects.filter(galerie = galerie).order_by('datum')
|
||||
obrazky = Obrazek.objects.filter(galerie = galerie)
|
||||
preview = zobrazit(galerie, request)
|
||||
|
||||
sourozenci = []
|
||||
|
@ -82,7 +82,7 @@ def detail(request, pk, fotka, soustredeni):
|
|||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
preview = zobrazit(galerie, request)
|
||||
obrazek = get_object_or_404(Obrazek, pk=fotka)
|
||||
obrazky = galerie.obrazek_set.all().order_by('datum')
|
||||
obrazky = galerie.obrazek_set.all()
|
||||
|
||||
# vytvoreni a obslouzeni formulare
|
||||
if request.method == 'POST':
|
||||
|
|
Loading…
Reference in a new issue