resitelEditView(view.py), EditForm(forms.py), template.edit.html
This commit is contained in:
		
							parent
							
								
									61c1ebfc9b
								
							
						
					
					
						commit
						08eb89d790
					
				
					 3 changed files with 213 additions and 3 deletions
				
			
		
							
								
								
									
										103
									
								
								seminar/forms.py
									
									
									
									
									
								
							
							
						
						
									
										103
									
								
								seminar/forms.py
									
									
									
									
									
								
							|  | @ -121,3 +121,106 @@ class PrihlaskaForm(forms.Form): | |||
| 				self.add_error('skola_nazev',forms.ValidationError('Je nutné vyplnit název školy')) | ||||
| 			elif data.get('skola_adresa')=='': | ||||
| 				self.add_error('skola_adresa',forms.ValidationError('Je nutné vyplnit adresu školy')) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| class EditForm(forms.Form): | ||||
| 	username = forms.CharField(label='Přihlašovací jméno',  | ||||
| 			max_length=256,  | ||||
| 			required=True, | ||||
| 			help_text='Tímto jménem se následně budeš přihlašovat pro odevzdání řešení a další činnosti v semináři') | ||||
| 	password = forms.CharField( | ||||
| 			label='Heslo', | ||||
| 			max_length=256, | ||||
| 			required=False, | ||||
| 			widget=forms.PasswordInput()) | ||||
| 	password_check = forms.CharField( | ||||
| 			label='Ověření hesla', | ||||
| 			max_length=256, | ||||
| 			required=False, | ||||
| 			widget=forms.PasswordInput()) | ||||
| 
 | ||||
| 	jmeno = forms.CharField(label='Jméno', max_length=256, required=True) | ||||
| 	prijmeni = forms.CharField(label='Příjmení', max_length=256, required=True) | ||||
| 	pohlavi_muz = forms.ChoiceField(label='Pohlaví', | ||||
| 			choices = ((True,'muž'),(False,'žena')), required=True) | ||||
| 	email = forms.EmailField(label='E-mail',max_length=256, required=True) | ||||
| 	telefon = forms.CharField(label='Telefon',max_length=256, required=False) | ||||
| 	datum_narozeni = forms.DateField(label='Datum narození', required=False) | ||||
| 	ulice = forms.CharField(label='Ulice', max_length=256, required=False) | ||||
| 	mesto = forms.CharField(label='Město', max_length=256, required=False) | ||||
| 	psc = forms.CharField(label='PSČ', max_length=32, required=False) | ||||
| 	stat = forms.ChoiceField(label='Stát',  | ||||
| 			choices = (('CZ', 'Česká Republika'), | ||||
| 				('SK', 'Slovenská Republika'), | ||||
| 				('other', 'Jiné')), | ||||
| 			required=False) | ||||
| 	stat_text = forms.CharField(label='Stát', max_length=256, required=False) | ||||
| 
 | ||||
| 	skola = forms.ModelChoiceField(label="Škola", | ||||
| 		queryset=Skola.objects.all(), | ||||
| 		widget=autocomplete.ModelSelect2( | ||||
| 			url='autocomplete_skola', | ||||
| 			attrs = {'data-placeholder--id': '-1', | ||||
| 				'data-placeholder--text' : '---', | ||||
| 				'data-allow-clear': 'true'}) | ||||
|     		,required=False) | ||||
| 	 | ||||
| 	skola_nazev = forms.CharField(label='Název školy', max_length=256, required=False) | ||||
| 	skola_adresa = forms.CharField(label='Adresa školy', max_length=256, required=False) | ||||
| 
 | ||||
| #	trida = forms.CharField(label='Třída',max_length=10, required=True) | ||||
| 
 | ||||
