|
@ -311,21 +311,24 @@ class ArchivView(generic.ListView): |
|
|
vyska = 297 # px |
|
|
vyska = 297 # px |
|
|
sirka = 210 # px |
|
|
sirka = 210 # px |
|
|
|
|
|
|
|
|
# nejnovějších 10 zveřejněných čísel |
|
|
# první číslo z každého ročníku |
|
|
# cisla = Cislo.objects.filter(verejne_db=True)[:10] |
|
|
cisla = Cislo.objects.filter(poradi=1) |
|
|
cisla = Cislo.objects.filter(poradi=1)[:10] |
|
|
|
|
|
|
|
|
|
|
|
# op == os.path, udělá z argumentů cestu |
|
|
# op == os.path, udělá z argumentů cestu |
|
|
png_dir = op.join(settings.MEDIA_ROOT, "cislo", "png") |
|
|
png_dir = op.join(settings.MEDIA_ROOT, "cislo", "png") |
|
|
|
|
|
|
|
|
# seznam [(url obrázku, číslo)] |
|
|
# seznam [(url obrázku, číslo)] |
|
|
urls = [] |
|
|
urls ={} |
|
|
|
|
|
|
|
|
for i, c in enumerate(cisla): |
|
|
for i,c in enumerate(cisla): |
|
|
if not c.pdf: |
|
|
if not c.pdf: |
|
|
continue |
|
|
urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", "default.png") |
|
|
|
|
|
# urls.append( |
|
|
|
|
|
# (op.join(settings.MEDIA_URL, "cislo", "png", "default.png"), c.rocnik) |
|
|
|
|
|
# ) |
|
|
|
|
|
else: |
|
|
filename = os.path.split(c.pdf.file.name)[1].split(".")[0] |
|
|
filename = os.path.split(c.pdf.file.name)[1].split(".")[0] |
|
|
png_filename = "{}-{}px.png".format(filename, vyska) |
|
|
png_filename = "{}.png".format(filename) |
|
|
|
|
|
|
|
|
# Pokud obrázek neexistuje nebo není aktuální, vytvoř jej |
|
|
# Pokud obrázek neexistuje nebo není aktuální, vytvoř jej |
|
|
png_path = op.join(png_dir, png_filename) |
|
|
png_path = op.join(png_dir, png_filename) |
|
@ -338,52 +341,83 @@ class ArchivView(generic.ListView): |
|
|
"-geometry", "{}x{}".format(vyska, sirka), |
|
|
"-geometry", "{}x{}".format(vyska, sirka), |
|
|
"-background", "white", |
|
|
"-background", "white", |
|
|
"-flatten", |
|
|
"-flatten", |
|
|
"-rotate", str(90 * i), |
|
|
|
|
|
"{}[0]".format(c.pdf.path), # titulní strana |
|
|
"{}[0]".format(c.pdf.path), # titulní strana |
|
|
png_path |
|
|
png_path |
|
|
]) |
|
|
]) |
|
|
|
|
|
|
|
|
urls.append( |
|
|
urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", png_filename) |
|
|
(op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) |
|
|
#urls.append( |
|
|
) |
|
|
#(op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c.rocnik) |
|
|
vyska, sirka = sirka, vyska / 2 |
|
|
#) |
|
|
|
|
|
|
|
|
tags = [] |
|
|
context["object_list"] = urls |
|
|
|
|
|
|
|
|
def spirala(urls, tags, idx): |
|
|
# for i, c in enumerate(cisla): |
|
|
"""Rekurzivně prochází urls a generuje strom elementů do tags""" |
|
|
# if not c.pdf: |
|
|
if idx >= len(urls): |
|
|
# continue |
|
|
return |
|
|
# filename = os.path.split(c.pdf.file.name)[1].split(".")[0] |
|
|
|
|
|
# png_filename = "{}-{}px.png".format(filename, vyska) |
|
|
img_url, cislo = urls[idx] |
|
|
|
|
|
tags.append( |
|
|
# # Pokud obrázek neexistuje nebo není aktuální, vytvoř jej |
|
|
"<div style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
# png_path = op.join(png_dir, png_filename) |
|
|
.format( |
|
|
# if not op.exists(png_path) or \ |
|
|
50 if idx % 4 == 2 else 0, |
|
|
# op.getmtime(png_path) < op.getmtime(c.pdf.path): |
|
|
50 if idx % 4 == 1 else 0, |
|
|
|
|
|
50 if idx % 2 == 1 else 100, |
|
|
# subprocess.call([ |
|
|
50 if idx > 0 and idx % 2 == 0 else 100 |
|
|
# "convert", |
|
|
) |
|
|
# "-density", "300x300", |
|
|
) |
|
|
# "-geometry", "{}x{}".format(vyska, sirka), |
|
|
tags.append("<a href='{}' title='{}'>".format( |
|
|
# "-background", "white", |
|
|
cislo.verejne_url(), cislo.kod() |
|
|
# "-flatten", |
|
|
)) |
|
|
# "-rotate", str(90 * i), |
|
|
tags.append( |
|
|
# "{}[0]".format(c.pdf.path), # titulní strana |
|
|
"<img src='{}' style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
# png_path |
|
|
.format( |
|
|
# ]) |
|
|
img_url, |
|
|
|
|
|
50 if idx % 4 == 3 else 0, |
|
|
# urls.append( |
|
|
50 if idx % 4 == 2 else 0, |
|
|
# (op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) |
|
|
50 if idx % 2 == 0 else 100, |
|
|
# ) |
|
|
50 if idx % 2 == 1 else 100 |
|
|
# vyska, sirka = sirka, vyska / 2 |
|
|
) |
|
|
|
|
|
) |
|
|
# tags = [] |
|
|
tags.append("</a>") |
|
|
|
|
|
spirala(urls, tags, idx + 1) |
|
|
# def spirala(urls, tags, idx): |
|
|
tags.append("</div>") |
|
|
# """Rekurzivně prochází urls a generuje strom elementů do tags""" |
|
|
spirala(urls, tags, 0) |
|
|
# if idx >= len(urls): |
|
|
|
|
|
# return |
|
|
context["nahledy"] = "\n".join(tags) |
|
|
|
|
|
|
|
|
# img_url, cislo = urls[idx] |
|
|
|
|
|
# tags.append( |
|
|
|
|
|
# "<div style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
|
|
|
# .format( |
|
|
|
|
|
# 50 if idx % 4 == 2 else 0, |
|
|
|
|
|
# 50 if idx % 4 == 1 else 0, |
|
|
|
|
|
# 50 if idx % 2 == 1 else 100, |
|
|
|
|
|
# 50 if idx > 0 and idx % 2 == 0 else 100 |
|
|
|
|
|
# ) |
|
|
|
|
|
# ) |
|
|
|
|
|
# tags.append("<a href='{}' title='{}'>".format( |
|
|
|
|
|
# cislo.verejne_url(), cislo.kod() |
|
|
|
|
|
# )) |
|
|
|
|
|
# tags.append( |
|
|
|
|
|
# "<img src='{}' style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
|
|
|
# .format( |
|
|
|
|
|
# img_url, |
|
|
|
|
|
# 50 if idx % 4 == 3 else 0, |
|
|
|
|
|
# 50 if idx % 4 == 2 else 0, |
|
|
|
|
|
# 50 if idx % 2 == 0 else 100, |
|
|
|
|
|
# 50 if idx % 2 == 1 else 100 |
|
|
|
|
|
# ) |
|
|
|
|
|
# ) |
|
|
|
|
|
# tags.append("</a>") |
|
|
|
|
|
# spirala(urls, tags, idx + 1) |
|
|
|
|
|
# tags.append("</div>") |
|
|
|
|
|
# spirala(urls, tags, 0) |
|
|
|
|
|
|
|
|
|
|
|
# context["nahledy"] = "\n".join(tags) |
|
|
|
|
|
print(context) |
|
|
|
|
|
for i in context["object_list"]: |
|
|
|
|
|
print(context["object_list"][i]) |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
### Výsledky |
|
|
### Výsledky |
|
|