Popisnejsi url pro cislo a rocnik
This commit is contained in:
parent
4bf299bf25
commit
7fac56f29a
3 changed files with 39 additions and 5 deletions
|
@ -223,7 +223,7 @@ class Rocnik(SeminarModelBase):
|
||||||
return self.prvni_rok + 1
|
return self.prvni_rok + 1
|
||||||
|
|
||||||
def verejne_url(self):
|
def verejne_url(self):
|
||||||
return reverse('seminar_rocnik', kwargs={'pk': self.id})
|
return reverse('seminar_rocnik', kwargs={'rocnik': self.rocnik})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cached_rocnik(cls, r_id):
|
def cached_rocnik(cls, r_id):
|
||||||
|
@ -279,7 +279,7 @@ class Cislo(SeminarModelBase):
|
||||||
verejne.boolean = True
|
verejne.boolean = True
|
||||||
|
|
||||||
def verejne_url(self):
|
def verejne_url(self):
|
||||||
return reverse('seminar_cislo', kwargs={'pk': self.id})
|
return reverse('seminar_cislo', kwargs={'rocnik': self.rocnik.rocnik, 'cislo': self.cislo})
|
||||||
|
|
||||||
def nasledujici(self):
|
def nasledujici(self):
|
||||||
u"Vrací None, pokud je toto poslední"
|
u"Vrací None, pokud je toto poslední"
|
||||||
|
|
|
@ -6,9 +6,10 @@ urlpatterns = patterns('',
|
||||||
url(r'^co-je-MaM/organizatori/$', views.CojemamOrganizatoriView.as_view()),
|
url(r'^co-je-MaM/organizatori/$', views.CojemamOrganizatoriView.as_view()),
|
||||||
|
|
||||||
url(r'^archiv/cisla/$', views.CislaView.as_view()),
|
url(r'^archiv/cisla/$', views.CislaView.as_view()),
|
||||||
url(r'^archiv/cisla/rocnik/(?P<pk>\d+)/$', views.RocnikView.as_view(), name='seminar_rocnik'),
|
|
||||||
url(r'^archiv/cisla/cislo/(?P<pk>\d+)/$', views.CisloView.as_view(), name='seminar_cislo'),
|
url(r'^rocnik/(?P<rocnik>\d+)/$', views.RocnikView.as_view(), name='seminar_rocnik'),
|
||||||
url(r'^archiv/cisla/problem/(?P<pk>\d+)/$', views.ProblemView.as_view(), name='seminar_problem'),
|
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>\d+)/$', views.CisloView.as_view(), name='seminar_cislo'),
|
||||||
|
url(r'^problem/(?P<pk>\d+)/$', views.ProblemView.as_view(), name='seminar_problem'),
|
||||||
|
|
||||||
url(r'^soustredeni/(?P<pk>\d+)/$', views.SoustredeniView.as_view(), name='seminar_soustredeni'),
|
url(r'^soustredeni/(?P<pk>\d+)/$', views.SoustredeniView.as_view(), name='seminar_soustredeni'),
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ from django.shortcuts import get_object_or_404, render
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.http import Http404
|
||||||
|
|
||||||
from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik, Soustredeni
|
from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik, Soustredeni
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +28,20 @@ class RocnikView(generic.DetailView):
|
||||||
model = Rocnik
|
model = Rocnik
|
||||||
template_name = 'seminar/archiv/rocnik.html'
|
template_name = 'seminar/archiv/rocnik.html'
|
||||||
|
|
||||||
|
# Vlastni ziskavani objektu z databaze podle (Rocnik.rocnik)
|
||||||
|
def get_object(self, queryset=None):
|
||||||
|
if queryset is None:
|
||||||
|
queryset = self.get_queryset()
|
||||||
|
rocnik_arg = self.kwargs.get('rocnik')
|
||||||
|
queryset = queryset.filter(rocnik=rocnik_arg)
|
||||||
|
|
||||||
|
try:
|
||||||
|
obj = queryset.get()
|
||||||
|
except queryset.model.DoesNotExist:
|
||||||
|
raise Http404(_("No %(verbose_name)s found matching the query") %
|
||||||
|
{'verbose_name': queryset.model._meta.verbose_name})
|
||||||
|
return obj
|
||||||
|
|
||||||
class SoustredeniView(generic.DetailView):
|
class SoustredeniView(generic.DetailView):
|
||||||
model = Soustredeni
|
model = Soustredeni
|
||||||
template_name = 'seminar/archiv/soustredeni.html'
|
template_name = 'seminar/archiv/soustredeni.html'
|
||||||
|
@ -39,6 +56,22 @@ class RadekVysledkovky(object):
|
||||||
class CisloView(generic.DetailView):
|
class CisloView(generic.DetailView):
|
||||||
model = Cislo
|
model = Cislo
|
||||||
template_name = 'seminar/archiv/cislo.html'
|
template_name = 'seminar/archiv/cislo.html'
|
||||||
|
|
||||||
|
# Vlastni ziskavani objektu z databaze podle (Rocnik.rocnik)
|
||||||
|
def get_object(self, queryset=None):
|
||||||
|
if queryset is None:
|
||||||
|
queryset = self.get_queryset()
|
||||||
|
rocnik_arg = self.kwargs.get('rocnik')
|
||||||
|
cislo_arg = self.kwargs.get('cislo')
|
||||||
|
queryset = queryset.filter(rocnik__rocnik=rocnik_arg, cislo=cislo_arg)
|
||||||
|
|
||||||
|
try:
|
||||||
|
obj = queryset.get()
|
||||||
|
except queryset.model.DoesNotExist:
|
||||||
|
raise Http404(_("No %(verbose_name)s found matching the query") %
|
||||||
|
{'verbose_name': queryset.model._meta.verbose_name})
|
||||||
|
return obj
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(CisloView, self).get_context_data(**kwargs)
|
context = super(CisloView, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue