diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 1e95ddad..a1025b07 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -121,6 +121,7 @@ INSTALLED_APPS = ( 'seminar', 'galerie', 'korektury', + 'prednasky', # Admin upravy: diff --git a/prednasky/__init__.py b/prednasky/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prednasky/admin.py b/prednasky/admin.py new file mode 100644 index 00000000..bbcea848 --- /dev/null +++ b/prednasky/admin.py @@ -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) diff --git a/prednasky/forms.py b/prednasky/forms.py new file mode 100644 index 00000000..969232e3 --- /dev/null +++ b/prednasky/forms.py @@ -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) + + + diff --git a/prednasky/migrations/0001_initial.py b/prednasky/migrations/0001_initial.py new file mode 100644 index 00000000..c3510548 --- /dev/null +++ b/prednasky/migrations/0001_initial.py @@ -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'), + ), + ] diff --git a/prednasky/migrations/0002_auto_20160417_2347.py b/prednasky/migrations/0002_auto_20160417_2347.py new file mode 100644 index 00000000..f3527e75 --- /dev/null +++ b/prednasky/migrations/0002_auto_20160417_2347.py @@ -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')]), + ), + ] diff --git a/prednasky/migrations/__init__.py b/prednasky/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prednasky/models.py b/prednasky/models.py new file mode 100644 index 00000000..0f94f500 --- /dev/null +++ b/prednasky/models.py @@ -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) + diff --git a/prednasky/templates/prednasky/Base.html b/prednasky/templates/prednasky/Base.html new file mode 100644 index 00000000..6b96372b --- /dev/null +++ b/prednasky/templates/prednasky/Base.html @@ -0,0 +1,40 @@ +{% extends 'base.html' %} + +{% load humanize %} +{% load staticfiles %} + +{% block title %} +Hlasování o přednáškách +{% endblock %} + +{% block content %} + +

+Jak moc by ses chtěl(a) zúčastnit následujících přednášek? +
+Obtížnost 1 je nejlehčí, 3 nejtěžší. +

+ +
+ {% csrf_token %} + {{form.as_table}} +
+ + {% for p in prednasky.prednaska_set.all %} + + + + + {% if p.klicova %}{% endif%} + + + {% endfor %} + +

{{p.anotace}}

{{p.obor}}
{{p.obtiznost}}
{{p.klicova}}
Hodnocení: + rozhodně nechci + je mi to jedno + rozhodně chci +
 
+
+ +{% endblock %} diff --git a/prednasky/templates/prednasky/hotovo.html b/prednasky/templates/prednasky/hotovo.html new file mode 100644 index 00000000..3e621b39 --- /dev/null +++ b/prednasky/templates/prednasky/hotovo.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} + +{% load humanize %} +{% load staticfiles %} + + +{% block content %} + +

Děkujeme.

+ +{% endblock %} diff --git a/prednasky/tests.py b/prednasky/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/prednasky/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/prednasky/views.py b/prednasky/views.py new file mode 100644 index 00000000..bcaa32f5 --- /dev/null +++ b/prednasky/views.py @@ -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. diff --git a/seminar/models.py b/seminar/models.py index 1ffe16d2..566b9d8d 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -550,6 +550,7 @@ class Reseni(SeminarModelBase): # TODO vyresit partial, tak aby slo migrovat #def generate_filename(self, filename, directory): # Django 1.9 podporuje partial + def generate_filename(self, filename): clean = filename.replace('/','-').replace('\0', '') datedir = timezone.now().strftime('%Y-%m') @@ -557,6 +558,7 @@ def generate_filename(self, filename): timezone.now().strftime('%Y-%m-%d-%H:%M'), clean) return os.path.join(settings.SEMINAR_RESENI_DIR, datedir, fname) + def generate_filename_konfera(self, filename): clean = filename.replace('/','-').replace('\0', '') datedir = timezone.now().strftime('%Y-%m') @@ -568,7 +570,6 @@ def generate_filename_konfera(self, filename): # return os.path.join(directory, datedir, fname) - @reversion.register(ignore_duplicate_revisions=True) @python_2_unicode_compatible class PrilohaReseni(SeminarModelBase): @@ -586,8 +587,6 @@ class PrilohaReseni(SeminarModelBase): timestamp = models.DateTimeField(u'vytvořeno', default=timezone.now, blank=True, editable=False) - #soubor = models.FileField(u'soubor', upload_to = partial(generate_filename,directory=settings.SEMINAR_RESENI_DIR))) - # TODO vyresit partial tak, aby slo migrovat soubor = models.FileField(u'soubor', upload_to = generate_filename) poznamka = models.TextField(u'neveřejná poznámka', blank=True, diff --git a/seminar/urls.py b/seminar/urls.py index 5f16d7d3..00d82ac4 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -3,10 +3,15 @@ from django.conf.urls import patterns, url from django.contrib.auth.decorators import user_passes_test from . import views, export from utils import staff_member_required +from prednasky.views import newPrednaska, Prednaska_hotovo staff_member_required = user_passes_test(lambda u: u.is_staff) urlpatterns = [ + # prednasky + url(r'^prednasky/$', newPrednaska), + url(r'^prednasky/hotovo$', Prednaska_hotovo), + url(r'^co-je-MaM/organizatori/$', views.CojemamOrganizatoriView.as_view(), name='organizatori'), url(r'^co-je-MaM/organizatori/organizovali/$', views.CojemamOrganizatoriStariView.as_view(), name='stari_organizatori'),