| 	rok_maturity = forms.IntegerField( | ||||
| 		label='Rok maturity',  | ||||
| 		min_value=date.today().year,  | ||||
| 		max_value=date.today().year+8, | ||||
| 		required=True) | ||||
| 	zasilat = forms.ChoiceField(label='Kam zasílat čísla a řešení',choices = Resitel.ZASILAT_CHOICES, required=True) | ||||
| 	gdpr = forms.BooleanField(label='Souhlasím se zpracováním osobních údajů', required=True) | ||||
| 	spam = forms.BooleanField(label='Souhlasím se zasíláním materiálů od MFF UK', required=False) | ||||
| #	def clean_username(self): | ||||
| #		err_logger = logging.getLogger('seminar.prihlaska.problem') | ||||
| #		username = self.cleaned_data.get('username') | ||||
| #		try: | ||||
| #			User.objects.get(username=username) | ||||
| #			msg = "Username {} exists".format(username) | ||||
| #			err_logger.info(msg) | ||||
| #			raise forms.ValidationError('Přihlašovací jméno je již použito') | ||||
| # | ||||
| #		except ObjectDoesNotExist: | ||||
| #			pass | ||||
| #		return username | ||||
| # | ||||
| #	def clean_email(self): | ||||
| #		err_logger = logging.getLogger('seminar.prihlaska.problem') | ||||
| #		email = self.cleaned_data.get('email') | ||||
| #		try: | ||||
| #			Osoba.objects.get(email=email) | ||||
| #			msg = "Email {} exists".format(email) | ||||
| #			err_logger.info(msg) | ||||
| #			raise forms.ValidationError('Email je již použit') | ||||
| # | ||||
| #		except ObjectDoesNotExist: | ||||
| #			pass | ||||
| #		return email | ||||
| 	#def clean(self): | ||||
| 	#	super().clean() | ||||
| 	#	 | ||||
| 	#	err_logger = logging.getLogger('seminar.prihlaska.problem') | ||||
| 
 | ||||
| 	#	data = self.cleaned_data | ||||
| 	#	if data.get('password') != data.get('password_check'): | ||||
| 	#		self.add_error('password_check',forms.ValidationError('Hesla se neshodují')) | ||||
| 	#	if data.get('stat') != '' and data.get('stat_text') != '': | ||||
| 	#		self.add_error('stat',forms.ValidationError('Nelze mít vybraný stát z menu a zároven zapsaný textem')) | ||||
| 	#	if data.get('skola') and (data.get('skola_nazev') or data.get('skola_adresa')): | ||||
| 	#		self.add_error('skola',forms.ValidationError('Pokud je škola v seznamu, nevypisujte ji ručně, pokud není, zrušte výběr ze seznamu (křížek vpravo)')) | ||||
| 	#	if not data.get('skola'): | ||||
| 	#		if data.get('skola_nazev')=='' and data.get('skola_adresa')=='': | ||||
| 	#			self.add_error('skola',forms.ValidationError('Je nutné vyplnit školu')) | ||||
| 	#		elif data.get('skola_nazev')=='': | ||||
| 	#			self.add_error('skola_nazev',forms.ValidationError('Je nutné vyplnit název školy')) | ||||
| 	#		elif data.get('skola_adresa')=='': | ||||
| 	#			self.add_error('skola_adresa',forms.ValidationError('Je nutné vyplnit adresu školy')) | ||||
|  |  | |||
							
								
								
									
										85
									
								
								seminar/templates/seminar/edit.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								seminar/templates/seminar/edit.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,85 @@ | |||
| {% extends "seminar/zadani/base.html" %} | ||||
| {% load staticfiles %} | ||||
| 
 | ||||
