Bc. Petr Pecha
9 years ago
14 changed files with 218 additions and 3 deletions
@ -0,0 +1,7 @@ |
|||||
|
from django.contrib import admin |
||||
|
|
||||
|
from models import Prednaska, Seznam, Hlasovani |
||||
|
|
||||
|
admin.site.register(Seznam) |
||||
|
admin.site.register(Prednaska) |
||||
|
admin.site.register(Hlasovani) |
@ -0,0 +1,8 @@ |
|||||
|
# coding: utf-8 |
||||
|
from django import forms |
||||
|
|
||||
|
class NewPrednaskyForm(forms.Form): |
||||
|
ucastnik = forms.CharField(label = 'Tvoje jméno', max_length = 100) |
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,45 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('seminar', '0036_add_org_to_soustredeni'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.CreateModel( |
||||
|
name='Hlasovani', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), |
||||
|
('body', models.IntegerField(default=0, verbose_name=b'Body', choices=[(0, b'0'), (1, b'1'), (-1, b'-1')])), |
||||
|
('ucastnik', models.CharField(max_length=100, verbose_name=b'\xc3\x9a\xc4\x8dastn\xc3\xadk')), |
||||
|
], |
||||
|
), |
||||
|
migrations.CreateModel( |
||||
|
name='Prednaska', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), |
||||
|
('nazev', models.CharField(max_length=300, verbose_name=b'N\xc3\xa1zev')), |
||||
|
('anotace', models.TextField(verbose_name=b'Anotace')), |
||||
|
('obtiznost', models.IntegerField(verbose_name=b'Obt\xc3\xad\xc5\xbenost', choices=[(1, b'Lehk\xc3\xa1'), (2, b'St\xc5\x99edn\xc3\xad'), (3, b'T\xc4\x9b\xc5\xbek\xc3\xa1')])), |
||||
|
('obor', models.CharField(max_length=5, verbose_name=b'Obor')), |
||||
|
('klicova', models.CharField(max_length=200, null=True, verbose_name=b'Kl\xc3\xad\xc4\x8dov\xc3\xa1 slova', blank=True)), |
||||
|
('org', models.ForeignKey(to='seminar.Organizator')), |
||||
|
], |
||||
|
), |
||||
|
migrations.CreateModel( |
||||
|
name='Seznam', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), |
||||
|
], |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='hlasovani', |
||||
|
name='prednaska', |
||||
|
field=models.ForeignKey(to='prednasky.Prednaska'), |
||||
|
), |
||||
|
] |
@ -0,0 +1,24 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('prednasky', '0001_initial'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AddField( |
||||
|
model_name='prednaska', |
||||
|
name='seznam', |
||||
|
field=models.ForeignKey(default=None, blank=True, to='prednasky.Seznam'), |
||||
|
), |
||||
|
migrations.AlterField( |
||||
|
model_name='hlasovani', |
||||
|
name='body', |
||||
|
field=models.IntegerField(default=0, verbose_name=b'Body', choices=[(-1, b'-1'), (0, b'0'), (1, b'1')]), |
||||
|
), |
||||
|
] |
@ -0,0 +1,34 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from django.db import models |
||||
|
from seminar.models import Organizator |
||||
|
|
||||
|
class Seznam(models.Model): |
||||
|
pass |
||||
|
|
||||
|
CHOICES_OBTIZNOST = ( |
||||
|
(1, 'Lehká'), |
||||
|
(2, 'Střední'), |
||||
|
(3, 'Těžká'), |
||||
|
) |
||||
|
|
||||
|
CHOICES_BODY = ( |
||||
|
(-1, '-1'), |
||||
|
(0, '0'), |
||||
|
(1, '1'), |
||||
|
) |
||||
|
|
||||
|
class Prednaska(models.Model): |
||||
|
nazev = models.CharField('Název', max_length = 300) |
||||
|
org = models.ForeignKey(Organizator) |
||||
|
anotace = models.TextField('Anotace') |
||||
|
obtiznost = models.IntegerField('Obtížnost', choices=CHOICES_OBTIZNOST) |
||||
|
obor = models.CharField('Obor', max_length = 5) |
||||
|
klicova = models.CharField('Klíčová slova', max_length = 200, null = True, blank = True) |
||||
|
seznam = models.ForeignKey(Seznam, blank = True, default = None) |
||||
|
|
||||
|
class Hlasovani(models.Model): |
||||
|
prednaska = models.ForeignKey(Prednaska) |
||||
|
body = models.IntegerField('Body', default = 0, choices = CHOICES_BODY) |
||||
|
ucastnik = models.CharField('Účastník', max_length = 100) |
||||
|
|
@ -0,0 +1,40 @@ |
|||||
|
{% extends 'base.html' %} |
||||
|
|
||||
|
{% load humanize %} |
||||
|
{% load staticfiles %} |
||||
|
|
||||
|
{% block title %} |
||||
|
Hlasování o přednáškách |
||||
|
{% endblock %} |
||||
|
|
||||
|
{% block content %} |
||||
|
|
||||
|
<p> |
||||
|
Jak moc by ses chtěl(a) zúčastnit následujících přednášek? |
||||
|
<br> |
||||
|
<span style="font-size: 75%">Obtížnost 1 je nejlehčí, 3 nejtěžší.</span> |
||||
|
</p> |
||||
|
|
||||
|
<form enctype="multipart/form-data" action="." method="post"> |
||||
|
{% csrf_token %} |
||||
|
<table>{{form.as_table}} |
||||
|
</table> |
||||
|
<table> |
||||
|
{% for p in prednasky.prednaska_set.all %} |
||||
|
<tr><td><label>{{p.org}}: <span style="font-size: 175%">{{p.nazev}}</span></label></td></tr> |
||||
|
<tr><td><p><i>{{p.anotace}}</i></p></td></tr> |
||||
|
<tr><td><label>Obor: </label> {{p.obor}}</td></tr> |
||||
|
<tr><td><label>Obtížnost: </label> {{p.obtiznost}}</td> </tr> |
||||
|
{% if p.klicova %}<tr><td><label>Klíčová slova: </label> {{p.klicova}}</td></tr>{% endif%} |
||||
|
<tr><td>Hodnocení: |
||||
|
<INPUT TYPE="radio" NAME="q{{p.pk}}" VALUE="-1"> rozhodně nechci |
||||
|
<INPUT TYPE="radio" NAME="q{{p.pk}}" VALUE="0" checked> je mi to jedno |
||||
|
<INPUT TYPE="radio" NAME="q{{p.pk}}" VALUE="1"> rozhodně chci |
||||
|
</td></tr> |
||||
|
<tr><td> </td></tr> |
||||
|
{% endfor %} |
||||
|
<tr><td><input name="odeslat" type="submit" value="Odeslat"></td><tr> |
||||
|
</table> |
||||
|
</form> |
||||
|
|
||||
|
{% endblock %} |
@ -0,0 +1,11 @@ |
|||||
|
{% extends 'base.html' %} |
||||
|
|
||||
|
{% load humanize %} |
||||
|
{% load staticfiles %} |
||||
|
|
||||
|
|
||||
|
{% block content %} |
||||
|
|
||||
|
<h1> Děkujeme. </h1> |
||||
|
|
||||
|
{% endblock %} |
@ -0,0 +1,3 @@ |
|||||
|
from django.test import TestCase |
||||
|
|
||||
|
# Create your tests here. |
@ -0,0 +1,38 @@ |
|||||
|
from django.shortcuts import render |
||||
|
from prednasky.forms import NewPrednaskyForm |
||||
|
from prednasky.models import Seznam, Hlasovani, Prednaska |
||||
|
from django.shortcuts import HttpResponseRedirect |
||||
|
|
||||
|
def newPrednaska(request): |
||||
|
# zjistime k jakemu soustredeni se vaze nove vytvarena galerie |
||||
|
prednasky = Seznam.objects.first() |
||||
|
# obsluha formulare umoznujiciho multiple nahravani fotek |
||||
|
if request.method == 'POST': |
||||
|
form = NewPrednaskyForm(request.POST, request.FILES) |
||||
|
if form.is_valid(): |
||||
|
jmeno = form.cleaned_data['ucastnik'] |
||||
|
for i in request.POST: |
||||
|
if i[0] == 'q': |
||||
|
hlasovani = Hlasovani() |
||||
|
print("q:"+i[1:]) |
||||
|
hlasovani.prednaska = Prednaska.objects.filter(pk = int(i[1:]))[0] |
||||
|
hlasovani.body = int(request.POST[i]) |
||||
|
hlasovani.ucastnik = jmeno |
||||
|
hlasovani.save() |
||||
|
|
||||
|
# presmerovani na prave vzniklou galerii |
||||
|
return HttpResponseRedirect('./hotovo') |
||||
|
|
||||
|
else: |
||||
|
form = NewPrednaskyForm() |
||||
|
|
||||
|
return render(request, 'prednasky/Base.html', |
||||
|
{ 'form' : form, |
||||
|
'prednasky' : prednasky, |
||||
|
}) |
||||
|
|
||||
|
def Prednaska_hotovo(request): |
||||
|
return render(request, 'prednasky/hotovo.html') |
||||
|
|
||||
|
|
||||
|
# Create your views here. |
Loading…
Reference in new issue