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.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í
+
+
+ {% for problem in object_list %}
+ - {{ problem }}
+ {% empty %}
+ - Nelze nic odevzdávat.
+ {% endfor %}
+
+
+{% 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: