Browse Source

Testovaci view na cislo a vysledkovka s daty z VIEW

remotes/origin/feincms
Tomas Gavenciak 10 years ago
parent
commit
557c1d55e1
  1. 32
      seminar/templates/seminar/cislo.html
  2. 1
      seminar/urls.py
  3. 38
      seminar/views.py

32
seminar/templates/seminar/cislo.html

@ -0,0 +1,32 @@
{% extends "base.html" %}
{% load staticfiles sekizai_tags %}
{% block content %}
<div>
<h2>Číslo {{ cislo }} [id {{ cislo.id}}]</h2>
<table class='vysledkovka'>
<tr class='border-b'>
<th class='border-r'>#
<th class='border-r'>Jméno
{% for p in problemy %}
<th class='border-r'>{{ p.cislo_zadani.cislo }}.{{ p.kod }}
{% endfor %}
<th class='border-r'>Sum
<th>Celkem
{% for rv in vysledkovka %}
<tr>
<td class='border-r'>{{ rv.poradi }}
<th class='border-r'>{{ rv.resitel.plne_jmeno }} [{{ rv.resitel.id }}]
{% for b in rv.body %}
<td class='border-r'>{{ b }}
{% endfor %}
<td class='border-r'>{{ rv.vysledek.body |default:0 }}
<td>{{ rv.vysledek.body_celkem }}
</tr>
{% endfor %}
</table>
</div>
{% endblock content %}

1
seminar/urls.py

@ -3,4 +3,5 @@ from . import views
urlpatterns = patterns('',
url(r'^problem/(?P<pk>\d+)/$', views.ProblemView.as_view(), name='problem'),
url(r'^cislo/(?P<pk>\d+)/$', views.CisloView.as_view(), name='cislo'),
)

38
seminar/views.py

@ -2,7 +2,7 @@ from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views import generic
from .models import Problem, Cislo
from .models import Problem, Cislo, Reseni, VysledkyKCislu
# Create your views here.
@ -10,8 +10,44 @@ class ProblemView(generic.DetailView):
model = Problem
template_name = 'seminar/problem.html'
class RadekVysledkovky(object):
pass
class CisloView(generic.DetailView):
model = Cislo
template_name = 'seminar/cislo.html'
def get_context_data(self, **kwargs):
context = super(CisloView, self).get_context_data(**kwargs)
vysledky = VysledkyKCislu.objects.filter(cislo = context['cislo']).select_related("resitel")
reseni = Reseni.objects.filter(cislo_body = context['cislo']).select_related("resitel")
problemy = sorted(list(set([r.problem for r in reseni])), key=lambda x:x.kod)
problem_index = {}
for i in range(len(problemy)):
problem_index[problemy[i].id] = i
vysledky_resitele = {}
vysledkovka = []
posledni_body = 100000
for vi in range(len(vysledky)):
v = vysledky[vi]
tv = RadekVysledkovky()
tv.resitel = v.resitel
tv.vysledek = v
tv.body = ['']*len(problemy)
tv.poradi = ''
if posledni_body > v.body_celkem:
posledni_body = v.body_celkem
tv.poradi = vi + 1
vysledky_resitele[v.resitel.id] = tv
vysledkovka.append(tv)
for r in reseni:
vysledky_resitele[r.resitel.id].body[problem_index[r.problem.id]] = r.body
context['vysledkovka'] = vysledkovka
context['problemy'] = problemy
return context

Loading…
Cancel
Save