from django.views.generic import FormView from seminar.models import Osoba from seminar.views import formularOKView from .forms import UcastnikVyrociForm from .models import UcastnikVyroci # Create your views here. class VyrociView(FormView): """ Zobrazí organizátorský rozcestník.""" template_name = 'vyroci/vyroci.html' form_class = UcastnikVyrociForm def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['ucastnici'] = UcastnikVyroci.objects.all() return context def form_valid(self, form): form.save() return formularOKView(self.request, "Úspěšně jsi se přihlásil na víkendovku") def get_initial(self): initial = super().get_initial() if self.request.user.is_authenticated: osoba = Osoba.objects.filter(user=self.request.user).first() if osoba is not None: initial["jmeno"] = osoba.plne_jmeno() initial["email"] = osoba.email return initial