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 { | div.nahledy_cisel div, div.nahledy_cisel img { | ||||||
|     position: absolute; |     position: absolute; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | div.nahledy_cisel_radek img { | ||||||
|  |     margin: 3px 3px 6px 0px; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -20,6 +20,25 @@ | ||||||
|     {% endfor %} |     {% endfor %} | ||||||
|   </ul> |   </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> | </div> | ||||||
| {% endblock content %} | {% endblock content %} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -178,10 +178,13 @@ 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 = [] | ||||||
|  | @ -192,21 +195,28 @@ 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): | ||||||
|  |                 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 |             # Pokud obrázek neexistuje nebo není aktuální, vytvoř jej | ||||||
|             png_path = op.join(png_dir, png_filename) |             png_path = op.join(png_dir, png_filename) | ||||||
|             if not op.exists(png_path) or \ |             if not op.exists(png_path) or \ | ||||||
|                     op.getmtime(png_path) < op.getmtime(c.pdf.path): |                     op.getmtime(png_path) < op.getmtime(c.pdf.path): | ||||||
| 
 |                 vytvor_obrazek_titulky( | ||||||
|                 subprocess.call([ |                     vyska - sirka_paddingu, | ||||||
|                     "convert", |                     c.pdf.path, | ||||||
|                     "-density", "180x180", |                     png_path, | ||||||
|                     "-geometry", "{}x{}".format(vyska, vyska), |                     rotace=i * 90 | ||||||
|                     "-background", "white", |                 ) | ||||||
|                     "-flatten", |  | ||||||
|                     "-rotate", str(90 * i), |  | ||||||
|                     "{}[0]".format(c.pdf.path),  # titulní strana |  | ||||||
|                     png_path |  | ||||||
|                 ]) |  | ||||||
| 
 | 
 | ||||||
|             urls.append( |             urls.append( | ||||||
|                 (op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) |                 (op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c) | ||||||
|  | @ -234,9 +244,11 @@ class ArchivView(generic.ListView): | ||||||
|                 cislo.verejne_url(), cislo.kod() |                 cislo.verejne_url(), cislo.kod() | ||||||
|             )) |             )) | ||||||
|             tags.append( |             tags.append( | ||||||
|                 "<img src='{}' style='top:{}%;left:{}%;width:{}%;height:{}%;'>" |                 "<img src='{}' style=" | ||||||
|  |                 "'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, | ||||||
|  | @ -248,7 +260,28 @@ 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 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Matěj Kocián
						Matěj Kocián