|
@ -308,81 +308,17 @@ 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 = 594 # px |
|
|
|
|
|
sirka = 420 # px |
|
|
|
|
|
|
|
|
|
|
|
# první číslo z každého ročníku |
|
|
|
|
|
cisla = Cislo.objects.filter(poradi=1) |
|
|
cisla = Cislo.objects.filter(poradi=1) |
|
|
|
|
|
|
|
|
# op == os.path, udělá z argumentů cestu |
|
|
|
|
|
png_dir = op.join(settings.MEDIA_ROOT, "cislo", "png") |
|
|
|
|
|
|
|
|
|
|
|
# slovník {(ročník, url obrázku)} |
|
|
|
|
|
urls ={} |
|
|
urls ={} |
|
|
|
|
|
|
|
|
for i, c in enumerate(cisla): |
|
|
for i, c in enumerate(cisla): |
|
|
if not c.pdf: |
|
|
if c.titulka_nahled: |
|
|
urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", "default.png") |
|
|
urls[c.rocnik] = c.titulka_nahled.url |
|
|
else: |
|
|
else: |
|
|
filename = os.path.split(c.pdf.file.name)[1].split(".")[0] |
|
|
urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", "default.png") |
|
|
png_filename = "{}.png".format(filename) |
|
|
|
|
|
|
|
|
|
|
|
# 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): |
|
|
|
|
|
|
|
|
|
|
|
subprocess.call([ |
|
|
|
|
|
"convert", |
|
|
|
|
|
"-density", "300x300", |
|
|
|
|
|
"-geometry", "{}x{}".format(vyska, sirka), |
|
|
|
|
|
"-background", "white", |
|
|
|
|
|
"-flatten", |
|
|
|
|
|
"{}[0]".format(c.pdf.path), # titulní strana |
|
|
|
|
|
png_path |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", png_filename) |
|
|
|
|
|
|
|
|
|
|
|
context["object_list"] = urls |
|
|
context["object_list"] = urls |
|
|
|
|
|
|
|
|
print(context) |
|
|
|
|
|
|
|
|
|
|
|
# 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 |
|
|