Cache a zrychleni na rocniky (hodne) a tez soustredeni_resitele
This commit is contained in:
parent
a1505485a1
commit
93b66fe0ec
2 changed files with 24 additions and 10 deletions
|
@ -90,6 +90,9 @@ class Soustredeni_UcastniciInline(admin.TabularInline):
|
||||||
fields = ['resitel', 'poznamka', ]
|
fields = ['resitel', 'poznamka', ]
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
def get_queryset(self, request):
|
||||||
|
qs = super(Soustredeni_UcastniciInline, self).get_queryset(request)
|
||||||
|
return qs.select_related('resitel', 'soustredeni')
|
||||||
|
|
||||||
### Resitel
|
### Resitel
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_unicode
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
|
||||||
from django_countries.fields import CountryField
|
from django_countries.fields import CountryField
|
||||||
from solo.models import SingletonModel
|
from solo.models import SingletonModel
|
||||||
|
@ -19,7 +21,6 @@ import reversion
|
||||||
|
|
||||||
from seminar.utils import roman
|
from seminar.utils import roman
|
||||||
|
|
||||||
# TODO společná báze (admin url, url, veřejné, ...)
|
|
||||||
class SeminarModelBase(models.Model):
|
class SeminarModelBase(models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -230,6 +231,16 @@ class Rocnik(SeminarModelBase):
|
||||||
def verejne_url(self):
|
def verejne_url(self):
|
||||||
return reverse('seminar_rocnik', kwargs={'pk': self.id})
|
return reverse('seminar_rocnik', kwargs={'pk': self.id})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def cached_rocnik(cls, r_id):
|
||||||
|
name = 'rocnik_%s' % (r_id, )
|
||||||
|
c = cache.get(name)
|
||||||
|
if c is None:
|
||||||
|
c = cls.objects.get(id=r_id)
|
||||||
|
cache.set(name, c, 300)
|
||||||
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@reversion.register(ignore_duplicate_revisions=True)
|
@reversion.register(ignore_duplicate_revisions=True)
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
|
@ -239,7 +250,7 @@ class Cislo(SeminarModelBase):
|
||||||
db_table = 'seminar_cisla'
|
db_table = 'seminar_cisla'
|
||||||
verbose_name = u'Číslo'
|
verbose_name = u'Číslo'
|
||||||
verbose_name_plural = u'Čísla'
|
verbose_name_plural = u'Čísla'
|
||||||
ordering = ['rocnik_id', 'cislo']
|
ordering = ['rocnik__rocnik', 'cislo']
|
||||||
|
|
||||||
# Interní ID
|
# Interní ID
|
||||||
id = models.AutoField(primary_key = True)
|
id = models.AutoField(primary_key = True)
|
||||||
|
@ -265,9 +276,9 @@ class Cislo(SeminarModelBase):
|
||||||
kod.short_description = u'Kód čísla'
|
kod.short_description = u'Kód čísla'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
#TODO: DB HOG
|
# Potenciální DB HOG, pokud by se ročník neckešoval
|
||||||
#return force_unicode(u'%s' % (self.kod(),))
|
r = Rocnik.cached_rocnik(self.rocnik_id)
|
||||||
return force_unicode(u'%s' % (self.cislo,))
|
return force_unicode(u'%s.%s' % (r.rocnik, self.cislo, ))
|
||||||
|
|
||||||
def verejne(self):
|
def verejne(self):
|
||||||
return self.verejne_db
|
return self.verejne_db
|
||||||
|
@ -416,7 +427,7 @@ class Reseni(SeminarModelBase):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return force_unicode(u"%s: %s (%sb)" % (self.resitel.plne_jmeno(), self.problem.nazev, self.body))
|
return force_unicode(u"%s: %s (%sb)" % (self.resitel.plne_jmeno(), self.problem.nazev, self.body))
|
||||||
#TODO: DB HOG
|
# NOTE: Potenciální DB HOG (bez select_related)
|
||||||
|
|
||||||
|
|
||||||
# PrilohaReseni method
|
# PrilohaReseni method
|
||||||
|
@ -516,7 +527,7 @@ class Soustredeni_Ucastnici(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return force_unicode(u'%s na %s' % (self.resitel, self.soustredeni, ))
|
return force_unicode(u'%s na %s' % (self.resitel, self.soustredeni, ))
|
||||||
#TODO: DB HOG
|
# NOTE: Poteciální DB HOG bez select_related
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
|
@ -539,7 +550,7 @@ class VysledkyBase(SeminarModelBase):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return force_unicode(u"%s: %sb (%s)" % (self.resitel.plne_jmeno(), self.body, str(self.cislo)))
|
return force_unicode(u"%s: %sb (%s)" % (self.resitel.plne_jmeno(), self.body, str(self.cislo)))
|
||||||
#NOTE: DB HOG (ale nepouzivany)
|
# NOTE: DB HOG (ale nepouzivany)
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class VysledkyZaCislo(VysledkyBase):
|
class VysledkyZaCislo(VysledkyBase):
|
||||||
|
@ -550,7 +561,7 @@ class VysledkyZaCislo(VysledkyBase):
|
||||||
managed = False
|
managed = False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
#NOTE: DB HOG (ale nepouzivany)
|
# NOTE: DB HOG (ale nepouzivany)
|
||||||
return force_unicode(u"%s: %sb (za %s)" % (self.resitel.plne_jmeno(), self.body, str(self.cislo)))
|
return force_unicode(u"%s: %sb (za %s)" % (self.resitel.plne_jmeno(), self.body, str(self.cislo)))
|
||||||
|
|
||||||
|
|
||||||
|
@ -565,7 +576,7 @@ class VysledkyKCislu(VysledkyBase):
|
||||||
body_celkem = models.IntegerField(u'body celkem do čísla', db_column='body_celkem')
|
body_celkem = models.IntegerField(u'body celkem do čísla', db_column='body_celkem')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
#NOTE: DB HOG (ale nepouzivany)
|
# NOTE: DB HOG (ale nepouzivany)
|
||||||
return force_unicode(u"%s: %sb / %sb (do %s)" % (self.resitel.plne_jmeno(), self.body, self.body_celkem, str(self.cislo)))
|
return force_unicode(u"%s: %sb / %sb (do %s)" % (self.resitel.plne_jmeno(), self.body, self.body_celkem, str(self.cislo)))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue