Browse Source

Odevzdávátko: Nejprve vybrat téma, pak podúlohy – part 1

pull/30/head
Jonas Havelka 2 years ago
parent
commit
ce4ee94fed
  1. 4
      api/views/autocomplete.py
  2. 3
      odevzdavatko/forms.py
  3. 6
      odevzdavatko/templates/odevzdavatko/nahraj_reseni.html
  4. 21
      odevzdavatko/templates/odevzdavatko/nahraj_reseni_nadproblem.html
  5. 3
      odevzdavatko/urls.py
  6. 11
      odevzdavatko/views.py

4
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):

3
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

6
odevzdavatko/templates/odevzdavatko/nahraj_reseni.html

@ -19,7 +19,7 @@
{% csrf_token %}
<table class='form' id="reseni">
<tr>
{% for field in form %}
{% for field in form.visible_fields %}
<td>
<label class="field-label{% if field.field.required %} field-required{% endif %}" for="{{ field.id_for_label }}">
{{ field.label }}:
@ -32,6 +32,10 @@
</tr>
</table>
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
<hr>

21
odevzdavatko/templates/odevzdavatko/nahraj_reseni_nadproblem.html

@ -0,0 +1,21 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<h1>
{% block nadpis1a %}
Poslat řešení
{% endblock %}
</h1>
<h4>Seznam témat k odevzdání</h4>
<ul>
{% for problem in object_list %}
<li><a href="{% url 'seminar_nahraj_reseni' problem.id %}">{{ problem }}</a></li>
{% empty %}
<li>Nelze nic odevzdávat.</li>
{% endfor %}
</ul>
{% endblock %}

3
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/<int:nadproblem_id>/', 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'),

11
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:

Loading…
Cancel
Save