|
@ -178,13 +178,10 @@ class ArchivView(generic.ListView): |
|
|
|
|
|
|
|
|
vyska = 297 # px |
|
|
vyska = 297 # px |
|
|
sirka = 210 # px |
|
|
sirka = 210 # px |
|
|
sirka_paddingu = 3 # px |
|
|
|
|
|
|
|
|
|
|
|
cisla = Cislo.objects.filter(verejne_db=True)[:10] |
|
|
cisla = Cislo.objects.filter(verejne_db=True)[:10] |
|
|
|
|
|
|
|
|
png_dir = op.join(settings.MEDIA_ROOT, "cislo", "png") |
|
|
png_dir = op.join(settings.MEDIA_ROOT, "cislo", "png") |
|
|
if not op.isdir(png_dir): |
|
|
|
|
|
os.makedirs(png_dir) |
|
|
|
|
|
|
|
|
|
|
|
# seznam [(url obrázku, číslo)] |
|
|
# seznam [(url obrázku, číslo)] |
|
|
urls = [] |
|
|
urls = [] |
|
@ -195,29 +192,22 @@ class ArchivView(generic.ListView): |
|
|
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 = "{}-{}px.png".format(filename, vyska) |
|
|
|
|
|
|
|
|
def vytvor_obrazek_titulky(strana, pdf_path, png_path, rotace=0): |
|
|
# 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([ |
|
|
subprocess.call([ |
|
|
"convert", |
|
|
"convert", |
|
|
"-density", "180x180", |
|
|
"-density", "180x180", |
|
|
"-geometry", "{}x{}".format(strana, strana), |
|
|
"-geometry", "{}x{}".format(vyska, vyska), |
|
|
"-background", "white", |
|
|
"-background", "white", |
|
|
"-flatten", |
|
|
"-flatten", |
|
|
"-rotate", str(rotace), |
|
|
"-rotate", str(90 * i), |
|
|
"{}[0]".format(pdf_path), # titulní strana |
|
|
"{}[0]".format(c.pdf.path), # titulní strana |
|
|
png_path |
|
|
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( |
|
|
urls.append( |
|
|
(op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) |
|
|
(op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) |
|
|
) |
|
|
) |
|
@ -244,11 +234,9 @@ class ArchivView(generic.ListView): |
|
|
cislo.verejne_url(), cislo.kod() |
|
|
cislo.verejne_url(), cislo.kod() |
|
|
)) |
|
|
)) |
|
|
tags.append( |
|
|
tags.append( |
|
|
"<img src='{}' style=" |
|
|
"<img src='{}' style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
"'padding:{}px;top:{}%;left:{}%;width:{}%;height:{}%;'>" |
|
|
|
|
|
.format( |
|
|
.format( |
|
|
img_url, |
|
|
img_url, |
|
|
sirka_paddingu, |
|
|
|
|
|
50 if idx % 4 == 3 else 0, |
|
|
50 if idx % 4 == 3 else 0, |
|
|
50 if idx % 4 == 2 else 0, |
|
|
50 if idx % 4 == 2 else 0, |
|
|
50 if idx % 2 == 0 else 100, |
|
|
50 if idx % 2 == 0 else 100, |
|
@ -260,28 +248,7 @@ class ArchivView(generic.ListView): |
|
|
tags.append("</div>") |
|
|
tags.append("</div>") |
|
|
spirala(urls, tags, 0) |
|
|
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["nahledy"] = "\n".join(tags) |
|
|
context["cisla"] = cisla |
|
|
|
|
|
context["www_png_dir"] = www_png_dir |
|
|
|
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|