|
@ -308,82 +308,137 @@ class ArchivView(generic.ListView): |
|
|
def get_context_data(self, **kwargs): |
|
|
def get_context_data(self, **kwargs): |
|
|
context = super(ArchivView, self).get_context_data(**kwargs) |
|
|
context = super(ArchivView, self).get_context_data(**kwargs) |
|
|
|
|
|
|
|
|
vyska = 297 # px |
|
|
vyska = 594 # px |
|
|
sirka = 210 # px |
|
|
sirka = 420 # 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)] |
|
|
# slovník {(ročník, url obrázku)} |
|
|
urls = [] |
|
|
urls ={} |
|
|
|
|
|
|
|
|
for i, c in enumerate(cisla): |
|
|
# for j, rocnik in enumerate(Rocnik.objects.all()): |
|
|
if not c.pdf: |
|
|
# urls_rocnik = {} |
|
|
continue |
|
|
# for i,c in enumerate(rocnik.cisla.all()): |
|
|
filename = os.path.split(c.pdf.file.name)[1].split(".")[0] |
|
|
# if not c.pdf: |
|
|
png_filename = "{}-{}px.png".format(filename, vyska) |
|
|
# urls_rocnik[c.poradi] = op.join(settings.MEDIA_URL, "cislo", "png", "default.png") |
|
|
|
|
|
# else: |
|
|
# Pokud obrázek neexistuje nebo není aktuální, vytvoř jej |
|
|
# filename = os.path.split(c.pdf.file.name)[1].split(".")[0] |
|
|
png_path = op.join(png_dir, png_filename) |
|
|
# png_filename = "{}.png".format(filename) |
|
|
if not op.exists(png_path) or \ |
|
|
|
|
|
op.getmtime(png_path) < op.getmtime(c.pdf.path): |
|
|
# # Pokud obrázek neexistuje nebo není aktuální, vytvoř jej |
|
|
|
|
|
# png_path = op.join(png_dir, png_filename) |
|
|
subprocess.call([ |
|
|
# if not op.exists(png_path) or \ |
|
|
"convert", |
|
|
# op.getmtime(png_path) < op.getmtime(c.pdf.path): |
|
|
"-density", "300x300", |
|
|
|
|
|
"-geometry", "{}x{}".format(vyska, sirka), |
|
|
# subprocess.call([ |
|
|
"-background", "white", |
|
|
# "convert", |
|
|
"-flatten", |
|
|
# "-density", "300x300", |
|
|
"-rotate", str(90 * i), |
|
|
# "-geometry", "{}x{}".format(vyska, sirka), |
|
|
"{}[0]".format(c.pdf.path), # titulní strana |
|
|
# "-background", "white", |
|
|
png_path |
|
|
# "-flatten", |
|
|
]) |
|
|
# "{}[0]".format(c.pdf.path), # titulní strana |
|
|
|
|
|
# png_path |
|
|
urls.append( |
|
|
# ]) |
|
|
(op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) |
|
|
|
|
|
) |
|
|
# urls_rocnik[c.poradi] = op.join(settings.MEDIA_URL, "cislo", "png", png_filename) |
|
|
vyska, sirka = sirka, vyska / 2 |
|
|
# urls[rocnik] = urls_rocnik |
|
|
|
|
|
|
|
|
tags = [] |
|
|
for i,c in enumerate(cisla): |
|
|
|
|
|
if not c.pdf: |
|
|
def spirala(urls, tags, idx): |
|
|
urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", "default.png") |
|
|
"""Rekurzivně prochází urls a generuje strom elementů do tags""" |
|
|
else: |
|
|
if idx >= len(urls): |
|
|
filename = os.path.split(c.pdf.file.name)[1].split(".")[0] |
|
|
return |
|
|
png_filename = "{}.png".format(filename) |
|
|
|
|
|
|
|
|
img_url, cislo = urls[idx] |
|
|
# Pokud obrázek neexistuje nebo není aktuální, vytvoř jej |
|
|
tags.append( |
|
|
png_path = op.join(png_dir, png_filename) |
|
|
"<div style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
if not op.exists(png_path) or \ |
|
|
.format( |
|
|
op.getmtime(png_path) < op.getmtime(c.pdf.path): |
|
|
50 if idx % 4 == 2 else 0, |
|
|
|
|
|
50 if idx % 4 == 1 else 0, |
|
|
subprocess.call([ |
|
|
50 if idx % 2 == 1 else 100, |
|
|
"convert", |
|
|
50 if idx > 0 and idx % 2 == 0 else 100 |
|
|
"-density", "300x300", |
|
|
) |
|
|
"-geometry", "{}x{}".format(vyska, sirka), |
|
|
) |
|
|
"-background", "white", |
|
|
tags.append("<a href='{}' title='{}'>".format( |
|
|
"-flatten", |
|
|
cislo.verejne_url(), cislo.kod() |
|
|
"{}[0]".format(c.pdf.path), # titulní strana |
|
|
)) |
|
|
png_path |
|
|
tags.append( |
|
|
]) |
|
|
"<img src='{}' style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
|
|
|
.format( |
|
|
urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", png_filename) |
|
|
img_url, |
|
|
|
|
|
50 if idx % 4 == 3 else 0, |
|
|
context["object_list"] = urls |
|
|
50 if idx % 4 == 2 else 0, |
|
|
|
|
|
50 if idx % 2 == 0 else 100, |
|
|
print(context) |
|
|
50 if idx % 2 == 1 else 100 |
|
|
|
|
|
) |
|
|
# for i, c in enumerate(cisla): |
|
|
) |
|
|
# if not c.pdf: |
|
|
tags.append("</a>") |
|
|
# continue |
|
|
spirala(urls, tags, idx + 1) |
|
|
# filename = os.path.split(c.pdf.file.name)[1].split(".")[0] |
|
|
tags.append("</div>") |
|
|
# png_filename = "{}-{}px.png".format(filename, vyska) |
|
|
spirala(urls, tags, 0) |
|
|
|
|
|
|
|
|
# # Pokud obrázek neexistuje nebo není aktuální, vytvoř jej |
|
|
context["nahledy"] = "\n".join(tags) |
|
|
# png_path = op.join(png_dir, png_filename) |
|
|
|
|
|
# if not op.exists(png_path) or \ |
|
|
|
|
|
# op.getmtime(png_path) < op.getmtime(c.pdf.path): |
|
|
|
|
|
|
|
|
|
|
|
# subprocess.call([ |
|
|
|
|
|
# "convert", |
|
|
|
|
|
# "-density", "300x300", |
|
|
|
|
|
# "-geometry", "{}x{}".format(vyska, sirka), |
|
|
|
|
|
# "-background", "white", |
|
|
|
|
|
# "-flatten", |
|
|
|
|
|
# "-rotate", str(90 * i), |
|
|
|
|
|
# "{}[0]".format(c.pdf.path), # titulní strana |
|
|
|
|
|
# png_path |
|
|
|
|
|
# ]) |
|
|
|
|
|
|
|
|
|
|
|
# urls.append( |
|
|
|
|
|
# (op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) |
|
|
|
|
|
# ) |
|
|
|
|
|
# vyska, sirka = sirka, vyska / 2 |
|
|
|
|
|
|
|
|
|
|
|
# tags = [] |
|
|
|
|
|
|
|
|
|
|
|
# def spirala(urls, tags, idx): |
|
|
|
|
|
# """Rekurzivně prochází urls a generuje strom elementů do tags""" |
|
|
|
|
|
# if idx >= len(urls): |
|
|
|
|
|
# return |
|
|
|
|
|
|
|
|
|
|
|
# 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) |
|
|
|
|
|
|
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
### Výsledky |
|
|
### Výsledky |
|
|