Modely: spolecny zaklad, url resolve, model Soustredeni
This commit is contained in:
parent
05a337c6f8
commit
eb4aaccccb
3 changed files with 203 additions and 21 deletions
71
seminar/migrations/0003_auto_20150511_0947.py
Normal file
71
seminar/migrations/0003_auto_20150511_0947.py
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('seminar', '0002_add_body_views'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='VysledkyKCislu',
|
||||||
|
fields=[
|
||||||
|
('dummy_id', models.CharField(max_length=32, serialize=False, verbose_name='dummy ID pro view', primary_key=True, db_column=b'id')),
|
||||||
|
('body', models.IntegerField(verbose_name='body za \u010d\xedslo', db_column=b'body')),
|
||||||
|
('body_celkem', models.IntegerField(verbose_name='body celkem do \u010d\xedsla', db_column=b'body_celkem')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
'db_table': 'seminar_body_k_cislu',
|
||||||
|
'managed': False,
|
||||||
|
},
|
||||||
|
bases=(models.Model,),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='VysledkyZaCislo',
|
||||||
|
fields=[
|
||||||
|
('dummy_id', models.CharField(max_length=32, serialize=False, verbose_name='dummy ID pro view', primary_key=True, db_column=b'id')),
|
||||||
|
('body', models.IntegerField(verbose_name='body za \u010d\xedslo', db_column=b'body')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
'db_table': 'seminar_body_za_cislo',
|
||||||
|
'managed': False,
|
||||||
|
},
|
||||||
|
bases=(models.Model,),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Soustredeni',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(serialize=False, primary_key=True)),
|
||||||
|
('datum_zacatku', models.DateField(help_text='Prvn\xed den soust\u0159ed\u011bn\xed', null=True, verbose_name='datum za\u010d\xe1tku', blank=True)),
|
||||||
|
('datum_konce', models.DateField(help_text='Posledn\xed den soust\u0159ed\u011bn\xed', null=True, verbose_name='datum konce', blank=True)),
|
||||||
|
('misto', models.CharField(default=b'', help_text='M\xedsto (n\xe1zev obce, voliteln\u011b t\xe9\u017e objektu', max_length=256, verbose_name='m\xedsto soust\u0159ed\u011bn\xed', blank=True)),
|
||||||
|
('rocnik', models.ForeignKey(related_name='soustredeni', verbose_name='ro\u010dn\xedk', to='seminar.Rocnik')),
|
||||||
|
('ucastnici', models.ManyToManyField(help_text='Seznam \xfa\u010dastn\xedk\u016f soust\u0159ed\u011bn\xed', to='seminar.Resitel', db_table=b'seminar_soustredeni_ucastnici', verbose_name='\xfa\u010dastn\xedci soust\u0159ed\u011bn\xed')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'ordering': ['rocnik__rocnik', 'datum_zacatku'],
|
||||||
|
'db_table': 'seminar_soustredeni',
|
||||||
|
'verbose_name': 'Soust\u0159ed\u011bn\xed',
|
||||||
|
'verbose_name_plural': 'Soust\u0159ed\u011bn\xed',
|
||||||
|
},
|
||||||
|
bases=(models.Model,),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='cislo',
|
||||||
|
name='cislo',
|
||||||
|
field=models.CharField(help_text='V\u011bt\u0161inou jen "1", vyj\xedme\u010dn\u011b "7-8", lexikograficky ur\u010dije po\u0159ad\xed v ro\u010dn\xedku!', max_length=32, verbose_name='n\xe1zev \u010d\xedsla'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='cislo',
|
||||||
|
name='rocnik',
|
||||||
|
field=models.ForeignKey(related_name='cisla', verbose_name='ro\u010dn\xedk', to='seminar.Rocnik'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
]
|
38
seminar/migrations/0004_auto_20150511_1215.py
Normal file
38
seminar/migrations/0004_auto_20150511_1215.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('seminar', '0003_auto_20150511_0947'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='cislo',
|
||||||
|
name='verejne_db',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='\u010d\xedslo zve\u0159ejn\u011bno', db_column=b'verejne'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='reseni',
|
||||||
|
name='poznamka',
|
||||||
|
field=models.TextField(help_text='Neve\u0159ejn\xe1 pozn\xe1mka k \u0159e\u0161en\xed (plain text)', verbose_name='neve\u0159ejn\xe1 pozn\xe1mka', blank=True),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='resitel',
|
||||||
|
name='poznamka',
|
||||||
|
field=models.TextField(help_text='Neve\u0159ejn\xe1 pozn\xe1mka k \u0159e\u0161iteli (plain text)', verbose_name='neve\u0159ejn\xe1 pozn\xe1mka', blank=True),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='soustredeni',
|
||||||
|
name='verejne_db',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='soust\u0159ed\u011bn\xed zve\u0159ejn\u011bno', db_column=b'verejne'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
]
|
|
@ -9,17 +9,35 @@ from django.utils import timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
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.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
from django_countries.fields import CountryField
|
from django_countries.fields import CountryField
|
||||||
from solo.models import SingletonModel
|
from solo.models import SingletonModel
|
||||||
|
|
||||||
class SeminarModel(models.Model):
|
from seminar.utils import roman
|
||||||
|
|
||||||
|
# TODO společná báze (admin url, url, veřejné, ...)
|
||||||
|
class SeminarModelBase(models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
def verejne(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def public_url(self):
|
||||||
|
if self.Meta.url_name:
|
||||||
|
return reverse(self.Meta.url_name,
|
||||||
|
kwargs={'id': self.id, 'pk': self.id})
|
||||||
|
return None
|
||||||
|
|
||||||
|
def admin_url(self):
|
||||||
|
model_name = self.__class__.__name__.lower()
|
||||||
|
return reverse('admin:seminar_%s_change'%(model_name, ), args=(self.id, ))
|
||||||
|
|
||||||
|
def verejne_url(self):
|
||||||
|
return None
|
||||||
|
|
||||||
#
|
#
|
||||||
# Mělo by být částečně vytaženo z Aesopa
|
# Mělo by být částečně vytaženo z Aesopa
|
||||||
|
@ -27,7 +45,7 @@ class SeminarModel(models.Model):
|
||||||
#
|
#
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Skola(models.Model):
|
class Skola(SeminarModelBase):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'seminar_skoly'
|
db_table = 'seminar_skoly'
|
||||||
|
@ -72,7 +90,7 @@ class Skola(models.Model):
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Resitel(models.Model):
|
class Resitel(SeminarModelBase):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'seminar_resitele'
|
db_table = 'seminar_resitele'
|
||||||
|
@ -137,6 +155,9 @@ class Resitel(models.Model):
|
||||||
stat = CountryField(u'stát', default='CZ',
|
stat = CountryField(u'stát', default='CZ',
|
||||||
help_text=u'ISO 3166-1 kód země velkými písmeny (CZ, SK, ...)')
|
help_text=u'ISO 3166-1 kód země velkými písmeny (CZ, SK, ...)')
|
||||||
|
|
||||||
|
poznamka = models.TextField(u'neveřejná poznámka', blank=True,
|
||||||
|
help_text=u'Neveřejná poznámka k řešiteli (plain text)')
|
||||||
|
|
||||||
def plne_jmeno(self):
|
def plne_jmeno(self):
|
||||||
return force_unicode(u'%s %s' % (self.jmeno, self.prijmeni))
|
return force_unicode(u'%s %s' % (self.jmeno, self.prijmeni))
|
||||||
|
|
||||||
|
@ -145,7 +166,7 @@ class Resitel(models.Model):
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Rocnik(models.Model):
|
class Rocnik(SeminarModelBase):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'seminar_rocniky'
|
db_table = 'seminar_rocniky'
|
||||||
|
@ -169,6 +190,9 @@ class Rocnik(models.Model):
|
||||||
else:
|
else:
|
||||||
return force_unicode(self.rocnik)
|
return force_unicode(self.rocnik)
|
||||||
|
|
||||||
|
def verejne(self):
|
||||||
|
return len(self.verejne_cisla()) > 0
|
||||||
|
|
||||||
def verejna_cisla(self):
|
def verejna_cisla(self):
|
||||||
vc = [c for c in self.cisla.all() if c.verejne()]
|
vc = [c for c in self.cisla.all() if c.verejne()]
|
||||||
vc.sort(key=lambda c: c.cislo)
|
vc.sort(key=lambda c: c.cislo)
|
||||||
|
@ -181,8 +205,12 @@ class Rocnik(models.Model):
|
||||||
def druhy_rok(self):
|
def druhy_rok(self):
|
||||||
return self.prvni_rok + 1
|
return self.prvni_rok + 1
|
||||||
|
|
||||||
|
def verejne_url(self):
|
||||||
|
return reverse('seminar_rocnik', kwargs={'pk': self.id})
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Cislo(models.Model):
|
class Cislo(SeminarModelBase):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'seminar_cisla'
|
db_table = 'seminar_cisla'
|
||||||
|
@ -204,6 +232,8 @@ class Cislo(models.Model):
|
||||||
datum_deadline = models.DateField(u'datum deadline', blank=True, null=True,
|
datum_deadline = models.DateField(u'datum deadline', blank=True, null=True,
|
||||||
help_text=u'Datum pro příjem řešení úloh zadaných v tomto čísle')
|
help_text=u'Datum pro příjem řešení úloh zadaných v tomto čísle')
|
||||||
|
|
||||||
|
verejne_db = models.BooleanField(u'číslo zveřejněno', db_column='verejne', default=False)
|
||||||
|
|
||||||
def kod(self):
|
def kod(self):
|
||||||
return u'%s.%s' % (self.rocnik.rocnik, self.cislo)
|
return u'%s.%s' % (self.rocnik.rocnik, self.cislo)
|
||||||
kod.short_description = u'Kód čísla'
|
kod.short_description = u'Kód čísla'
|
||||||
|
@ -212,14 +242,14 @@ class Cislo(models.Model):
|
||||||
return force_unicode(u'%s' % (self.kod(),))
|
return force_unicode(u'%s' % (self.kod(),))
|
||||||
|
|
||||||
def verejne(self):
|
def verejne(self):
|
||||||
return (self.datum_vydani and self.datum_vydani <= datetime.date.today())
|
return self.verejne_db
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def verejne_url(self):
|
||||||
return reverse('seminar.cislo', args=[str(self.id)])
|
return reverse('seminar_cislo', kwargs={'pk': self.id})
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Problem(models.Model):
|
class Problem(SeminarModelBase):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'seminar_problemy'
|
db_table = 'seminar_problemy'
|
||||||
|
@ -285,9 +315,15 @@ class Problem(models.Model):
|
||||||
return force_unicode(u"t%s" % (self.kod,))
|
return force_unicode(u"t%s" % (self.kod,))
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def verejne(self):
|
||||||
|
return (self.cislo_zadani and self.cislo_zadani.verejne())
|
||||||
|
|
||||||
|
def verejne_url(self):
|
||||||
|
return reverse('seminar_problem', kwargs={'pk': self.id})
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Reseni(models.Model):
|
class Reseni(SeminarModelBase):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'seminar_reseni'
|
db_table = 'seminar_reseni'
|
||||||
|
@ -308,6 +344,9 @@ class Reseni(models.Model):
|
||||||
|
|
||||||
timestamp = models.DateTimeField(u'vytvořeno', auto_now=True)
|
timestamp = models.DateTimeField(u'vytvořeno', auto_now=True)
|
||||||
|
|
||||||
|
poznamka = models.TextField(u'neveřejná poznámka', blank=True,
|
||||||
|
help_text=u'Neveřejná poznámka k řešení (plain text)')
|
||||||
|
|
||||||
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))
|
||||||
|
|
||||||
|
@ -321,8 +360,9 @@ def generate_filename(self, filename):
|
||||||
clean)
|
clean)
|
||||||
return os.path.join(settings.SEMINAR_RESENI_DIRNAME, datedir, fname)
|
return os.path.join(settings.SEMINAR_RESENI_DIRNAME, datedir, fname)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class PrilohaReseni(models.Model):
|
class PrilohaReseni(SeminarModelBase):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'seminar_priloha_reseni'
|
db_table = 'seminar_priloha_reseni'
|
||||||
|
@ -343,7 +383,44 @@ class PrilohaReseni(models.Model):
|
||||||
return force_unicode(self.soubor)
|
return force_unicode(self.soubor)
|
||||||
|
|
||||||
|
|
||||||
class VysledkyBase(models.Model):
|
@python_2_unicode_compatible
|
||||||
|
class Soustredeni(SeminarModelBase):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = 'seminar_soustredeni'
|
||||||
|
verbose_name = u'Soustředění'
|
||||||
|
verbose_name_plural = u'Soustředění'
|
||||||
|
ordering = ['rocnik__rocnik', 'datum_zacatku']
|
||||||
|
|
||||||
|
# Interní ID
|
||||||
|
id = models.AutoField(primary_key = True)
|
||||||
|
|
||||||
|
rocnik = models.ForeignKey(Rocnik, verbose_name=u'ročník', related_name='soustredeni')
|
||||||
|
|
||||||
|
datum_zacatku = models.DateField(u'datum začátku', blank=True, null=True,
|
||||||
|
help_text=u'První den soustředění')
|
||||||
|
|
||||||
|
datum_konce = models.DateField(u'datum konce', blank=True, null=True,
|
||||||
|
help_text=u'Poslední den soustředění')
|
||||||
|
|
||||||
|
verejne_db = models.BooleanField(u'soustředění zveřejněno', db_column='verejne', default=False)
|
||||||
|
|
||||||
|
misto = models.CharField(u'místo soustředění', max_length=256, blank=True, default='',
|
||||||
|
help_text=u'Místo (název obce, volitelně též objektu')
|
||||||
|
|
||||||
|
ucastnici = models.ManyToManyField(Resitel, verbose_name=u'účastníci soustředění',
|
||||||
|
help_text=u'Seznam účastníků soustředění', db_table='seminar_soustredeni_ucastnici')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return force_unicode(u'%s (%s)' % (self.misto, self.datum_zacatek))
|
||||||
|
|
||||||
|
def verejne(self):
|
||||||
|
return self.verejne_db
|
||||||
|
|
||||||
|
def verejne_url(self):
|
||||||
|
return reverse('seminar_soustredeni', kwargs={'pk': self.id})
|
||||||
|
|
||||||
|
class VysledkyBase(SeminarModelBase):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = u'Řádek výsledkovky'
|
verbose_name = u'Řádek výsledkovky'
|
||||||
|
@ -400,12 +477,8 @@ class Nastaveni(SingletonModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'Nastavení semináře'
|
return u'Nastavení semináře'
|
||||||
|
|
||||||
|
def admin_url(self):
|
||||||
def roman(num):
|
return reverse('admin:seminar_nastaveni_change', args=(self.id, ))
|
||||||
ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
|
|
||||||
nums = ('M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I')
|
def verejne(self):
|
||||||
res = ""
|
return False
|
||||||
for i, n in zip(ints, nums):
|
|
||||||
res += n * (num // i)
|
|
||||||
num %= i
|
|
||||||
return res
|
|
||||||
|
|
Loading…
Reference in a new issue