mamweb/vyroci/views.py

35 lines
972 B
Python
Raw Normal View History

from django.views.generic import FormView, ListView
2023-06-02 21:04:11 +02:00
from seminar.models import Osoba
2024-08-04 17:41:24 +02:00
from various.views.pomocne import formularOKView
2023-06-02 21:04:11 +02:00
from .forms import UcastnikVyrociForm
from .models import UcastnikVyroci
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()
2023-06-13 22:36:08 +02:00
return formularOKView(self.request, "Úspěšně ses přihlásil na sraz")
2023-06-02 21:04:11 +02:00
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