| {% block script %} | ||||
|     <!--script type="text/javascript" src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script!--> | ||||
|     {{form.media}} | ||||
|     <script src="{% static 'seminar/prihlaska.js' %}"></script> | ||||
| {% endblock %} | ||||
| {% block content %} | ||||
| <h1> | ||||
|   {% block nadpis1a %}{% block nadpis1b %} | ||||
|    Změna osobních údajů | ||||
|   {% endblock %}{% endblock %} | ||||
| </h1> | ||||
| <form action="{% url 'seminar_resitel_edit' %}" method="post"> | ||||
|  {% csrf_token %} | ||||
|  {{form.non_field_errors}} | ||||
|  <ul class="form"> | ||||
|      <li> | ||||
|      Přihlašovací údaje | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.username %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.password %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.password_check %} | ||||
|      </li><li> | ||||
|      Osobní údaje | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.jmeno %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.prijmeni %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.pohlavi_muz%} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.email %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.telefon %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.datum_narozeni %} | ||||
|      </li><li> | ||||
|   <hr> | ||||
|        Bydliště | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.ulice %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.mesto %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.psc %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.stat %} | ||||
|      </li> | ||||
|      <li id="id_li_stat_text"> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.stat_text %} | ||||
|      </li><li> | ||||
|  <hr> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.skola %} | ||||
|      </li><li> | ||||
|        <button id="id_skola_text_button" type="button">Škola není v seznamu</button> | ||||
|      </li> | ||||
|      <li id="id_li_skola_nazev"> | ||||
|        Vyplň prosím celý název a adresu školy.<br> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.skola_nazev %} | ||||
|      </li> | ||||
|      <li id="id_li_skola_adresa"> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.skola_adresa %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.rok_maturity %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.zasilat %} | ||||
|      </li><li> | ||||
|        {% include "seminar/gdpr.html" %} | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.gdpr %} | ||||
|      </li><li> | ||||
|        {% include "seminar/prihlaska_field.html" with field=form.spam %} | ||||
|      </li> | ||||
| </ul> | ||||
|     <input type="submit" value="Změnit"> | ||||
| </form> | ||||
| <script> | ||||
| $("#id_stat").on("change",addrCountryChanged); | ||||
| $("#id_skola_text_button").on("click",schoolNotInList); | ||||
| </script> | ||||
| {% endblock %} | ||||
| 
 | ||||
|  | @ -19,7 +19,7 @@ from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Orga | |||
| #from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva | ||||
| from . import utils | ||||
| from .unicodecsv import UnicodeWriter | ||||
| from .forms import PrihlaskaForm, LoginForm | ||||
| from .forms import PrihlaskaForm, LoginForm, EditForm | ||||
| 
 | ||||
| from datetime import timedelta, date, datetime | ||||
| from django.utils import timezone | ||||
|  | @ -989,8 +989,6 @@ class ResitelView(LoginRequiredMixin,generic.DetailView): | |||
| 		return Resitel.objects.get(osoba__user=self.request.user) | ||||
| 
 | ||||
| ## Formulare | ||||
| def resitelEditView(request): | ||||
| 	pass | ||||
| def resetPasswordView(request): | ||||
| 	pass | ||||
| 
 | ||||
|  | @ -1027,6 +1025,30 @@ def prihlaska_log_gdpr_safe(logger, gdpr_logger, msg, form_data): | |||
| 	logger.warn(msg) | ||||
| 	gdpr_logger.warn(msg+", form:{}".format(form_data))		 | ||||
| 
 | ||||
| from django.forms.models import model_to_dict | ||||
| def resitelEditView(request): | ||||
|     ## Načtení objektu Osoba a Resitel, patrici k aktuálně přihlášenému uživately | ||||
|     u = request.user | ||||
|     osoba_edit = Osoba.objects.get(user=u) | ||||
|     resitel_edit = osoba_edit.resitel | ||||
|     user_edit = osoba_edit.user | ||||
|     ## Vytvoření slovníku, kterým předvyplním formulář  | ||||
|     prefill_1=model_to_dict(osoba_edit) | ||||
|     prefill_2=model_to_dict(resitel_edit) | ||||
|     prefill_3=model_to_dict(user_edit) | ||||
|     prefill_1.update(prefill_2) | ||||
|     prefill_1.update(prefill_3) | ||||
|     form = EditForm(initial=prefill_1) | ||||
|     ## Změna údajů a jejich uložení | ||||
|     if request.method == 'POST': | ||||
|         form = EditForm(request.POST) | ||||
|         if form.is_valid(): | ||||
|             osoba_edit.prijmeni = 'NOVOTA' | ||||
|             osoba_edit.save() | ||||
|             return HttpResponseRedirect('/thanks/') | ||||
|     else: | ||||
|         ## Stránka před odeslaním formuláře = předvyplněný formulář | ||||
|         return render(request, 'seminar/edit.html', {'form': form}) | ||||
| 
 | ||||
| def prihlaskaView(request): | ||||
| 	generic_logger = logging.getLogger('seminar.prihlaska') | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 KubaR
						KubaR