From 467c7c53b36409b480688073af0882428b742df1 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Wed, 1 Apr 2015 14:01:13 +0200 Subject: [PATCH] Nove sketche views pro seminar --- mamweb/templates/base.html | 2 +- mamweb/templates/menu.html | 19 ++----------------- mamweb/urls.py | 1 + seminar/models.py | 22 +++++++++++++++++++++- seminar/templates/seminar/cislo.html | 22 ++++++++++++++++++++-- seminar/templates/seminar/problem.html | 6 +++++- seminar/templates/seminar/rocnik.html | 18 ++++++++++++++++++ seminar/urls.py | 3 ++- seminar/views.py | 6 +++++- 9 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 seminar/templates/seminar/rocnik.html diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index ec7a70e9..23ca8289 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -18,7 +18,7 @@
- Menu + {% include "menu.html" %}
{% block content %} diff --git a/mamweb/templates/menu.html b/mamweb/templates/menu.html index 64db1d25..96879514 100644 --- a/mamweb/templates/menu.html +++ b/mamweb/templates/menu.html @@ -1,18 +1,3 @@ -{% load i18n menu_tags cache %} +{% load i18n cache %} -{% for child in children %} - - - - -{% if class and forloop.last and not forloop.parentloop %} -{% endif %} -{% endfor %} +MENU diff --git a/mamweb/urls.py b/mamweb/urls.py index 28e43361..1960c7b8 100644 --- a/mamweb/urls.py +++ b/mamweb/urls.py @@ -7,6 +7,7 @@ from django.conf import settings urlpatterns = i18n_patterns('', url(r'^admin/', include(admin.site.urls)), # NOQA + url(r'^r/', include('django.conf.urls.shortcut')), url(r'^admin_tools/', include('admin_tools.urls')), url(r'^ckeditor/', include('ckeditor.urls')), url(r'^', include('seminar.urls')), diff --git a/seminar/models.py b/seminar/models.py index 9863ee4e..2162c004 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -9,6 +9,7 @@ from django.utils import timezone from django.conf import settings from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import force_unicode +from django.core.urlresolvers import reverse from django_countries.fields import CountryField from solo.models import SingletonModel @@ -161,6 +162,12 @@ class Rocnik(models.Model): else: return force_unicode(self.rocnik) + def verejna_cisla(self): + return [c for c in self.cisla.all() if c.verejne()] + + def druhy_rok(self): + return self.prvni_rok + 1 + @python_2_unicode_compatible class Cislo(models.Model): @@ -173,7 +180,7 @@ class Cislo(models.Model): # Interní ID id = models.AutoField(primary_key = True) - rocnik = models.ForeignKey(Rocnik, verbose_name=u'ročník') + rocnik = models.ForeignKey(Rocnik, verbose_name=u'ročník', related_name='cisla') cislo = models.CharField(u'název čísla', max_length=32, help_text=u'Většinou jen "1", vyjímečně "7-8", lexikograficky určije pořadí v ročníku!') @@ -191,6 +198,12 @@ class Cislo(models.Model): def __str__(self): return force_unicode(u'%s' % (self.kod(),)) + def verejne(self): + return (self.datum_vydani and self.datum_vydani <= datetime.date.today()) + + def get_absolute_url(self): + return reverse('seminar.cislo', args=[str(self.id)]) + @python_2_unicode_compatible class Problem(models.Model): @@ -252,6 +265,13 @@ class Problem(models.Model): def __str__(self): return force_unicode(u'%s (%s)' % (self.nazev, self.stav)) + def kod_v_rocniku(self): + if self.typ == self.TYP_ULOHA: + return force_unicode(u"%s.u%s" % (self.cislo_zadani.cislo, self.kod,)) + if self.typ == self.TYP_TEMA: + return force_unicode(u"t%s" % (self.kod,)) + return '' + @python_2_unicode_compatible class Reseni(models.Model): diff --git a/seminar/templates/seminar/cislo.html b/seminar/templates/seminar/cislo.html index f31a747f..be2b7df3 100644 --- a/seminar/templates/seminar/cislo.html +++ b/seminar/templates/seminar/cislo.html @@ -3,14 +3,32 @@ {% block content %}
-

Číslo {{ cislo }} [id {{ cislo.id}}]

+

Číslo {{ cislo }}

+ +

Ročník {% url 'seminar.rocnik' cislo.rocnik.id %} + +

Zadané problémy

+ + +

Řešené problémy

+ + +

Výsledkovka

# Jméno {% for p in problemy %} - {{ p.cislo_zadani.cislo }}.{{ p.kod }} + {{ p.cislo_zadani.cislo }}.{{ p.kod }} {% endfor %} Sum Celkem diff --git a/seminar/templates/seminar/problem.html b/seminar/templates/seminar/problem.html index 26559344..646bf7a0 100644 --- a/seminar/templates/seminar/problem.html +++ b/seminar/templates/seminar/problem.html @@ -3,7 +3,11 @@ {% block content %}
-

Problém {{ problem.nazev }}

+

Problém {{ problem.kod_v_rocniku }} {{ problem.nazev }}

+ +

Zadáno v čísle {{ problem.cislo_zadani.kod }}, +

řešeno v čísle {{ problem.cislo_reseni.kod }}, +

Text

{{ problem.text_problemu |safe }} diff --git a/seminar/templates/seminar/rocnik.html b/seminar/templates/seminar/rocnik.html new file mode 100644 index 00000000..4d202129 --- /dev/null +++ b/seminar/templates/seminar/rocnik.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} +{% load staticfiles sekizai_tags %} + +{% block content %} +
+

Ročník {{ rocnik.roman }}

+ +

Ročník číslo {{ rocnik.rocnik }} ({{ rocnik.prvni_rok }}/{{ rocnik.druhy_rok }}) + +

+ +
+{% endblock content %} + diff --git a/seminar/urls.py b/seminar/urls.py index 869b59ad..08884bb7 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -2,7 +2,8 @@ from django.conf.urls import patterns, url from . import views urlpatterns = patterns('', - url(r'^problem/(?P\d+)/$', views.ProblemView.as_view(), name='seminar.problem'), + url(r'^rocnik/(?P\d+)/$', views.RocnikView.as_view(), name='seminar.rocnik'), url(r'^cislo/(?P\d+)/$', views.CisloView.as_view(), name='seminar.cislo'), + url(r'^problem/(?P\d+)/$', views.ProblemView.as_view(), name='seminar.problem'), url(r'^zadani/$', 'seminar.views.AktualZadaniView'), ) diff --git a/seminar/views.py b/seminar/views.py index 219413a1..0f582e59 100644 --- a/seminar/views.py +++ b/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, Reseni, VysledkyKCislu, Nastaveni +from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik def AktualZadaniView(request): @@ -12,6 +12,10 @@ def AktualZadaniView(request): }, ) +class RocnikView(generic.DetailView): + model = Rocnik + template_name = 'seminar/rocnik.html' + class ProblemView(generic.DetailView): model = Problem template_name = 'seminar/problem.html'