|
|
@ -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( |
|
|
|
"<img src='{}' style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
|
"<img src='{}' style=" |
|
|
|
"'padding:{}px;top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
|
.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("</div>") |
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|