35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
# apps/participants/views.py
|
|
from django.views.generic import ListView, CreateView, View, TemplateView
|
|
from django.urls import reverse_lazy
|
|
from django.shortcuts import redirect
|
|
from .models import Participant
|
|
from .forms import ParticipantForm
|
|
from .services import calculate_scores
|
|
from django.views.generic import TemplateView
|
|
from .services import calculate_scores_details
|
|
|
|
class ParticipantCreateView(CreateView):
|
|
model = Participant
|
|
form_class = ParticipantForm
|
|
template_name = "participants/form.html"
|
|
success_url = reverse_lazy("participant_new") # vuelve a sí misma
|
|
|
|
class CalculateView(View):
|
|
def post(self, request, *args, **kwargs):
|
|
calculate_scores()
|
|
return redirect("results")
|
|
|
|
class ResultsView(ListView):
|
|
model = Participant
|
|
template_name = "participants/results.html"
|
|
context_object_name = "participants"
|
|
|
|
class ResultsView(TemplateView):
|
|
template_name = "participants/results.html"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
ctx = super().get_context_data(**kwargs)
|
|
# recalcula en memoria y entrega detalles
|
|
ctx["rankings"] = calculate_scores_details()
|
|
return ctx
|