Zakladni testy konzistence dat -- pridejte dalsi!

This commit is contained in:
Tomas Gavenciak 2015-07-29 11:46:08 +02:00
parent 39f520260d
commit 1692d8c2e0
4 changed files with 78 additions and 1 deletions

View file

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block content %}
<div>
<h2>Stav databáze</h2>
<h3>Nastavení</h3>
<h3>Problémy</h3>
{% for p in problemy %}
<div>{{ p |safe }}</div>
{% endfor %}
</div>
{% endblock content %}

View file

@ -17,6 +17,8 @@ urlpatterns = patterns('',
url(r'^zadani/aktualni/$', views.AktualniZadaniView, name='seminar_aktualni_zadani'), url(r'^zadani/aktualni/$', views.AktualniZadaniView, name='seminar_aktualni_zadani'),
url(r'^stav$', views.StavDatabazeView, name='stav_databaze'),
url(r'^aesop-export/mam-rocnik-(?P<prvni_rok>\d+)\.csv$', export.ExportRocnikView.as_view(), name='seminar_export_rocnik'), url(r'^aesop-export/mam-rocnik-(?P<prvni_rok>\d+)\.csv$', export.ExportRocnikView.as_view(), name='seminar_export_rocnik'),
url(r'^aesop-export/mam-sous-(?P<datum_zacatku>[\d-]+)\.csv$', export.ExportSousView.as_view(), name='seminar_export_sous'), url(r'^aesop-export/mam-sous-(?P<datum_zacatku>[\d-]+)\.csv$', export.ExportSousView.as_view(), name='seminar_export_sous'),
url(r'^aesop-export/index.csv$', export.ExportIndexView.as_view(), name='seminar_export_index'), url(r'^aesop-export/index.csv$', export.ExportIndexView.as_view(), name='seminar_export_index'),

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import datetime
roman_numerals = zip((1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1), roman_numerals = zip((1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
('M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I')) ('M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I'))
@ -18,3 +20,49 @@ def from_roman(rom):
return i + from_roman(rom[len(n):]) return i + from_roman(rom[len(n):])
raise Exception('Invalid roman numeral: "%s"', rom) raise Exception('Invalid roman numeral: "%s"', rom)
def seznam_problemu():
from .models import Problem, Resitel, Rocnik, Reseni, Cislo
problemy = []
# Pomocna fce k formatovani problemovych hlasek
def prb(cls, msg, objs=None):
s = u'<b>%s:</b> %s' % (cls.__name__, msg)
if objs:
s += u' ['
for o in objs:
try:
url = o.admin_url()
except:
url = None
if url:
s += u'<a href="%s">%s</a>, ' % (url, o.pk, )
else:
s += u'%s, ' % (o.pk, )
s = s[:-2] + u']'
problemy.append(s)
# Duplicita jmen
jmena = {}
for r in Resitel.objects.all():
j = r.plne_jmeno()
if j not in jmena:
jmena[j] = []
jmena[j].append(r)
for j in jmena:
if len(jmena[j]) > 1:
prb(Resitel, u'Duplicitní jméno "%s"' % (j, ), jmena[j])
# Data maturity a narození
for r in Resitel.objects.all():
if not r.rok_maturity:
prb(Resitel, u'Neznámý rok maturity', [r])
if r.rok_maturity and (r.rok_maturity < 1990 or r.rok_maturity > datetime.date.today().year + 10):
prb(Resitel, u'Podezřelé datum maturity', [r])
if r.datum_narozeni and (r.datum_narozeni.year < 1970 or r.datum_narozeni.year > datetime.date.today().year - 12):
prb(Resitel, u'Podezřelé datum narození', [r])
# if not r.email:
# prb(Resitel, u'Neznámý email', [r])
return problemy

View file

@ -6,7 +6,7 @@ from django.utils.translation import ugettext as _
from django.http import Http404 from django.http import Http404
from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik, Soustredeni, Organizator from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik, Soustredeni, Organizator
from . import utils
def AktualniZadaniView(request): def AktualniZadaniView(request):
nastaveni = get_object_or_404(Nastaveni) nastaveni = get_object_or_404(Nastaveni)
@ -161,3 +161,14 @@ class SoustredeniListView(generic.ListView):
class SoustredeniView(generic.DetailView): class SoustredeniView(generic.DetailView):
model = Soustredeni model = Soustredeni
template_name = 'seminar/archiv/soustredeni.html' template_name = 'seminar/archiv/soustredeni.html'
### Status
def StavDatabazeView(request):
# nastaveni = Nastaveni.objects.get()
problemy = utils.seznam_problemu()
return render(request, 'seminar/stav_databaze.html',
{
# 'nastaveni': nastaveni,
'problemy': problemy,
})