Archiv: náhledy posledních čísel vedle ročníků
This commit is contained in:
parent
ea0f03d27f
commit
1a4fd15423
4 changed files with 99 additions and 3 deletions
|
@ -685,3 +685,16 @@ div.novinka_obrazek {
|
|||
div.org-text {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
div.nahledy_cisel {
|
||||
float: right;
|
||||
height: 297px;
|
||||
width: 420px;
|
||||
position: relative;
|
||||
margin-right: 10%;
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
|
||||
div.nahledy_cisel div, div.nahledy_cisel img {
|
||||
position: absolute;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
{% endblock %}{% endblock %}
|
||||
</h2>
|
||||
|
||||
<div class='nahledy_cisel'>
|
||||
{% autoescape off %}{{ nahledy }}{% endautoescape %}
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
{% for r in object_list %}
|
||||
<li><a href='{{ r.verejne_url }}'>Ročník {{ r }}</a>
|
||||
|
@ -16,7 +20,6 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ urlpatterns = [
|
|||
url(r'^co-je-MaM/organizatori/organizovali/$', views.CojemamOrganizatoriStariView.as_view(), name='stari_organizatori'),
|
||||
|
||||
# Archiv
|
||||
url(r'^archiv/cisla/$', views.CislaView.as_view()),
|
||||
url(r'^archiv/cisla/$', views.ArchivView.as_view()),
|
||||
url(r'^archiv/temata/$', views.ArchivTemataView.as_view()),
|
||||
|
||||
url(r'^rocnik/(?P<rocnik>\d+)/$', views.RocnikView.as_view(), name='seminar_rocnik'),
|
||||
|
|
|
@ -22,6 +22,7 @@ import tempfile
|
|||
import subprocess
|
||||
import shutil
|
||||
import os
|
||||
import os.path as op
|
||||
from django.conf import settings
|
||||
import unicodedata
|
||||
import json
|
||||
|
@ -167,10 +168,89 @@ class CojemamOrganizatoriStariView(generic.ListView):
|
|||
|
||||
### Archiv
|
||||
|
||||
class CislaView(generic.ListView):
|
||||
|
||||
class ArchivView(generic.ListView):
|
||||
model = Rocnik
|
||||
template_name='seminar/archiv/cisla.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ArchivView, self).get_context_data(**kwargs)
|
||||
|
||||
vyska = 297 # px
|
||||
sirka = 210 # px
|
||||
|
||||
cisla = Cislo.objects.filter(verejne_db=True)[:10]
|
||||
|
||||
png_dir = op.join(settings.MEDIA_ROOT, "cislo", "png")
|
||||
|
||||
# seznam [(url obrázku, číslo)]
|
||||
urls = []
|
||||
|
||||
for i, c in enumerate(cisla):
|
||||
if not c.pdf:
|
||||
continue
|
||||
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):
|
||||
|
||||
subprocess.call([
|
||||
"convert",
|
||||
"-density", "180x180",
|
||||
"-geometry", "{}x{}".format(vyska, vyska),
|
||||
"-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
|
||||
|
||||
|
||||
def sloupec_s_poradim(vysledky):
|
||||
# počet řešitelů ve výsledkovce nad aktuálním
|
||||
|
|
Loading…
Reference in a new issue