Archiv: náhledy – připomínky od Jethra a Anet
This commit is contained in:
		
							parent
							
								
									1a4fd15423
								
							
						
					
					
						commit
						7780ef34ff
					
				
					 3 changed files with 68 additions and 12 deletions
				
			
		|  | @ -698,3 +698,7 @@ div.nahledy_cisel { | |||
| div.nahledy_cisel div, div.nahledy_cisel img { | ||||
|     position: absolute; | ||||
| } | ||||
| 
 | ||||
| div.nahledy_cisel_radek img { | ||||
|     margin: 3px 3px 6px 0px; | ||||
| } | ||||
|  |  | |||
|  | @ -20,6 +20,25 @@ | |||
|     {% endfor %} | ||||
|   </ul> | ||||
| 
 | ||||
|   <div style='margin-top:300px'> | ||||
|   <ul> | ||||
|     {% for c in cisla %} | ||||
|       {% ifchanged c.rocnik %} | ||||
|         {% if not forloop.first %} | ||||
|           </div> | ||||
|         {% endif %} | ||||
|         <li><a href='{{ c.rocnik.verejne_url }}'>Ročník {{ c.rocnik }}</a> | ||||
|         <div class='nahledy_cisel_radek'> | ||||
|       {% endifchanged %} | ||||
|         <a href='{{ c.verejne_url }}' title='{{ c.kod }}'> | ||||
|           <img src='{{ www_png_dir }}/{{ c.rocnik.rocnik }}-{{ c.cislo }}.png'> | ||||
|         </a> | ||||
|     {% empty %} | ||||
|       Nejsou žádné ročníky | ||||
|     {% endfor %} | ||||
|   </ul> | ||||
|   </div> | ||||
| 
 | ||||
| </div> | ||||
| {% endblock content %} | ||||
| 
 | ||||
|  |  | |||
|  | @ -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,21 +195,28 @@ class ArchivView(generic.ListView): | |||
|             filename = os.path.split(c.pdf.file.name)[1].split(".")[0] | ||||
|             png_filename = "{}-{}px.png".format(filename, vyska) | ||||
| 
 | ||||
|             def vytvor_obrazek_titulky(strana, pdf_path, png_path, rotace=0): | ||||
|                 subprocess.call([ | ||||
|                     "convert", | ||||
|                     "-density", "180x180", | ||||
|                     "-geometry", "{}x{}".format(strana, strana), | ||||
|                     "-background", "white", | ||||
|                     "-flatten", | ||||
|                     "-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): | ||||
| 
 | ||||
|                 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 | ||||
|                 ]) | ||||
|                 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 | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Matěj Kocián
						Matěj Kocián