From 746bb4b34c1f2e23fa5b1c9d5f6eeb5bd28cc580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 27 Nov 2015 18:22:15 +0100 Subject: [PATCH] =?UTF-8?q?Galerie:=20odstran=C4=9Bn=20datum=20u=20obr?= =?UTF-8?q?=C3=A1zku,=20=C5=99a=C4=8F=20dle=20n=C3=A1zvu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0007_obrazek_odstranen_datum.py | 22 ++++++++++++++ galerie/models.py | 30 ++----------------- galerie/views.py | 4 +-- 3 files changed, 27 insertions(+), 29 deletions(-) create mode 100644 galerie/migrations/0007_obrazek_odstranen_datum.py diff --git a/galerie/migrations/0007_obrazek_odstranen_datum.py b/galerie/migrations/0007_obrazek_odstranen_datum.py new file mode 100644 index 00000000..94c3596b --- /dev/null +++ b/galerie/migrations/0007_obrazek_odstranen_datum.py @@ -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', + ), + ] diff --git a/galerie/models.py b/galerie/models.py index 9d55a3bf..9f3b1478 100644 --- a/galerie/models.py +++ b/galerie/models.py @@ -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): diff --git a/galerie/views.py b/galerie/views.py index 9e23133f..46860810 100644 --- a/galerie/views.py +++ b/galerie/views.py @@ -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':