From b3229fafe1e2cec767b90963e710f0d3e9898d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 20 Nov 2015 20:21:22 +0100 Subject: [PATCH 01/21] =?UTF-8?q?Pou=C5=BE=C3=ADvej=20na=20miniatury=20dja?= =?UTF-8?q?ngo-imagekit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit místo vlastních funkcí volaných v save() * migrace seminar i galerie * miniatury (a "střední velikosti") se nyní vytvářejí podle potřeby v media/CACHE --- galerie/migrations/0006_django_imagekit.py | 22 +++++ galerie/models.py | 96 ++++---------------- galerie/templates/galerie/GalerieNahled.html | 8 +- requirements.txt | 1 + seminar/migrations/0035_django_imagekit.py | 25 +++++ seminar/models.py | 67 +++----------- 6 files changed, 85 insertions(+), 134 deletions(-) create mode 100644 galerie/migrations/0006_django_imagekit.py create mode 100644 seminar/migrations/0035_django_imagekit.py diff --git a/galerie/migrations/0006_django_imagekit.py b/galerie/migrations/0006_django_imagekit.py new file mode 100644 index 00000000..6b90b791 --- /dev/null +++ b/galerie/migrations/0006_django_imagekit.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', '0005_obrazek_ordering_datum'), + ] + + operations = [ + migrations.RemoveField( + model_name='obrazek', + name='obrazek_maly', + ), + migrations.RemoveField( + model_name='obrazek', + name='obrazek_stredni', + ), + ] diff --git a/galerie/models.py b/galerie/models.py index 22457ba1..9d55a3bf 100644 --- a/galerie/models.py +++ b/galerie/models.py @@ -5,6 +5,8 @@ import seminar.models from django.db.models import Q from django.utils import timezone 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 @@ -32,47 +34,32 @@ def get_exif(fn): ret[decoded] = value return ret -def flip_horizontal(im): return im.transpose(Image.FLIP_LEFT_RIGHT) -def flip_vertical(im): return im.transpose(Image.FLIP_TOP_BOTTOM) -def rotate_180(im): return im.transpose(Image.ROTATE_180) -def rotate_90(im): return im.transpose(Image.ROTATE_90) -def rotate_270(im): return im.transpose(Image.ROTATE_270) -def transpose(im): return rotate_90(flip_horizontal(im)) -def transverse(im): return rotate_90(flip_vertical(im)) -orientation_funcs = [None, - lambda x: x, - flip_horizontal, - rotate_180, - flip_vertical, - transpose, - rotate_270, - transverse, - rotate_90 - ] - +# 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(): + pass +def obrazek_filename_stredni(): + pass +def obrazek_filename_velky(): + pass 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 cislo_gal = force_unicode(gal.pk) cesta = "" while(not gal.soustredeni): gal = gal.galerie_up - return os.path.join('Galerie', "soustredeni_" + force_unicode(gal.soustredeni.pk), "galerie_" + cislo_gal, typ, force_unicode(self.nazev)) + return os.path.join('Galerie', "soustredeni_" + force_unicode(gal.soustredeni.pk), "galerie_" + cislo_gal, "velky", force_unicode(self.nazev)) class Obrazek(models.Model): 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=obrazek_filename_stredni, null = True, editable = False) - obrazek_maly = models.ImageField(upload_to=obrazek_filename_maly, null = True, editable = False) + obrazek_stredni = ImageSpecField(source='obrazek_velky', + processors=[Transpose(Transpose.AUTO), ResizeToFit(900, 675, upscale=False)], + options={'quality': 95}) + obrazek_maly = ImageSpecField(source='obrazek_velky', + processors=[Transpose(Transpose.AUTO), ResizeToFit(167, 167, upscale=False)], + options={'quality': 95}) 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) @@ -89,55 +76,10 @@ class Obrazek(models.Model): original = Image.open(self.obrazek_velky) # vycteni EXIFu exif = get_exif(original) - # otoceni podle EXIFu - if exif['Orientation']: - f = orientation_funcs[exif['Orientation']] - original_otoceny = f(original) - original_otoceny.format = original.format - original = original_otoceny - # datum podle EXIfu if exif['DateTimeOriginal']: - datum_string = ":".join(exif['DateTimeOriginal'].split(' ')).split(":") - datum_int = [] - for retezec in datum_string: - datum_int.append(int(retezec)) - self.datum = datetime(datum_int[0], datum_int[1], datum_int[2], - datum_int[3], datum_int[4], datum_int[5]) - jmeno = os.path.basename(self.obrazek_velky.file.name) - if not self.obrazek_stredni: - Obrazek._vyrobMiniaturu(original, jmeno, 1024, self.obrazek_stredni) - if not self.obrazek_maly: - Obrazek._vyrobMiniaturu(original, jmeno, 200, self.obrazek_maly) + datum_ints = map(int, ":".join(exif['DateTimeOriginal'].split(' ')).split(":")) + self.datum = datetime(*datum_ints) super(Obrazek, self).save() - - @staticmethod - def _vyrobMiniaturu(original, jmeno, maximum, field): - zmensenina = Obrazek._zmensiObrazek(original, maximum) - f = StringIO() - try: - zmensenina.save(f, format=original.format) - data = ContentFile(f.getvalue()) - finally: - f.close() - field.save(jmeno, data, save = False) - - @staticmethod - def _zmensiObrazek(original, maximum): - """Preskaluje obrazek tak, aby byl zachovan pomer stran a zadny rozmer - nepresahoval maxRozmer. Pokud zadny rozmer nepresahuje maxRozmer, tak - vrati puvodni obrazek (tj. nedojde ke zvetseni obrazku).""" - novaVelikost = Obrazek._zmensiVelikost(original.size, maximum) - return original.resize(novaVelikost, Image.ANTIALIAS) - - @staticmethod - def _zmensiVelikost(velikost, maximum): - maximum = float(maximum) - w, h = velikost - soucasneMaximum = max(w, h) - if soucasneMaximum <= maximum: - return velikost - pomer = maximum/soucasneMaximum - return (int(w * pomer), int(h * pomer)) class Galerie(models.Model): diff --git a/galerie/templates/galerie/GalerieNahled.html b/galerie/templates/galerie/GalerieNahled.html index 1a4656b4..9a26f101 100644 --- a/galerie/templates/galerie/GalerieNahled.html +++ b/galerie/templates/galerie/GalerieNahled.html @@ -45,8 +45,8 @@ Galerie {{galerie.nazev}} {% if galerie.titulni_obrazek %} {% with galerie.titulni_obrazek.obrazek_maly as obrazek %} + width="{{ obrazek.width }}" + height="{{ obrazek.height }}" /> {% endwith %} {% endif %}
@@ -76,8 +76,8 @@ Galerie {{galerie.nazev}} {% for obrazek in obrazky %} + width="{{ obrazek.obrazek_maly.width }}" + height="{{ obrazek.obrazek_maly.height }}" /> {% endfor %}
diff --git a/requirements.txt b/requirements.txt index ea1261ee..4003e290 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,7 @@ django-flat-theme==0.9.3 django-taggit==0.17 django-autocomplete-light==2.2.6 django-crispy-forms==1.4.0 +django-imagekit==3.2.7 # Comments akismet==0.2.0 diff --git a/seminar/migrations/0035_django_imagekit.py b/seminar/migrations/0035_django_imagekit.py new file mode 100644 index 00000000..dd443018 --- /dev/null +++ b/seminar/migrations/0035_django_imagekit.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import imagekit.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0034_reseni_forma_default_email'), + ] + + operations = [ + migrations.RemoveField( + model_name='organizator', + name='foto_male', + ), + migrations.AlterField( + model_name='organizator', + name='foto', + field=imagekit.models.fields.ProcessedImageField(help_text=b'Vlo\xc5\xbe fotografii organiz\xc3\xa1tora o libovoln\xc3\xa9 velikosti', upload_to=b'image_organizatori/velke/%Y/', null=True, verbose_name=b'Fotografie organiz\xc3\xa1tora', blank=True), + preserve_default=True, + ), + ] diff --git a/seminar/models.py b/seminar/models.py index 0f65c272..47f71e5f 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -11,6 +11,8 @@ from django.utils.encoding import force_unicode from django.utils.text import slugify from django.core.urlresolvers import reverse from django.core.cache import cache +from imagekit.models import ImageSpecField, ProcessedImageField +from imagekit.processors import ResizeToFit, Transpose from PIL import Image import os @@ -785,11 +787,19 @@ class Organizator(models.Model): "'Přednáší na MFF'") strucny_popis_organizatora = models.TextField('Stručný popis organizátora', null = True, blank = True) - foto = models.ImageField('Fotografie organizátora', + foto = ProcessedImageField(verbose_name='Fotografie organizátora', upload_to='image_organizatori/velke/%Y/', null = True, blank = True, - help_text = 'Vlož fotografii organizátora o libovolné velikosti') - foto_male = models.ImageField(upload_to='image_organizatori/male/%Y/', - null = True, blank = True, editable = False) + help_text = 'Vlož fotografii organizátora o libovolné velikosti', + processors=[ + Transpose(Transpose.AUTO), + ResizeToFit(500, 500, upscale=False) + ], + options={'quality': 95}) + foto_male = ImageSpecField(source='foto', + processors=[ + ResizeToFit(200, 200, upscale=False) + ], + options={'quality': 95}) def __str__(self): return str(self.user) @@ -797,52 +807,3 @@ class Organizator(models.Model): class Meta: verbose_name = 'Organizátor' verbose_name_plural = 'Organizátoři' - - def save(self): - # v databázi uložený záznam o organizátorovi - puvodni = None - - # pokud už organizátor v databázi existuje, nastav puvodni - if self.id is not None: - puvodni = Organizator.objects.get(id=self.id) - # pokud nahráváme fotku - if self.foto: - # a je jiná než ta stará - if not puvodni or puvodni.foto != self.foto: - # uložíme ji - original = Image.open(self.foto) - jmeno = os.path.basename(self.foto.file.name) - Organizator._vyrobMiniaturu(original, jmeno, 500, self.foto) - Organizator._vyrobMiniaturu(original, jmeno, 200, self.foto_male) - super(Organizator, self).save() - - @staticmethod - def _vyrobMiniaturu(original, jmeno, maximum, field): - zmensenina = Organizator._zmensiObrazek(original, maximum) - f = StringIO() - try: - zmensenina.save(f, format=original.format) - data = ContentFile(f.getvalue()) - finally: - f.close() - field.save(jmeno, data, save = False) - - @staticmethod - def _zmensiObrazek(original, maximum): - """Preskaluje obrazek tak, aby byl zachovan pomer stran - a zadny rozmer nepresahoval maxRozmer. Pokud zadny rozmer - nepresahuje maxRozmer, tak vrati puvodni obrazek - (tj. nedojde ke zvetseni obrazku).""" - novaVelikost = Organizator._zmensiVelikost(original.size, maximum) - return original.resize(novaVelikost, Image.ANTIALIAS) - - @staticmethod - def _zmensiVelikost(velikost, maximum): - maximum = float(maximum) - w, h = velikost - soucasneMaximum = max(w, h) - if soucasneMaximum <= maximum: - return velikost - pomer = maximum/soucasneMaximum - return (int(w * pomer), int(h * pomer)) - From ead4f091e6a2705877a43059c39d11b2aa1af06e Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Sun, 22 Nov 2015 19:43:56 +0100 Subject: [PATCH 02/21] hlaseni chyb na errors e-mail --- mamweb/settings_prod.py | 1 + mamweb/settings_test.py | 1 + 2 files changed, 2 insertions(+) diff --git a/mamweb/settings_prod.py b/mamweb/settings_prod.py index ee8233e3..b56a9380 100644 --- a/mamweb/settings_prod.py +++ b/mamweb/settings_prod.py @@ -50,6 +50,7 @@ ADMINS = [ ('Petr Pecha', 'nejlepsitextovyeditorjevim@gmail.com'), ('Tomas Gavenciak', 'gavento@gmail.com'), ('Matěj Kocián', 'matej.kocian@gmail.com'), + ('M&M ERRORs', 'mam-errors@atrey.karlin.mff.cuni.cz'), ] diff --git a/mamweb/settings_test.py b/mamweb/settings_test.py index abe315ad..3d1b0010 100644 --- a/mamweb/settings_test.py +++ b/mamweb/settings_test.py @@ -50,6 +50,7 @@ import os SERVER_EMAIL = 'mamweb-test-errors@mam.mff.cuni.cz' ADMINS = [ ('Petr Pecha', 'nejlepsitextovyeditorjevim@gmail.com'), + ('M&M ERRORs', 'mam-errors@atrey.karlin.mff.cuni.cz'), ] From 8196108b36054b5cef69c7d42b46423a160e2f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 27 Nov 2015 11:29:29 +0100 Subject: [PATCH 03/21] manage.py generateimages funguje MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (vygeneruje všechny náhledy) * imagekit přidán do INSTALLED_APPS * nová verze django-debug-toolbar 1.4 nižší verze kolidovala s imagekitem --- mamweb/settings_common.py | 2 ++ requirements.txt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 5b3fe86b..d48a0938 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -111,6 +111,8 @@ INSTALLED_APPS = ( 'django.contrib.flatpages', 'django.contrib.humanize', + 'imagekit', + # MaMweb 'mamweb', 'seminar', diff --git a/requirements.txt b/requirements.txt index 4003e290..cff14d30 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,7 +33,7 @@ django-contrib-comments==1.6.1 # debug tools/extensions -django-debug-toolbar==1.3.2 +django-debug-toolbar==1.4 django-extensions==1.5.6 sqlparse==0.1.16 Werkzeug==0.10.4 From 6a8db788f0a733e81347af3782efbe75d0705443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 27 Nov 2015 16:52:20 +0100 Subject: [PATCH 04/21] =?UTF-8?q?Novinky:=20obr=C3=A1zky=20jsou=20klikatel?= =?UTF-8?q?n=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/static/css/mamweb.css | 10 +++++++++- seminar/models.py | 6 ++++++ seminar/templates/seminar/novinky.html | 13 ++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/mamweb/static/css/mamweb.css b/mamweb/static/css/mamweb.css index bfdb87b0..1daecacc 100644 --- a/mamweb/static/css/mamweb.css +++ b/mamweb/static/css/mamweb.css @@ -437,7 +437,7 @@ div.zadani_azad_termin { float: none; width: 70%; margin-left: auto; - margin-right: auto + margin-right: auto; } } @@ -649,3 +649,11 @@ div.zadani_azad_termin { float: right; max-width: 42%; } + +.novinka_obrazek img { + margin-bottom: 15px; +} + +div.novinka_obrazek { + width: 100%; +} diff --git a/seminar/models.py b/seminar/models.py index 47f71e5f..c33488f1 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -757,6 +757,12 @@ class Novinky(models.Model): text = models.TextField('Text novinky', blank=True, null=True) obrazek = models.ImageField('Obrázek', upload_to='image_novinky/%Y/%m/%d/', null=True, blank=True) + obrazek_maly = ImageSpecField(source='obrazek', + processors=[ + ResizeToFit(350, 200, upscale=False) + ], + options={'quality': 95}) + autor = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='Autor novinky') zverejneno = models.BooleanField('Zveřejněno', default="False") diff --git a/seminar/templates/seminar/novinky.html b/seminar/templates/seminar/novinky.html index c13407f5..66876fbd 100644 --- a/seminar/templates/seminar/novinky.html +++ b/seminar/templates/seminar/novinky.html @@ -7,15 +7,14 @@ {{ novinka.text | safe }} {# obrazek #} {% if novinka.obrazek %} -
- + {% if novinka.obrazek.height > novinka.obrazek_maly.height %} + + + {% else %} - {{novinka.obrazek.height}} + {% endif%} - '>
{% endif %} {# autor #} 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 05/21] =?UTF-8?q?Galerie:=20odstran=C4=9Bn=20datum=20u=20o?= =?UTF-8?q?br=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': From 606426bb1ec7f124b11b6b35fe4ec942e4d4681b Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sat, 28 Nov 2015 22:45:10 +0100 Subject: [PATCH 06/21] Pridan odkaz na aktualni zadani v odpocitavadle. --- seminar/templates/seminar/titulnistrana.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seminar/templates/seminar/titulnistrana.html b/seminar/templates/seminar/titulnistrana.html index a28ffa15..c6c1a522 100644 --- a/seminar/templates/seminar/titulnistrana.html +++ b/seminar/templates/seminar/titulnistrana.html @@ -20,7 +20,7 @@ M&M je korespondeční seminář. Několikrát do roka zdarma vydáváme ča
{% if dead %}
-

Do konce odeslání řešení zbývá:
+

Do konce odeslání řešení zbývá:
{{ted|timesince:dead}}

From fd03563ad6535b65007811eeafdca323112d1434 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sat, 28 Nov 2015 23:18:43 +0100 Subject: [PATCH 07/21] Nezverejnene novinky se zobrazuji prihlasenym. --- seminar/templates/seminar/novinky.html | 8 ++++++++ seminar/views.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/seminar/templates/seminar/novinky.html b/seminar/templates/seminar/novinky.html index 66876fbd..f7aa8dfd 100644 --- a/seminar/templates/seminar/novinky.html +++ b/seminar/templates/seminar/novinky.html @@ -1,6 +1,10 @@ {% for novinka in object_list %} {# pripravene div-y na stylovani#}
+ {% if not novinka.zverejneno and user.is_authenticated %} +
+ {% endif %} + {% if novinka.zverejneno or user.is_authenticated %} {# datum #}
{{novinka.datum}}
{# text #} @@ -25,6 +29,10 @@ {{novinka.autor.last_name}}

+ {% endif %} + {% if not novinka.zverejneno and user.is_authenticated %} +
+ {% endif %}
{% endfor%} diff --git a/seminar/views.py b/seminar/views.py index 36002799..c43799fd 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -66,7 +66,7 @@ def ZadaniAktualniVysledkovkaView(request): class TitulniStranaView(generic.ListView): model = Novinky template_name='seminar/titulnistrana.html' - queryset = Novinky.objects.filter(zverejneno=True).order_by('-datum')[:5] + queryset = Novinky.objects.order_by('-datum')[:5] def get_context_data(self, **kwargs): context = super(TitulniStranaView, self).get_context_data(**kwargs) From 7377e143bfa9984ab334b8b6efa73c26607e527f Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sat, 28 Nov 2015 23:40:50 +0100 Subject: [PATCH 08/21] is_staff je asi lepsi nez is_authenticated. --- seminar/templates/seminar/novinky.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/seminar/templates/seminar/novinky.html b/seminar/templates/seminar/novinky.html index f7aa8dfd..0ac99356 100644 --- a/seminar/templates/seminar/novinky.html +++ b/seminar/templates/seminar/novinky.html @@ -1,10 +1,10 @@ {% for novinka in object_list %} {# pripravene div-y na stylovani#}
- {% if not novinka.zverejneno and user.is_authenticated %} + {% if not novinka.zverejneno and user.is_staff %}
{% endif %} - {% if novinka.zverejneno or user.is_authenticated %} + {% if novinka.zverejneno or user.is_staff %} {# datum #}
{{novinka.datum}}
{# text #} @@ -30,7 +30,7 @@

{% endif %} - {% if not novinka.zverejneno and user.is_authenticated %} + {% if not novinka.zverejneno and user.is_staff %}
{% endif %}
From ea99212e804115c6d4cb5c40a8d0fe0085ee035d Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sat, 28 Nov 2015 23:41:12 +0100 Subject: [PATCH 09/21] Ze seznamu soustredeni se daji generovat obalky. --- seminar/templates/seminar/soustredeni/seznam_soustredeni.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seminar/templates/seminar/soustredeni/seznam_soustredeni.html b/seminar/templates/seminar/soustredeni/seznam_soustredeni.html index be7a3644..121d19b0 100644 --- a/seminar/templates/seminar/soustredeni/seznam_soustredeni.html +++ b/seminar/templates/seminar/soustredeni/seznam_soustredeni.html @@ -52,7 +52,8 @@ {% if user.is_staff %} {% endif %} From d289d165ef45f7c77076d7bd646e2409303eea65 Mon Sep 17 00:00:00 2001 From: Aneta Date: Thu, 3 Dec 2015 01:05:06 +0100 Subject: [PATCH 10/21] =?UTF-8?q?Oprava=20generov=C3=A1n=C3=AD=20TeXovsk?= =?UTF-8?q?=C3=A9=20v=C3=BDsledkovky.=20V=20models=20p=C5=99id=C3=A1na=20f?= =?UTF-8?q?ce=20pro=20=C5=99e=C5=A1itele=20inicial=5Fkrestni,=20ve=20views?= =?UTF-8?q?.py=20opraveno=20po=C5=99ad=C3=AD=20(2.-5.)=20pomoc=C3=AD=20uni?= =?UTF-8?q?codov=C3=A9=20poml=C4=8Dky.=20A.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/models.py | 3 ++ .../seminar/archiv/cislo_vysledkovka.tex | 35 +++---------------- seminar/views.py | 3 +- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/seminar/models.py b/seminar/models.py index c33488f1..fbb2a9d5 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -185,6 +185,9 @@ class Resitel(SeminarModelBase): def plne_jmeno(self): return force_unicode(u'%s %s' % (self.jmeno, self.prijmeni)) + def inicial_krestni(self): + return force_unicode(u'%s.' % (self.jmeno[0])) + def __str__(self): return force_unicode(self.plne_jmeno()) diff --git a/seminar/templates/seminar/archiv/cislo_vysledkovka.tex b/seminar/templates/seminar/archiv/cislo_vysledkovka.tex index e988484c..f3a9d662 100644 --- a/seminar/templates/seminar/archiv/cislo_vysledkovka.tex +++ b/seminar/templates/seminar/archiv/cislo_vysledkovka.tex @@ -1,33 +1,6 @@ -\begin{longtable}{r|l|c|l|c - {% for p in problemy %} - @\hskip.5em}c {% endfor %} - |c|r|r} -\hline -& & & & \multicolumn{ {{ problemy|length }} }{c|}{\textbf{Úlohy}} & & \\ -\textbf{Poř.} & \textbf{Jméno} & \textbf{R.} & \raisebox{0.7mm}{$\sum_{-1}$} & -{% for p in problemy %} - {% if p.TYP_ULOHA %} - \textbf{ r{{ p.kod }} } & - {% else %} - \textbf{ t{{ p.kod }} } & - {% endif %} -{% endfor %} -\raisebox{0.7mm}{$\sum_0$} & -\raisebox{0.7mm}{$\sum_1$} \\ -\hline +\begin{longtable}{|r|l|c|r|{% for p in problemy %}c@{\hskip.5em}{% endfor %}|r|r|}\hline +& & & & \multicolumn{ {{ problemy|length }} }{c|}{\textbf{Úlohy}} & & \\\textbf{Poř.} & \textbf{Jméno} & \textbf{R.} & \raisebox{0.7mm}{$\sum_{-1}$} & {% for p in problemy %}{% if p.TYP_ULOHA %}\textbf{r{{p.kod}}} & {% else %}\textbf{t{{p.kod}}} & {% endif %}{% endfor %}\raisebox{0.7mm}{$\sum_0$} & \raisebox{0.7mm}{$\sum_1$} \\ \hline \endhead \hline -\endfoot - -{% for rv in vysledkovka %} - {{ rv.poradi }} & -{% if rv.resitel.titul %} - \titul{ {{ rv.titul }} } -{% endif %} - {{ rv.resitel.plne_jmeno }} & {{ rv.resitel.rocnik |default:"" }} & {{ rv.body_minule }} - {% for b in rv.body %} - {{ b }} & - {% endfor %} - {{ rv.body_celkem_rocnik |default:0 }} & {{ rv.body_celkem_minule }} \\ -{% endfor %} -\end{longtable} +\endfoot {% for rv in vysledkovka %} {{ rv.poradi }} & {% if rv.resitel.titul %} \titul{ {{ rv.titul }} } {% endif %} {{rv.resitel.inicial_krestni}} {{rv.resitel.prijmeni}} & {{ rv.resitel.rocnik |default:"" }} & {{ rv.body_minule }} & {% for b in rv.body_ulohy %}{{ b }} & {% endfor %} {{ rv.body_celkem_rocnik |default:0 }} & {{ rv.body_celkem_minule }} \\ +{% endfor %}\end{longtable} diff --git a/seminar/views.py b/seminar/views.py index c43799fd..54ed3e11 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -128,8 +128,9 @@ def sloupec_s_poradim(vysledky): poradi_l += ["{}.".format(lepsich_resitelu + 1)] # je-li účastníků se stejným počtem bodů víc, pořadí (rozsah X.-Y.) je jen u prvního else: - poradi_l += ["{}.–{}.".format(lepsich_resitelu + 1, lepsich_resitelu + len(skupina))] + [""] * (len(skupina)-1) + poradi_l += [u"{}. – {}.".format(lepsich_resitelu + 1, lepsich_resitelu + len(skupina))] + [""] * (len(skupina)-1) lepsich_resitelu += len(skupina) + #pomlcka je opravdu pomlcka v unicode!!dulezite pro vysledkovku v TeXu return poradi_l From 1f0ba770b3c585fac5df3ef6f129d563b6a54f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 4 Dec 2015 14:34:51 +0100 Subject: [PATCH 11/21] =?UTF-8?q?Galerie:=20=C3=BApravy=20vzhledu=20a=20ma?= =?UTF-8?q?m-org-only=20blok=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- galerie/templates/galerie/GalerieNahled.html | 15 +++- mamweb/static/css/mamweb.css | 18 ++++- .../soustredeni/seznam_soustredeni.html | 72 +++++++++---------- 3 files changed, 64 insertions(+), 41 deletions(-) diff --git a/galerie/templates/galerie/GalerieNahled.html b/galerie/templates/galerie/GalerieNahled.html index 9a26f101..bb475b50 100644 --- a/galerie/templates/galerie/GalerieNahled.html +++ b/galerie/templates/galerie/GalerieNahled.html @@ -6,6 +6,10 @@ Galerie {{galerie.nazev}} {% block content %} + {% if galerie.zobrazit > 0 %} +
+ {% endif %} +

{% for g in cesta %} {% if not forloop.last %} @@ -19,7 +23,7 @@ Galerie {{galerie.nazev}} {% if not obrazky %}
{% if galerie.titulni_obrazek %} - + {% endif %}
{% endif %} @@ -45,8 +49,8 @@ Galerie {{galerie.nazev}} {% if galerie.titulni_obrazek %} {% with galerie.titulni_obrazek.obrazek_maly as obrazek %} + width="{% widthratio obrazek.width 167 obrazek.width %}" + height="{% widthratio obrazek.width 167 obrazek.height %}" /> {% endwith %} {% endif %}
@@ -103,4 +107,9 @@ Galerie {{galerie.nazev}}
{% endif %} {% endif %} + + {% if galerie.zobrazit > 0 %} +

{# mam-org-only #} + {% endif %} + {% endblock content %} diff --git a/mamweb/static/css/mamweb.css b/mamweb/static/css/mamweb.css index 1daecacc..8b1ef07d 100644 --- a/mamweb/static/css/mamweb.css +++ b/mamweb/static/css/mamweb.css @@ -18,6 +18,15 @@ body { border: orange 2px dashed; } +.mam-org-only .mam-org-only { + border: 0px; +} + +li.mam-org-only { + padding: 3px 0px; + margin: -2px 0px; +} + table .border-r { border-right: solid 1px; } @@ -446,7 +455,8 @@ div.zadani_azad_termin { /* galerie */ /* velká fotka */ -.galerie .obrazek { +/* zmenšování spolu s oknem prohlížeče */ +.galerie .obrazek, .titulni_obrazek { max-width: 100%; height: auto; width: auto\9; /* ie8 */ @@ -482,7 +492,6 @@ div.zadani_azad_termin { .galerie { position: relative; text-align: center; - /*width: 100%;*/ margin: 20px auto 0 auto; } @@ -503,6 +512,11 @@ div.zadani_azad_termin { text-align: center; } +/* titulní obrázek hlavní galerie soustředění */ +.titulni_obrazek { + border: 1px solid black; +} + .galerie_nahledy{ /*margin: 1em 0;*/ margin: 0 auto 30px auto; diff --git a/seminar/templates/seminar/soustredeni/seznam_soustredeni.html b/seminar/templates/seminar/soustredeni/seznam_soustredeni.html index 121d19b0..f7bc73a8 100644 --- a/seminar/templates/seminar/soustredeni/seznam_soustredeni.html +++ b/seminar/templates/seminar/soustredeni/seznam_soustredeni.html @@ -21,47 +21,44 @@ {# Projdi vsechna soustredeni #} {% for soustredeni in object_list %} {# Kdyz je verejne -> zobraz #} - {% if soustredeni.verejne_db or user.is_authenticated %} - {% if not soustredeni.verejne_db and user.is_authenticated %} - Groups of user: {{user.groups.all}}
- - Toto soustředění není veřejné, vidíte ho jen proto, - že jste přihlášení.
+ {% if soustredeni.verejne_db or user.is_staff %} + {% if not soustredeni.verejne_db and user.is_staff %} +
+ {% endif %} {# misto soustredeni TODO upravit#} -

- {{soustredeni.get_typ_display}} - {{soustredeni.misto}} -

-
    -
  • - {{soustredeni.datum_zacatku}} – {{soustredeni.datum_konce}} -
  • - {# Zobrazeni odkazu na galerie #} - {% if soustredeni.galerie_set.all %} - {% for galerie in soustredeni.galerie_set.all %} - {% if galerie.zobrazit == 0 or user.is_staff %} +

    + {{soustredeni.get_typ_display}} + {{soustredeni.misto}} +

    +
    • - Fotogalerie - {# TODO kdyz je titulni obrazek, tak asi i titulni obrazek #} + {{soustredeni.datum_zacatku}} – {{soustredeni.datum_konce}}
    • + {# Zobrazeni odkazu na galerie #} + {% if soustredeni.galerie_set.all %} + {% for galerie in soustredeni.galerie_set.all %} + {% if galerie.zobrazit == 0 or user.is_staff %} +
    • 0 and user.is_staff %}class="mam-org-only"{% endif %}> + Fotogalerie + {# TODO kdyz je titulni obrazek, tak asi i titulni obrazek #} +
    • + {% endif %} + {% endfor %} + {% endif %} +
    + {% if user.is_staff %} + {% endif %} - {% endfor %} - {% endif %} -
- {% if user.is_staff %} - - {% endif %} - {# popis soustredeni #} - {% if soustredeni.text %} - {% autoescape off %}{{soustredeni.text}}{% endautoescape %} - {% endif %} + {# popis soustredeni #} + {% if soustredeni.text %} + {% autoescape off %}{{soustredeni.text}}{% endautoescape %} + {% endif %} {% if user.is_authenticated %} {# Účastníci #}

Soustředění se zúčastnili tito účastníci:

@@ -73,9 +70,12 @@ {% endfor %} {% endif %} + {% if not soustredeni.verejne_db and user.is_staff %} +
{# class="mam-org-only" #} + {% endif %} {% endif %} - {% empty %} - Žádná soustředění zatím neproběhla! + {% empty %} + Žádná soustředění zatím neproběhla! {% endfor %} {% endblock %} From 26b3cbba7f2c9a4611c80327b39ec22e44101bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 4 Dec 2015 16:03:15 +0100 Subject: [PATCH 12/21] =?UTF-8?q?Admin:=20filtrov=C3=A1n=C3=AD=20zadan?= =?UTF-8?q?=C3=BDch=20probl=C3=A9m=C5=AF=20dle=20zam=C4=9B=C5=99en=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seminar/admin.py b/seminar/admin.py index 3a680fc4..b86d933a 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -334,7 +334,7 @@ create_modeladmin(ProblemNavrhAdmin, Problem, 'ProblemNavrh', verbose_name=u'Pro class ProblemZadanyAdmin(ProblemAdmin): list_display = ['nazev', 'typ', 'autor', 'opravovatel', 'kod', 'cislo_zadani', 'pocet_reseni', 'verejne'] - list_filter = ['typ', 'cislo_zadani__cislo', 'cislo_zadani__rocnik'] + list_filter = ['typ', 'zamereni', 'cislo_zadani__cislo', 'cislo_zadani__rocnik'] inlines = [ReseniKProblemuInline] def get_queryset(self, request): From 607a94ff8cf31092adcc8414e856a4009b5d791e Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Fri, 4 Dec 2015 20:03:06 +0100 Subject: [PATCH 13/21] Nezverejnuj odpocet, pokud neni jeste verejne cislo --- seminar/templates/seminar/titulnistrana.html | 16 +--------------- seminar/views.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/seminar/templates/seminar/titulnistrana.html b/seminar/templates/seminar/titulnistrana.html index c6c1a522..ae949d7e 100644 --- a/seminar/templates/seminar/titulnistrana.html +++ b/seminar/templates/seminar/titulnistrana.html @@ -22,23 +22,9 @@ M&M je korespondeční seminář. Několikrát do roka zdarma vydáváme ča

Do konce odeslání řešení zbývá:
{{ted|timesince:dead}}

- - - -
{% endif %} + {# Novinky #}

Novinky

{% include 'seminar/novinky.html' %} diff --git a/seminar/views.py b/seminar/views.py index 54ed3e11..e122d163 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -72,16 +72,16 @@ class TitulniStranaView(generic.ListView): context = super(TitulniStranaView, self).get_context_data(**kwargs) nastaveni = get_object_or_404(Nastaveni) cas_deadline = nastaveni.aktualni_cislo.datum_deadline - try: - rozdil_casu = datetime.combine(cas_deadline, datetime.max.time()) \ - - datetime.now() - context['cas_do_konce_dni'] = rozdil_casu.days - context['cas_do_konce_hodin'] = rozdil_casu.seconds / 3600 - context['cas_do_konce_minut'] = (rozdil_casu.seconds / 60) % 60 - context['cas_do_konce_sekund'] = rozdil_casu.seconds % 60 - context['dead'] = datetime.combine(cas_deadline, datetime.max.time()) - context['ted'] = datetime.now() - except: + # Pokud neni zverejnene cislo nezverejnuj odpocet + if nastaveni.aktualni_cislo.verejne(): + # pokus se zjistit termin odeslani a pokud neni zadany, + # nezverejnuj odpocet + try: + context['dead'] = datetime.combine(cas_deadline, datetime.max.time()) + context['ted'] = datetime.now() + except: + context['dead'] = None + else: context['dead'] = None return context From 7599522a13dec758b4e6ecef91ca33c18f6bd3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 4 Dec 2015 20:09:42 +0100 Subject: [PATCH 14/21] =?UTF-8?q?Admin:=20=C3=BApravy=20galeri=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tlačítko uložit nahoře * náhled obrázku ve volbě titulní fotky * řazení galerií podle (rodiče, pořadí) --- galerie/admin.py | 27 +++++++++----- galerie/autocomplete_light_registry.py | 49 ++++++++++++++++++++++++++ galerie/models.py | 6 ++++ 3 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 galerie/autocomplete_light_registry.py diff --git a/galerie/admin.py b/galerie/admin.py index 4f95c951..1441ce09 100644 --- a/galerie/admin.py +++ b/galerie/admin.py @@ -3,6 +3,9 @@ from galerie.models import Obrazek, Galerie from django.contrib import admin from django.http import HttpResponseRedirect +from django import forms +from django.db import models +import autocomplete_light # akction @@ -27,17 +30,25 @@ def prepnout_fotogalerii_do_org_rezimu(modeladmin, request, queryset): 'Přepnout do režimu úprav (zneveřejní galerii)' class GalerieInline(admin.TabularInline): - model = Obrazek + model = Obrazek + fields = ['obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag'] + readonly_fields = ['nazev', 'obrazek_maly_tag'] + formfield_overrides = { + models.TextField: {'widget': forms.TextInput}, + } class ObrazekAdmin(admin.ModelAdmin): - list_display = ('obrazek_velky', 'nazev', 'popis') + list_display = ('obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag') -class GalerieAdmin(admin.ModelAdmin): - model = Galerie - fields = ('zobrazit', 'nazev', 'titulni_obrazek', 'popis', 'galerie_up', 'soustredeni', 'poradi') - list_display = ('nazev', 'pk', 'datum_zmeny', 'zobrazit', 'soustredeni') - inlines = [GalerieInline] - actions = [zverejnit_fotogalerii, prepnout_fotogalerii_do_org_rezimu] +class GalerieAdmin(admin.ModelAdmin): + form = autocomplete_light.modelform_factory(Galerie, autocomplete_fields=['titulni_obrazek'], fields=['titulni_obrazek']) + model = Galerie + fields = ('zobrazit', 'nazev', 'titulni_obrazek', 'popis', 'galerie_up', 'soustredeni', 'poradi') + list_display = ('nazev', 'pk', 'poradi', 'datum_zmeny', 'zobrazit', 'soustredeni') + inlines = [GalerieInline] + actions = [zverejnit_fotogalerii, prepnout_fotogalerii_do_org_rezimu] + save_on_top = True + ordering = ['galerie_up__nazev', 'poradi'] admin.site.register(Obrazek, ObrazekAdmin) admin.site.register(Galerie, GalerieAdmin) diff --git a/galerie/autocomplete_light_registry.py b/galerie/autocomplete_light_registry.py new file mode 100644 index 00000000..7b624d20 --- /dev/null +++ b/galerie/autocomplete_light_registry.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +from __future__ import unicode_literals + +import autocomplete_light + +from models import Obrazek, Galerie +from views import cesta_od_korene + + +class ObrazekAutocomplete(autocomplete_light.AutocompleteModelBase): + + model = Obrazek + search_fields = ['nazev', 'popis'] + split_words = True + limit_choices = 15 + attrs = { + # This will set the input placeholder attribute: + 'placeholder': u'Obrázek', + # This will set the yourlabs.Autocomplete.minimumCharacters + # options, the naming conversion is handled by jQuery + 'data-autocomplete-minimum-characters': 1, + } + + choice_html_format = ''' + + + {} + {} + + + ''' + + def choice_label(self, obrazek): + cesta = "/".join(g.nazev for g in cesta_od_korene(obrazek.galerie)) + popis = "{}
".format(obrazek.popis) if obrazek.popis else "" + return '{}
{}{}'.format(obrazek.nazev, popis, cesta) + + def choice_html(self, obrazek): + """Vrátí kus html i s obrázkem, které se pak ukazuje v nabídce""" + return self.choice_html_format.format(self.choice_value(obrazek), + obrazek.obrazek_maly_tag(), self.choice_label(obrazek)) + + widget_attrs={ + 'data-widget-maximum-values': 15, + 'class': 'modern-style', + } + +autocomplete_light.register(ObrazekAutocomplete) diff --git a/galerie/models.py b/galerie/models.py index 9f3b1478..4c08c4f2 100644 --- a/galerie/models.py +++ b/galerie/models.py @@ -56,6 +56,12 @@ class Obrazek(models.Model): verbose_name = 'Obrázek' verbose_name_plural = 'Obrázky' ordering = ['nazev'] + + def obrazek_maly_tag(self): + return u''.format(self.obrazek_maly.url) + obrazek_maly_tag.short_description = "Náhled" + obrazek_maly_tag.allow_tags = True + class Galerie(models.Model): From 5be011652d987452e0448b0326c232e723eff15e Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sun, 6 Dec 2015 18:56:56 +0100 Subject: [PATCH 15/21] Orgovksy odkaz na obalky. --- seminar/templates/seminar/archiv/cislo.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/seminar/templates/seminar/archiv/cislo.html b/seminar/templates/seminar/archiv/cislo.html index 2978cc84..50d50c5a 100644 --- a/seminar/templates/seminar/archiv/cislo.html +++ b/seminar/templates/seminar/archiv/cislo.html @@ -27,6 +27,12 @@ {% endfor %} + {% if user.is_staff %} + + {% endif %} + {% if cislo.verejna_vysledkovka %}

Výsledkovka

{% else %} From 09149f6fc9edc356f11b05fc6ceee9ad82e4bde1 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sun, 6 Dec 2015 19:25:31 +0100 Subject: [PATCH 16/21] Odkaz na tituly ze stranky cisla. --- seminar/templates/seminar/archiv/cislo.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/seminar/templates/seminar/archiv/cislo.html b/seminar/templates/seminar/archiv/cislo.html index 50d50c5a..a398a6cb 100644 --- a/seminar/templates/seminar/archiv/cislo.html +++ b/seminar/templates/seminar/archiv/cislo.html @@ -29,7 +29,11 @@ {% if user.is_staff %}
- Obálky (PDF) +

Orgovské odkazy

+
{% endif %} From 96161c49743ba41ee532dda38d3721c7b1ffa8ee Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sun, 6 Dec 2015 23:32:25 +0100 Subject: [PATCH 17/21] Funkce pro aktualni a aktivni resitele. --- seminar/views.py | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/seminar/views.py b/seminar/views.py index 54ed3e11..84890ea8 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -7,6 +7,7 @@ from django.core.urlresolvers import reverse from django.views import generic from django.utils.translation import ugettext as _ from django.http import Http404 +from django.db.models import Q from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva @@ -343,28 +344,42 @@ class RocnikVysledkovkaView(RocnikView): ### Generovani obalek class CisloObalkyStruct: - resitele = None rocnik = None - problemy = None - -def cisloObalkyView(request,rocnik,cislo): + cisla = None + + +# Vraci QuerySet aktualnich resitelu = nekdy neco poslali, ale jeste neodmaturovali +def aktualniResitele(rocnik): + letos = Rocnik.objects.filter(rocnik = rocnik).first() + return Resitel.objects.filter(rok_maturity__gt = letos.prvni_rok) +# # ALERT: pokud nekdo nema vypleny rok maturity, tak neni aktualni, protoze Karel Tesar a jini +# return Resitel.objects.filter(Q(rok_maturity__gt = letos.prvni_rok)|Q(rok_maturity = None)) + +# Vraci QuerySet aktivnich resitelu = +# jeste neodmaturovali && +# (pokud je aktualni cislo mensi nez 3, pak (letos || loni) neco poslali +# jinak letos neco poslali) +def aktivniResitele(rocnik,cislo): letos = CisloObalkyStruct() loni = CisloObalkyStruct() - letos.rocnik = Rocnik.objects.filter(rocnik = rocnik)[0] - loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1)[0] - letos.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo)) - loni.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=loni.rocnik)) - letos.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=letos.problemy)).distinct() - loni.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=loni.problemy)).distinct() - - loni.resitele = loni.resitele.filter(rok_maturity__gt = letos.rocnik.prvni_rok) - + aktualni_resitele = aktualniResitele(rocnik) + + letos.rocnik = Rocnik.objects.filter(rocnik = rocnik).first() + loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1).first() + letos.cisla = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo) + loni.cisla = Cislo.objects.filter(rocnik=loni.rocnik) if int(cislo) > 3: - resitele = letos.resitele + problemy = Problem.objects.filter(cislo_zadani = letos.cisla) else: - resitele = list(letos.resitele) + list(loni.resitele) - return obalkyView(request,resitele) + problemy = Problem.objects.filter(Q(cislo_zadani = letos.cisla)|Q(cislo_zadani=loni.cisla)) + resitele = aktualni_resitele.filter(reseni = Reseni.objects.filter(problem=problemy)).distinct() + + return resitele + + +def cisloObalkyView(request,rocnik,cislo): + return obalkyView(request,aktivniResitele(rocnik,cislo)) def obalkyView(request,resitele): From a2c333241badad6271f653ba7e95d8fd80257546 Mon Sep 17 00:00:00 2001 From: Aneta Date: Mon, 7 Dec 2015 22:41:12 +0100 Subject: [PATCH 18/21] =?UTF-8?q?Doupraven=C3=AD=20v=C3=BDsledkovky=20do?= =?UTF-8?q?=20funk=C4=8Dn=C3=ADho=20stavu.=20A.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/templates/seminar/archiv/cislo_vysledkovka.tex | 9 ++++++--- seminar/views.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/seminar/templates/seminar/archiv/cislo_vysledkovka.tex b/seminar/templates/seminar/archiv/cislo_vysledkovka.tex index f3a9d662..d961d39f 100644 --- a/seminar/templates/seminar/archiv/cislo_vysledkovka.tex +++ b/seminar/templates/seminar/archiv/cislo_vysledkovka.tex @@ -1,6 +1,9 @@ +\setlength{\tabcolsep}{3pt} \begin{longtable}{|r|l|c|r|{% for p in problemy %}c@{\hskip.5em}{% endfor %}|r|r|}\hline -& & & & \multicolumn{ {{ problemy|length }} }{c|}{\textbf{Úlohy}} & & \\\textbf{Poř.} & \textbf{Jméno} & \textbf{R.} & \raisebox{0.7mm}{$\sum_{-1}$} & {% for p in problemy %}{% if p.TYP_ULOHA %}\textbf{r{{p.kod}}} & {% else %}\textbf{t{{p.kod}}} & {% endif %}{% endfor %}\raisebox{0.7mm}{$\sum_0$} & \raisebox{0.7mm}{$\sum_1$} \\ \hline +&&&&\multicolumn{ {{ problemy|length}} }{c|}{\textbf{Úlohy}}&&\\\textbf{Poř.}&\textbf{Jméno}&\textbf{R.}&\raisebox{0.7mm}{$\sum_{-1}$}&{% for p in problemy %}{% if p.typ == "uloha" %}\textbf{r{{p.kod}}}&{% elif p.typ = "tema" %}\textbf{t{{p.kod}}}&{% else %}\textbf{ {{p.kod}} }&{% endif %}{% endfor %}\raisebox{0.7mm}{$\sum_0$}&\raisebox{0.7mm}{$\sum_1$}\\\hline \endhead \hline -\endfoot {% for rv in vysledkovka %} {{ rv.poradi }} & {% if rv.resitel.titul %} \titul{ {{ rv.titul }} } {% endif %} {{rv.resitel.inicial_krestni}} {{rv.resitel.prijmeni}} & {{ rv.resitel.rocnik |default:"" }} & {{ rv.body_minule }} & {% for b in rv.body_ulohy %}{{ b }} & {% endfor %} {{ rv.body_celkem_rocnik |default:0 }} & {{ rv.body_celkem_minule }} \\ -{% endfor %}\end{longtable} +\endfoot +{% for rv in vysledkovka %}{{rv.poradi}}&{% if rv.titul %}\titul{ {{ rv.titul}}}{% endif %}{{rv.resitel.inicial_krestni}}{{rv.resitel.prijmeni}}&{{rv.resitel.rocnik|default:""}}&{{rv.body_celkem_odjakziva}}&{% for b in rv.body_ulohy %}{{b}}&{% endfor %}{{rv.body_cislo}}&{{rv.body_celkem_rocnik|default:0}}\\ +{% endfor %} +\end{longtable} diff --git a/seminar/views.py b/seminar/views.py index 54ed3e11..5a11f42a 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -294,6 +294,7 @@ class CisloView(generic.DetailView): v.poradi = poradi v.body_celkem_rocnik = v.body v.body_celkem_odjakziva = VysledkyKCisluOdjakziva.objects.get(resitel=v.resitel, cislo=context['cislo']).body + v.resitel.rocnik = v.resitel.rocnik(v.cislo.rocnik) # je tady '', aby se nezobrazovala 0, pokud se řešitel o řešení úlohy ani nepokusil v.body_ulohy = [''] * len(problemy) From 7196b5512dfc9a5514be9655c6addf39b4191004 Mon Sep 17 00:00:00 2001 From: Aneta Date: Tue, 8 Dec 2015 14:43:37 +0100 Subject: [PATCH 19/21] Snad uz finalni oprava vysledkovky. A. --- seminar/templates/seminar/archiv/cislo_vysledkovka.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seminar/templates/seminar/archiv/cislo_vysledkovka.tex b/seminar/templates/seminar/archiv/cislo_vysledkovka.tex index d961d39f..619b30e1 100644 --- a/seminar/templates/seminar/archiv/cislo_vysledkovka.tex +++ b/seminar/templates/seminar/archiv/cislo_vysledkovka.tex @@ -1,6 +1,6 @@ \setlength{\tabcolsep}{3pt} \begin{longtable}{|r|l|c|r|{% for p in problemy %}c@{\hskip.5em}{% endfor %}|r|r|}\hline -&&&&\multicolumn{ {{ problemy|length}} }{c|}{\textbf{Úlohy}}&&\\\textbf{Poř.}&\textbf{Jméno}&\textbf{R.}&\raisebox{0.7mm}{$\sum_{-1}$}&{% for p in problemy %}{% if p.typ == "uloha" %}\textbf{r{{p.kod}}}&{% elif p.typ = "tema" %}\textbf{t{{p.kod}}}&{% else %}\textbf{ {{p.kod}} }&{% endif %}{% endfor %}\raisebox{0.7mm}{$\sum_0$}&\raisebox{0.7mm}{$\sum_1$}\\\hline +& & & & \multicolumn{ {{ problemy|length}} }{c|}{\textbf{Úlohy}} & & \\\textbf{Poř.}& \textbf{Jméno}& \textbf{R.}& \raisebox{0.7mm}{$\sum_{-1}$}& {% for p in problemy %}{% if p.typ == "uloha" %}\textbf{r{{p.kod}}}&{% elif p.typ = "tema" %}\textbf{t{{p.kod}}}&{% else %}\textbf{ {{p.kod}} }&{% endif %}{% endfor %}\raisebox{0.7mm}{$\sum_0$}&\raisebox{0.7mm}{$\sum_1$}\\\hline \endhead \hline \endfoot From c1c71c3073889f194e85ca7d52da019b27ce7b1d Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Wed, 9 Dec 2015 14:34:07 +0100 Subject: [PATCH 20/21] Aktualni zadani | Upravy v zobrazeni 1) Nezverejnuj nezverejnene ulohy 2) Pro organizatory zverejnuj nezverejnene ulohy --- .../seminar/zadani/AktualniVysledkovka.html | 2 +- .../templates/seminar/zadani/AktualniZadani.html | 15 +++++++++++++-- seminar/views.py | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/seminar/templates/seminar/zadani/AktualniVysledkovka.html b/seminar/templates/seminar/zadani/AktualniVysledkovka.html index 9996b567..8e0898ca 100644 --- a/seminar/templates/seminar/zadani/AktualniVysledkovka.html +++ b/seminar/templates/seminar/zadani/AktualniVysledkovka.html @@ -19,7 +19,7 @@ {% if vysledkovka %} {% include "seminar/vysledkovka_rocnik.html" %} {% else %} - V tomto ročníku zatím žádné výsledky nejsou + V tomto ročníku zatím žádné výsledky nejsou. {% endif %} {% if user.is_staff and vysledkovka_s_neverejnymi %} diff --git a/seminar/templates/seminar/zadani/AktualniZadani.html b/seminar/templates/seminar/zadani/AktualniZadani.html index ff6c3cd3..a9f84a64 100644 --- a/seminar/templates/seminar/zadani/AktualniZadani.html +++ b/seminar/templates/seminar/zadani/AktualniZadani.html @@ -13,7 +13,11 @@ {% block content %}
- {% with nastaveni.aktualni_cislo as ac %} +{% with nastaveni.aktualni_cislo as ac %} + +{# Zobrazovani neverejnych zadani jen organizatorum #} +{% if user.is_staff or verejne %} +{% if user.is_staff and not verejne %}
{% endif %} {% if ac.zadane_problemy.all %}
@@ -45,6 +49,12 @@ Aktuálně nejsou zadané žádné úlohy k řešení. {% endfor %} +{% if user.is_staff and not verejne%}
{% endif %} +{% else %} +

Aktuálně nejsou zveřejněny žádné úlohy

+{% endif %} + +

Témata

    {% for problem in temata %} @@ -56,7 +66,8 @@ Aktuálně nejsou zadána žádná témata k řešení. {% endfor %}
- {% endwith %} + +{% endwith %}
{% endblock content %} diff --git a/seminar/views.py b/seminar/views.py index bc43d6fc..4bef203a 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -30,6 +30,7 @@ def verejna_temata(rocnik): def AktualniZadaniView(request): nastaveni = get_object_or_404(Nastaveni) + verejne = nastaveni.aktualni_cislo.verejne() problemy = Problem.objects.filter(cislo_zadani=nastaveni.aktualni_cislo).filter(stav = 'zadany') ulohy = problemy.filter(typ = 'uloha').order_by('kod') serialy = problemy.filter(typ = 'serial').order_by('kod') @@ -38,6 +39,7 @@ def AktualniZadaniView(request): {'nastaveni': nastaveni, 'jednorazove_problemy': jednorazove_problemy, 'temata': verejna_temata(nastaveni.aktualni_rocnik), + 'verejne': verejne, }, ) From d6b419f03755ff4ecc880a54e5c305852e765bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Sun, 13 Dec 2015 21:46:44 +0100 Subject: [PATCH 21/21] =?UTF-8?q?CKEditor:=20opraveno=20nastaven=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/settings_common.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index d48a0938..67072e59 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -157,6 +157,7 @@ CKEDITOR_IMAGE_BACKEND = 'pillow' #CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js' CKEDITOR_CONFIGS = { 'default': { + 'entities': False, 'toolbar': [ ['Source', 'ShowBlocks', '-', 'Maximize'], ['Bold', 'Italic', 'Subscript', 'Superscript', '-', 'RemoveFormat'], @@ -235,12 +236,3 @@ LOGGING = { # MaM specific SEMINAR_RESENI_DIR = os.path.join(BASE_DIR, 'media', 'reseni') - - -CKEDITOR_CONFIGS = { - 'default': { - 'entities': False - } -} - -