From 7780ef34ffb718b0e86fb114755602694c5fce96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Sat, 18 Feb 2017 17:36:36 +0100 Subject: [PATCH] =?UTF-8?q?Archiv:=20n=C3=A1hledy=20=E2=80=93=20p=C5=99ipo?= =?UTF-8?q?m=C3=ADnky=20od=20Jethra=20a=20Anet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/static/css/mamweb.css | 4 ++ seminar/templates/seminar/archiv/cisla.html | 19 ++++++++ seminar/views.py | 51 +++++++++++++++++---- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/mamweb/static/css/mamweb.css b/mamweb/static/css/mamweb.css index 6e5b9488..22f24445 100644 --- a/mamweb/static/css/mamweb.css +++ b/mamweb/static/css/mamweb.css @@ -698,3 +698,7 @@ div.nahledy_cisel { div.nahledy_cisel div, div.nahledy_cisel img { position: absolute; } + +div.nahledy_cisel_radek img { + margin: 3px 3px 6px 0px; +} diff --git a/seminar/templates/seminar/archiv/cisla.html b/seminar/templates/seminar/archiv/cisla.html index 07833aa4..b6f4e376 100644 --- a/seminar/templates/seminar/archiv/cisla.html +++ b/seminar/templates/seminar/archiv/cisla.html @@ -20,6 +20,25 @@ {% endfor %} +
+
+ {% endif %} +
  • Ročník {{ c.rocnik }} +
    + {% endifchanged %} + + + + {% empty %} + Nejsou žádné ročníky + {% endfor %} + +
    + {% endblock content %} diff --git a/seminar/views.py b/seminar/views.py index 4c18c2fe..7f39f3d1 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -178,10 +178,13 @@ class ArchivView(generic.ListView): vyska = 297 # px sirka = 210 # px + sirka_paddingu = 3 # px cisla = Cislo.objects.filter(verejne_db=True)[:10] png_dir = op.join(settings.MEDIA_ROOT, "cislo", "png") + if not op.isdir(png_dir): + os.makedirs(png_dir) # seznam [(url obrázku, číslo)] urls = [] @@ -192,22 +195,29 @@ class ArchivView(generic.ListView): filename = os.path.split(c.pdf.file.name)[1].split(".")[0] png_filename = "{}-{}px.png".format(filename, vyska) - # Pokud obrázek neexistuje nebo není aktuální, vytvoř jej - png_path = op.join(png_dir, png_filename) - if not op.exists(png_path) or \ - op.getmtime(png_path) < op.getmtime(c.pdf.path): - + def vytvor_obrazek_titulky(strana, pdf_path, png_path, rotace=0): subprocess.call([ "convert", "-density", "180x180", - "-geometry", "{}x{}".format(vyska, vyska), + "-geometry", "{}x{}".format(strana, strana), "-background", "white", "-flatten", - "-rotate", str(90 * i), - "{}[0]".format(c.pdf.path), # titulní strana + "-rotate", str(rotace), + "{}[0]".format(pdf_path), # titulní strana png_path ]) + # Pokud obrázek neexistuje nebo není aktuální, vytvoř jej + png_path = op.join(png_dir, png_filename) + if not op.exists(png_path) or \ + op.getmtime(png_path) < op.getmtime(c.pdf.path): + vytvor_obrazek_titulky( + vyska - sirka_paddingu, + c.pdf.path, + png_path, + rotace=i * 90 + ) + urls.append( (op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) ) @@ -234,9 +244,11 @@ class ArchivView(generic.ListView): cislo.verejne_url(), cislo.kod() )) tags.append( - "" + "" .format( img_url, + sirka_paddingu, 50 if idx % 4 == 3 else 0, 50 if idx % 4 == 2 else 0, 50 if idx % 2 == 0 else 100, @@ -248,7 +260,28 @@ class ArchivView(generic.ListView): tags.append("") spirala(urls, tags, 0) + # náhledy v řádcích + + cisla = Cislo.objects.all().select_related("rocnik__rocnik")\ + .order_by("-rocnik__rocnik", "cislo") + for c in cisla: + if not c.pdf: + continue + png_filename_radek = "{}-{}.png".format(c.rocnik.rocnik, c.cislo) + + www_png_dir = op.join(settings.MEDIA_URL, "cislo", "png") + png_path_radek = op.join(png_dir, png_filename_radek) + if not op.exists(png_path_radek) or \ + op.getmtime(png_path_radek) < op.getmtime(c.pdf.path): + vytvor_obrazek_titulky( + 297 // 4, + c.pdf.path, + png_path_radek + ) + context["nahledy"] = "\n".join(tags) + context["cisla"] = cisla + context["www_png_dir"] = www_png_dir return context