Hodně oprav
Neumím kódit :-)
This commit is contained in:
		
							parent
							
								
									b37953bc90
								
							
						
					
					
						commit
						70c3ec8b6c
					
				
					 2 changed files with 14 additions and 11 deletions
				
			
		|  | @ -1,14 +1,15 @@ | |||
| from django import template | ||||
| from django.utils.safestring import mark_safe | ||||
| from seminar.utils import TypDeadline, deadline | ||||
| register = template.Library() | ||||
| 
 | ||||
| @register.filter(name='deadline') | ||||
| def deadline_text(datum): | ||||
| 	typ, cislo, deadline = deadline(datum) | ||||
| 	typ, cislo, dl = deadline(datum) | ||||
| 	strings = { | ||||
| 		TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({deadline})", | ||||
| 		TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({deadline})", | ||||
| 		TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({deadline})", | ||||
| 		TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({dl})", | ||||
| 		TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({dl})", | ||||
| 		TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({dl})", | ||||
| 		} | ||||
| 	return strings[typ] | ||||
| 
 | ||||
|  | @ -21,4 +22,4 @@ def deadline_html(datum): | |||
| 		TypDeadline.SousDeadline: 'sous_deadline', | ||||
| 		TypDeadline.FinalDeadline: 'final_deadline', | ||||
| 		} | ||||
| 	return f'<span class="{classes[typ]}">{text}</span>' | ||||
| 	return mark_safe(f'<span class="{classes[typ]}">{text}</span>') | ||||
|  |  | |||
|  | @ -309,7 +309,7 @@ def deadline_v_rocniku(datum, rocnik): | |||
| 			deadliny.append((TypDeadline.FinalDeadline, c, c.datum_deadline)) | ||||
| 	deadliny = sorted(deadliny, key=lambda x: x[2])	# podle data | ||||
| 	for dl in deadliny: | ||||
| 		if datum <= dl: | ||||
| 		if datum <= dl[2]: | ||||
| 			# První takový deadline je ten nejtěsnější | ||||
| 			return dl | ||||
| 
 | ||||
|  | @ -319,20 +319,22 @@ def deadline(datum): | |||
| 	Vrací trojici (TypDeadline, Cislo, datumDeadline: date). | ||||
| 	""" | ||||
| 
 | ||||
| 	if isinstance(datum, datetime.datetime): | ||||
| 		datum = datum.date() | ||||
| 	rok = datum.year | ||||
| 	# Dva ročníky podezřelé z obsahování dat | ||||
| 	pozdejsi_rocnik = m.Rocnik.filter(prvni_rok=rok) | ||||
| 	drivejsi_rocnik = m.Rocnik.filter(druhy_rok=rok) | ||||
| 	if any( | ||||
| 	pozdejsi_rocnik = m.Rocnik.objects.filter(prvni_rok=rok) | ||||
| 	drivejsi_rocnik = m.Rocnik.objects.filter(prvni_rok=rok-1) | ||||
| 	if any([ | ||||
| 			pozdejsi_rocnik.count() > 1, | ||||
| 			drivejsi_rocnik.count() > 1, | ||||
| 			): | ||||
| 			]): | ||||
| 		raise ValueError(f"Více ročníků začíná/končí stejným rokem: {rok}") | ||||
| 	pozdejsi_rocnik = pozdejsi_rocnik.first() if pozdejsi_rocnik.count() > 0 else None | ||||
| 	drivejsi_rocnik = drivejsi_rocnik.first() if drivejsi_rocnik.count() > 0 else None | ||||
| 
 | ||||
| 	# Předpokládáme, že neexistuje číslo, které má deadline ale nemá finální deadline. | ||||
| 	posledni_deadline_drivejsiho_rocniku = m.Cislo.objects.get(rocnik=drivejsi_rocnik, datum_deadline__isnull=False).datum_deadline | ||||
| 	posledni_deadline_drivejsiho_rocniku = m.Cislo.objects.filter(rocnik=drivejsi_rocnik, datum_deadline__isnull=False).last().datum_deadline | ||||
| 
 | ||||
| 	if datum <= posledni_deadline_drivejsiho_rocniku: | ||||
| 		return deadline_v_rocniku(datum, drivejsi_rocnik) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Pavel "LEdoian" Turinsky
						Pavel "LEdoian" Turinsky