Browse Source

odevzdavatko: zjednodušení DetailReseniView

notifikace_zpetne_vazby
Karel Balej 2 years ago
parent
commit
288c8ad459
  1. 20
      odevzdavatko/views.py

20
odevzdavatko/views.py

@ -219,24 +219,12 @@ class DetailReseniView(DetailView):
model = m.Reseni model = m.Reseni
template_name = 'odevzdavatko/detail.html' template_name = 'odevzdavatko/detail.html'
def aktualni_hodnoceni(self):
self.reseni = get_object_or_404(m.Reseni, id=self.kwargs['pk'])
result = [] # Slovníky s klíči problem, body, deadline_body -- initial data pro f.OhodnoceniReseniFormSet
for hodn in m.Hodnoceni.objects.filter(reseni=self.reseni):
result.append({
"problem": hodn.problem,
"body": hodn.body,
"deadline_body": hodn.deadline_body,
"feedback": hodn.feedback,
})
return result
def get_context_data(self, **kw): def get_context_data(self, **kw):
reseni = get_object_or_404(m.Reseni, id=self.kwargs['pk'])
initial = m.Hodnoceni.objects.filter(reseni=reseni).values('problem', 'body', 'deadline_body', 'feedback',)
ctx = super().get_context_data(**kw) ctx = super().get_context_data(**kw)
ctx['form'] = f.OhodnoceniReseniFormSet( ctx['form'] = f.OhodnoceniReseniFormSet(initial=initial)
initial = self.aktualni_hodnoceni() ctx['poznamka_form'] = f.PoznamkaReseniForm(instance=reseni)
)
ctx['poznamka_form'] = f.PoznamkaReseniForm(instance=self.reseni)
return ctx return ctx

Loading…
Cancel
Save