Merge branch 'data_migrations' into test
This commit is contained in:
		
						commit
						275cdb18dd
					
				
					 14 changed files with 113 additions and 8 deletions
				
			
		|  | @ -78,6 +78,7 @@ TEMPLATES = [ | ||||||
|                 'django.contrib.messages.context_processors.messages', |                 'django.contrib.messages.context_processors.messages', | ||||||
|                 'sekizai.context_processors.sekizai', |                 'sekizai.context_processors.sekizai', | ||||||
|                 'header_fotky.context_processors.vzhled', |                 'header_fotky.context_processors.vzhled', | ||||||
|  |                 'various.context_processors.april', | ||||||
|             ) |             ) | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
|  | @ -132,6 +133,7 @@ INSTALLED_APPS = ( | ||||||
|     'korektury', |     'korektury', | ||||||
|     'prednasky', |     'prednasky', | ||||||
|     'header_fotky', |     'header_fotky', | ||||||
|  |     'various', | ||||||
| 
 | 
 | ||||||
|     # Admin upravy: |     # Admin upravy: | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -131,6 +131,48 @@ | ||||||
| 	   $("a[rel^='gallery-image']").prettyPhoto(prettyparams); | 	   $("a[rel^='gallery-image']").prettyPhoto(prettyparams); | ||||||
| 	}); | 	}); | ||||||
|     </script> |     </script> | ||||||
|  | 	{% if april == 2021 %} | ||||||
|  |     <script type="text/javascript" charset="utf-8"> | ||||||
|  | 	function rotace(vektor, uhel_deg) { | ||||||
|  | 		var uhel = uhel_deg *(Math.PI / 180); | ||||||
|  | 		var x = vektor[0]; | ||||||
|  | 		var y = vektor[1]; | ||||||
|  | 		return [x*Math.cos(uhel) - y*Math.sin(uhel), x*Math.sin(uhel) + y*Math.cos(uhel)]; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	function rotace_a_posun(obj, uhel) { | ||||||
|  | 		var ow = obj.width(); | ||||||
|  | 		var oh = obj.height(); | ||||||
|  | 
 | ||||||
|  | 		var rohy = [[0,0], [0,oh], [ow, 0], [ow, oh]]; | ||||||
|  | 		var minx = 0; | ||||||
|  | 		var miny = 0; | ||||||
|  | 		for (var roh of rohy) { | ||||||
|  | 			var otoceny = rotace(roh, uhel); | ||||||
|  | 			if (otoceny[0] < minx) { | ||||||
|  | 				minx = otoceny[0]; | ||||||
|  | 			} | ||||||
|  | 			if (otoceny[1] < miny) { | ||||||
|  | 				miny = otoceny[1]; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		miny *= -1; | ||||||
|  | 		minx *= -1; | ||||||
|  | 
 | ||||||
|  | 		var transf_str = "translateX("+minx+"px) translateY("+miny+"px) rotate("+uhel+"deg)"; | ||||||
|  | 		obj.css('transform-origin', 'top left'); | ||||||
|  | 		obj.css('transform', transf_str); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	function randomUhel() { | ||||||
|  | 		return Math.floor(360*Math.random()); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	$('.container').css('margin', 0); | ||||||
|  | 	rotace_a_posun($('.container'), randomUhel()); | ||||||
|  | 	</script> | ||||||
|  | 	{% endif %} | ||||||
|     {% render_block "js" %} |     {% render_block "js" %} | ||||||
|   </body> |   </body> | ||||||
| </html> | </html> | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| {% extends "base.html" %} | {% extends "base.html" %} | ||||||
| {% load static %} | {% load static %} | ||||||
|  | {% load deadliny %} | ||||||
| 
 | 
 | ||||||
| {% block content %} | {% block content %} | ||||||
| 
 | 
 | ||||||
|  | @ -62,7 +63,9 @@ $(document).ready(function(){ | ||||||
| <p>Řešitelé: {{ object.resitele.all | join:", " }}</p> | <p>Řešitelé: {{ object.resitele.all | join:", " }}</p> | ||||||
| 
 | 
 | ||||||
| {# https://docs.djangoproject.com/en/3.1/ref/models/instances/#django.db.models.Model.get_FOO_display #} | {# https://docs.djangoproject.com/en/3.1/ref/models/instances/#django.db.models.Model.get_FOO_display #} | ||||||
| <p>Forma: {{ object.get_forma_display }}, doručeno {{ object.cas_doruceni }}</p> | <p>Forma: {{ object.get_forma_display }}</p> | ||||||
|  | 
 | ||||||
|  | <p>Doručeno {{ object.cas_doruceni }}, deadline: {{object.cas_doruceni | deadline_html }}</p> | ||||||
| 
 | 
 | ||||||
| {# Soubory: #} | {# Soubory: #} | ||||||
| <h3>Přílohy:</h3> | <h3>Přílohy:</h3> | ||||||
|  |  | ||||||
|  | @ -4,5 +4,5 @@ Obdrželi jsme od Tebe žádost o obnovu hesla uživatele {{ user }} na webu M&M | ||||||
| Pro zadání nového hesla přejdi na následující stránku: | Pro zadání nového hesla přejdi na následující stránku: | ||||||
| {{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} | {{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} | ||||||
| 
 | 
 | ||||||
| S pozdravem, | S pozdravem | ||||||
| organizátoři M&M | organizátoři M&M | ||||||
							
								
								
									
										25
									
								
								seminar/templatetags/deadliny.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								seminar/templatetags/deadliny.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | ||||||
|  | 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, dl = deadline(datum) | ||||||
|  | 	strings = { | ||||||
|  | 		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] | ||||||
|  | 
 | ||||||
|  | @register.filter(name='deadline_html') | ||||||
|  | def deadline_html(datum): | ||||||
|  | 	typ, _, _ = deadline(datum) | ||||||
|  | 	text = deadline_text(datum) | ||||||
|  | 	classes = { | ||||||
|  | 		TypDeadline.PredDeadline: 'preddeadline', | ||||||
|  | 		TypDeadline.SousDeadline: 'sous_deadline', | ||||||
|  | 		TypDeadline.FinalDeadline: 'final_deadline', | ||||||
|  | 		} | ||||||
|  | 	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.append((TypDeadline.FinalDeadline, c, c.datum_deadline)) | ||||||
| 	deadliny = sorted(deadliny, key=lambda x: x[2])	# podle data | 	deadliny = sorted(deadliny, key=lambda x: x[2])	# podle data | ||||||
| 	for dl in deadliny: | 	for dl in deadliny: | ||||||
| 		if datum <= dl: | 		if datum <= dl[2]: | ||||||
| 			# První takový deadline je ten nejtěsnější | 			# První takový deadline je ten nejtěsnější | ||||||
| 			return dl | 			return dl | ||||||
| 
 | 
 | ||||||
|  | @ -319,20 +319,22 @@ def deadline(datum): | ||||||
| 	Vrací trojici (TypDeadline, Cislo, datumDeadline: date). | 	Vrací trojici (TypDeadline, Cislo, datumDeadline: date). | ||||||
| 	""" | 	""" | ||||||
| 
 | 
 | ||||||
|  | 	if isinstance(datum, datetime.datetime): | ||||||
|  | 		datum = datum.date() | ||||||
| 	rok = datum.year | 	rok = datum.year | ||||||
| 	# Dva ročníky podezřelé z obsahování dat | 	# Dva ročníky podezřelé z obsahování dat | ||||||
| 	pozdejsi_rocnik = m.Rocnik.filter(prvni_rok=rok) | 	pozdejsi_rocnik = m.Rocnik.objects.filter(prvni_rok=rok) | ||||||
| 	drivejsi_rocnik = m.Rocnik.filter(druhy_rok=rok) | 	drivejsi_rocnik = m.Rocnik.objects.filter(prvni_rok=rok-1) | ||||||
| 	if any( | 	if any([ | ||||||
| 			pozdejsi_rocnik.count() > 1, | 			pozdejsi_rocnik.count() > 1, | ||||||
| 			drivejsi_rocnik.count() > 1, | 			drivejsi_rocnik.count() > 1, | ||||||
| 			): | 			]): | ||||||
| 		raise ValueError(f"Více ročníků začíná/končí stejným rokem: {rok}") | 		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 | 	pozdejsi_rocnik = pozdejsi_rocnik.first() if pozdejsi_rocnik.count() > 0 else None | ||||||
| 	drivejsi_rocnik = drivejsi_rocnik.first() if drivejsi_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. | 	# 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: | 	if datum <= posledni_deadline_drivejsiho_rocniku: | ||||||
| 		return deadline_v_rocniku(datum, drivejsi_rocnik) | 		return deadline_v_rocniku(datum, drivejsi_rocnik) | ||||||
|  |  | ||||||
							
								
								
									
										0
									
								
								various/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								various/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										3
									
								
								various/admin.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								various/admin.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | from django.contrib import admin | ||||||
|  | 
 | ||||||
|  | # Register your models here. | ||||||
							
								
								
									
										5
									
								
								various/apps.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								various/apps.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | from django.apps import AppConfig | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class VariousConfig(AppConfig): | ||||||
|  |     name = 'various' | ||||||
							
								
								
									
										14
									
								
								various/context_processors.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								various/context_processors.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | ||||||
|  | def april(req): | ||||||
|  | 	if 'X-April' in req.headers: | ||||||
|  | 		try: | ||||||
|  | 			year = int(req.headers['X-April']) | ||||||
|  | 			return {'april': year} | ||||||
|  | 		except: | ||||||
|  | 			pass # Fall-back to regular behaviour | ||||||
|  | 	 | ||||||
|  | 	import datetime | ||||||
|  | 	today = datetime.date.today() | ||||||
|  | 	if today.day == 1 and today.month == 4: | ||||||
|  | 		return {'april': today.year} | ||||||
|  | 	return {} | ||||||
|  | 
 | ||||||
							
								
								
									
										0
									
								
								various/migrations/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								various/migrations/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										3
									
								
								various/models.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								various/models.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | from django.db import models | ||||||
|  | 
 | ||||||
|  | # Create your models here. | ||||||
							
								
								
									
										3
									
								
								various/tests.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								various/tests.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | from django.test import TestCase | ||||||
|  | 
 | ||||||
|  | # Create your tests here. | ||||||
							
								
								
									
										3
									
								
								various/views.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								various/views.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | from django.shortcuts import render | ||||||
|  | 
 | ||||||
|  | # Create your views here. | ||||||
		Loading…
	
		Reference in a new issue
	
	 Pavel "LEdoian" Turinsky
						Pavel "LEdoian" Turinsky