Merge branch 'data_migrations' of gimli.ms.mff.cuni.cz:/akce/mam/git/mamweb into data_migrations
This commit is contained in:
		
						commit
						54c85d5fa7
					
				
					 1 changed files with 57 additions and 0 deletions
				
			
		|  | @ -11,6 +11,8 @@ from django.contrib.auth.models import AnonymousUser | ||||||
| from django.contrib.contenttypes.models import ContentType | from django.contrib.contenttypes.models import ContentType | ||||||
| from django.core.exceptions import ObjectDoesNotExist | from django.core.exceptions import ObjectDoesNotExist | ||||||
| 
 | 
 | ||||||
|  | from enum import Enum | ||||||
|  | 
 | ||||||
| import seminar.models as m | import seminar.models as m | ||||||
| import seminar.treelib as t | import seminar.treelib as t | ||||||
| 
 | 
 | ||||||
|  | @ -282,3 +284,58 @@ def podproblemy_v_cislu(cislo, problemy=None, hlavni_problemy=None): | ||||||
| 			podproblemy[-1].append(problem) | 			podproblemy[-1].append(problem) | ||||||
| 
 | 
 | ||||||
| 	return podproblemy | 	return podproblemy | ||||||
|  | 
 | ||||||
|  | class TypDeadline(Enum): | ||||||
|  | 	PredDeadline = auto() | ||||||
|  | 	SousDeadline = auto() | ||||||
|  | 	FinalDeadline = auto() | ||||||
|  | 
 | ||||||
|  | def deadline_v_rocniku(datum, rocnik): | ||||||
|  | 	"""Funkce pro dohledání, ke kterému deadlinu daného ročníku se datum váže. | ||||||
|  | 	 | ||||||
|  | 	Vrací trojici (TypDeadline, Cislo, datumDeadline: date). | ||||||
|  | 
 | ||||||
|  | 	V případě nevalidního volání není aktuálně chování definováno(!) | ||||||
|  | 	""" | ||||||
|  | 	cisla = m.Cislo.objects.filter(rocnik=rocnik) | ||||||
|  | 	deadliny = [] | ||||||
|  | 	for c in cisla: | ||||||
|  | 		if c.datum_preddeadline is not None: | ||||||
|  | 			deadliny.append((TypDeadline.PredDeadline, c, c.datum_preddeadline)) | ||||||
|  | 		if c.datum_deadline_soustredeni is not None: | ||||||
|  | 			deadliny.append((TypDeadline.SousDeadline, c, c.datum_deadline_soustredeni)) | ||||||
|  | 		if c.datum_deadline is not None: | ||||||
|  | 			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: | ||||||
|  | 			# První takový deadline je ten nejtěsnější | ||||||
|  | 			return dl | ||||||
|  | 
 | ||||||
|  | def deadline(datum): | ||||||
|  | 	"""Funkce pro dohledání, ke kterému deadlinu se datum váže. | ||||||
|  | 	 | ||||||
|  | 	Vrací trojici (TypDeadline, Cislo, datumDeadline: 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.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 | ||||||
|  | 
 | ||||||
|  | 	if datum <= posledni_deadline_drivejsiho_rocniku: | ||||||
|  | 		return deadline_v_rocniku(datum, drivejsi_rocnik) | ||||||
|  | 	else: | ||||||
|  | 		return deadline_v_rocniku(datum, pozdejsi_rocnik) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Kateřina Č
						Kateřina Č