from django.views.generic import FormView, ListView from seminar.models.personalni import Osoba from seminar.views import formularOKView from .forms import UcastnikVyrociForm from .models import UcastnikVyroci # Create your views here. class VyrociView(FormView): 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ě ses přihlásil na sraz") 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 class VyrociListView(ListView): template_name = 'vyroci/vyroci_list.html' model = UcastnikVyroci