From ce4ee94fedca54212bd6c02b907ae136b5e923f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Mon, 15 May 2023 21:49:35 +0200 Subject: [PATCH] =?UTF-8?q?Odevzd=C3=A1v=C3=A1tko:=20Nejprve=20vybrat=20t?= =?UTF-8?q?=C3=A9ma,=20pak=20pod=C3=BAlohy=20=E2=80=93=20part=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/views/autocomplete.py | 4 ++++ odevzdavatko/forms.py | 3 +++ .../templates/odevzdavatko/nahraj_reseni.html | 6 +++++- .../nahraj_reseni_nadproblem.html | 21 +++++++++++++++++++ odevzdavatko/urls.py | 3 ++- odevzdavatko/views.py | 11 ++++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 odevzdavatko/templates/odevzdavatko/nahraj_reseni_nadproblem.html diff --git a/api/views/autocomplete.py b/api/views/autocomplete.py index 601f4e35..473f2722 100644 --- a/api/views/autocomplete.py +++ b/api/views/autocomplete.py @@ -87,6 +87,10 @@ class OdevzdatelnyProblemAutocomplete(autocomplete.Select2QuerySetView): if self.q: qs = qs.filter( Q(nazev__icontains=self.q)) + + nadproblem_id = int(self.forwarded.get("nadproblem_id", -1)) + if nadproblem_id != -1: + qs = [problem for problem in qs if problem.hlavni_problem.id == nadproblem_id] return qs class ProblemAutocomplete(autocomplete.Select2QuerySetView): diff --git a/odevzdavatko/forms.py b/odevzdavatko/forms.py index d9d90a3e..89121747 100644 --- a/odevzdavatko/forms.py +++ b/odevzdavatko/forms.py @@ -72,6 +72,7 @@ class NahrajReseniForm(forms.ModelForm): attrs = {'data-placeholder--id': '-1', 'data-placeholder--text' : '---', 'data-allow-clear': 'true'}, + forward=["nadproblem_id"], ), 'resitele': autocomplete.ModelSelect2Multiple( @@ -82,6 +83,8 @@ class NahrajReseniForm(forms.ModelForm): ) } + nadproblem_id = forms.IntegerField(required=False, disabled=True, widget=forms.HiddenInput()) + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # FIXME Z nějakého důvodu se do této třídy dostaneme i bez resitele diff --git a/odevzdavatko/templates/odevzdavatko/nahraj_reseni.html b/odevzdavatko/templates/odevzdavatko/nahraj_reseni.html index 61c4d9ec..80f97fbf 100644 --- a/odevzdavatko/templates/odevzdavatko/nahraj_reseni.html +++ b/odevzdavatko/templates/odevzdavatko/nahraj_reseni.html @@ -19,7 +19,7 @@ {% csrf_token %} - {% for field in form %} + {% for field in form.visible_fields %}
+ {% for field in form.hidden_fields %} + {{ field }} + {% endfor %} +
diff --git a/odevzdavatko/templates/odevzdavatko/nahraj_reseni_nadproblem.html b/odevzdavatko/templates/odevzdavatko/nahraj_reseni_nadproblem.html new file mode 100644 index 00000000..6e49f02e --- /dev/null +++ b/odevzdavatko/templates/odevzdavatko/nahraj_reseni_nadproblem.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% load static %} + +{% block content %} +

+ {% block nadpis1a %} + Poslat řešení + {% endblock %} +

+ +

Seznam témat k odevzdání

+ + + +{% endblock %} diff --git a/odevzdavatko/urls.py b/odevzdavatko/urls.py index 8c53de6b..35b74eea 100644 --- a/odevzdavatko/urls.py +++ b/odevzdavatko/urls.py @@ -20,7 +20,8 @@ from . import views urlpatterns = [ path('org/add_solution', org_required(views.PosliReseniView.as_view()), name='seminar_vloz_reseni'), - path('resitel/nahraj_reseni', resitel_required(views.NahrajReseniView.as_view()), name='seminar_nahraj_reseni'), + path('resitel/nahraj_reseni', resitel_required(views.NahrajReseniNadproblemView.as_view()), name='seminar_nahraj_reseni'), + path('resitel/nahraj_reseni//', resitel_required(views.NahrajReseniView.as_view()), name='seminar_nahraj_reseni'), path('resitel/odevzdana_reseni/', resitel_or_org_required(views.PrehledOdevzdanychReseni.as_view()), name='seminar_resitel_odevzdana_reseni'), path('org/reseni/', org_required(views.TabulkaOdevzdanychReseniView.as_view()), name='odevzdavatko_tabulka'), diff --git a/odevzdavatko/views.py b/odevzdavatko/views.py index d3c74812..acef1669 100644 --- a/odevzdavatko/views.py +++ b/odevzdavatko/views.py @@ -381,6 +381,14 @@ class PosliReseniView(LoginRequiredMixin, FormView): return data +class NahrajReseniNadproblemView(LoginRequiredMixin, ListView): + model = m.Problem + template_name = 'odevzdavatko/nahraj_reseni_nadproblem.html' + + def get_queryset(self): + return super().get_queryset().filter(nadproblem__isnull=True) + + class NahrajReseniView(LoginRequiredMixin, CreateView): model = m.Reseni template_name = 'odevzdavatko/nahraj_reseni.html' @@ -399,6 +407,9 @@ class NahrajReseniView(LoginRequiredMixin, CreateView): }) return super().get(request, *args, **kwargs) + def get_initial(self): + return {"nadproblem_id": self.kwargs["nadproblem_id"]} + def get_context_data(self,**kwargs): data = super().get_context_data(**kwargs) if self.request.POST: