pokusy s archivem, pokouším se do kontextu k ročníku přidat cestu k png 1. čísla, teď to nefunguje
This commit is contained in:
		
							parent
							
								
									2a347d988f
								
							
						
					
					
						commit
						732a2273db
					
				
					 2 changed files with 94 additions and 60 deletions
				
			
		|  | @ -15,6 +15,7 @@ | |||
|   <ul> | ||||
|     {% for r in object_list %} | ||||
|     <li><a href='{{ r.verejne_url }}'>Ročník {{ r }}</a> | ||||
|       <img src="{{ object_list.r }}" alt=""> | ||||
|     {% empty %} | ||||
|       Nejsou žádné ročníky | ||||
|     {% endfor %} | ||||
|  | @ -22,4 +23,3 @@ | |||
| 
 | ||||
| </div> | ||||
| {% endblock content %} | ||||
| 
 | ||||
|  |  | |||
|  | @ -311,21 +311,24 @@ class ArchivView(generic.ListView): | |||
| 		vyska = 297  # px | ||||
| 		sirka = 210  # px | ||||
| 
 | ||||
| 		# nejnovějších 10 zveřejněných čísel | ||||
| 		# cisla = Cislo.objects.filter(verejne_db=True)[:10] | ||||
| 		cisla = Cislo.objects.filter(poradi=1)[:10]		 | ||||
| 		# první číslo z každého ročníku | ||||
| 		cisla = Cislo.objects.filter(poradi=1)	 | ||||
| 
 | ||||
| 		# op == os.path, udělá z argumentů cestu | ||||
| 		png_dir = op.join(settings.MEDIA_ROOT, "cislo", "png") | ||||
| 
 | ||||
| 		# seznam [(url obrázku, číslo)] | ||||
| 		urls = [] | ||||
| 		urls ={} | ||||
| 
 | ||||
| 		for i, c in enumerate(cisla): | ||||
| 		for i,c in enumerate(cisla): | ||||
| 			if not c.pdf: | ||||
| 				continue | ||||
| 				urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", "default.png") | ||||
| 				# urls.append( | ||||
| 				# 	(op.join(settings.MEDIA_URL, "cislo", "png", "default.png"), c.rocnik) | ||||
| 				# ) | ||||
| 			else: | ||||
| 				filename = os.path.split(c.pdf.file.name)[1].split(".")[0] | ||||
| 			png_filename = "{}-{}px.png".format(filename, vyska) | ||||
| 				png_filename = "{}.png".format(filename) | ||||
| 
 | ||||
| 				# Pokud obrázek neexistuje nebo není aktuální, vytvoř jej | ||||
| 				png_path = op.join(png_dir, png_filename) | ||||
|  | @ -338,52 +341,83 @@ class ArchivView(generic.ListView): | |||
| 						"-geometry", "{}x{}".format(vyska, sirka), | ||||
| 						"-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 | ||||
| 				urls[c.rocnik] = op.join(settings.MEDIA_URL, "cislo", "png", png_filename) | ||||
| 				#urls.append( | ||||
| 					#(op.join(settings.MEDIA_URL, "cislo", "png", png_filename), c.rocnik) | ||||
| 				#) | ||||
| 
 | ||||
| 		tags = [] | ||||
| 		context["object_list"] = urls | ||||
| 
 | ||||
| 		def spirala(urls, tags, idx): | ||||
| 			"""Rekurzivně prochází urls a generuje strom elementů do tags""" | ||||
| 			if idx >= len(urls): | ||||
| 				return | ||||
| 		# 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) | ||||
| 
 | ||||
| 			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) | ||||
| 		# 	# 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): | ||||
| 
 | ||||
| 		context["nahledy"] = "\n".join(tags) | ||||
| 		# 		subprocess.call([ | ||||
| 		# 			"convert", | ||||
| 		# 			"-density", "300x300", | ||||
| 		# 			"-geometry", "{}x{}".format(vyska, sirka), | ||||
| 		# 			"-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) | ||||
| 		print(context) | ||||
| 		for i in context["object_list"]: | ||||
| 			print(context["object_list"][i]) | ||||
| 		return context | ||||
| 
 | ||||
| ### Výsledky | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Kateřina Čížková
						Kateřina Čížková