|
|
@ -1,14 +1,23 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
import os |
|
|
|
import datetime |
|
|
|
import random |
|
|
|
|
|
|
|
from django.db import models |
|
|
|
from django.contrib import auth |
|
|
|
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 feincms.models import Base |
|
|
|
|
|
|
|
# |
|
|
|
# Mělo by být částečně vytaženo z Aesopa |
|
|
|
# viz https://ovvp.mff.cuni.cz/wiki/aesop/export-skol. |
|
|
|
# |
|
|
|
|
|
|
|
@python_2_unicode_compatible |
|
|
|
class Skola(models.Model): |
|
|
|
|
|
|
|
class Meta: |
|
|
@ -48,10 +57,11 @@ class Skola(models.Model): |
|
|
|
stat = models.CharField(u'kód státu', max_length=2, default='CZ', |
|
|
|
help_text=u'ISO 3166-1 kód zeme velkými písmeny (CZ, SK, ...)') |
|
|
|
|
|
|
|
def __unicode__(self): |
|
|
|
return u'%s, %s' % (self.nazev, self.mesto) |
|
|
|
def __str__(self): |
|
|
|
return force_unicode(u'%s, %s' % (self.nazev, self.mesto)) |
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible |
|
|
|
class Resitel(models.Model): |
|
|
|
|
|
|
|
class Meta: |
|
|
@ -116,10 +126,14 @@ class Resitel(models.Model): |
|
|
|
stat = models.CharField(u'kód státu', max_length=2, |
|
|
|
help_text=u'ISO 3166-1 kód zeme velkými písmeny (CZ, SK, ...)', default='CZ') |
|
|
|
|
|
|
|
def __unicode__(self): |
|
|
|
return u'%s %s' % (self.jmeno, self.prijmeni) |
|
|
|
def plne_jmeno(self): |
|
|
|
return force_unicode(u'%s %s' % (self.jmeno, self.prijmeni)) |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return force_unicode(self.plne_jmeno()) |
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible |
|
|
|
class Rocnik(models.Model): |
|
|
|
|
|
|
|
class Meta: |
|
|
@ -131,9 +145,15 @@ class Rocnik(models.Model): |
|
|
|
# Interní ID |
|
|
|
id = models.AutoField(primary_key = True) |
|
|
|
|
|
|
|
rocnik = models.IntegerField(u'číslo ročníku') |
|
|
|
prvni_rok = models.IntegerField(u'první rok') |
|
|
|
|
|
|
|
rocnik = models.CharField(u'číslo ročníku', max_length=16) |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return force_unicode(u'%s (%d/%d)' % (self.rocnik, self.prvni_rok, self.prvni_rok+1)) |
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible |
|
|
|
class Cislo(models.Model): |
|
|
|
|
|
|
|
class Meta: |
|
|
@ -158,9 +178,14 @@ class Cislo(models.Model): |
|
|
|
|
|
|
|
def kod(self): |
|
|
|
return u'%s.%s' % (self.rocnik.rocnik, self.cislo) |
|
|
|
kod.short_description = u'Kód čísla' |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return force_unicode(u'%s' % (self.kod(),)) |
|
|
|
|
|
|
|
class Problem(models.Model): |
|
|
|
|
|
|
|
@python_2_unicode_compatible |
|
|
|
class Problem(Base): |
|
|
|
|
|
|
|
class Meta: |
|
|
|
db_table = 'seminar_problemy' |
|
|
@ -170,6 +195,7 @@ class Problem(models.Model): |
|
|
|
# Interní ID |
|
|
|
id = models.AutoField(primary_key = True) |
|
|
|
|
|
|
|
# Název |
|
|
|
nazev = models.CharField(u'název', max_length=256) |
|
|
|
|
|
|
|
TYP_ULOHA = 'uloha' |
|
|
@ -196,33 +222,99 @@ class Problem(models.Model): |
|
|
|
] |
|
|
|
stav = models.CharField(u'stav problému', max_length=32, choices=STAV_CHOICES, blank=False, default=STAV_NAVRH) |
|
|
|
|
|
|
|
text_org = None |
|
|
|
# text_problemu_org = PlaceholderField('text_problemu_org', related_name='problem_text_org', |
|
|
|
# verbose_name=u'organizátorský (neveřejný) text') |
|
|
|
|
|
|
|
text_verejny = None |
|
|
|
# text_problemu = PlaceholderField('text_problemu', related_name='problem_text', |
|
|
|
# verbose_name=u'veřejný text zadání a řešení') |
|
|
|
|
|
|
|
zadavatel |
|
|
|
autor = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'autor problému', related_name='autor_uloh') |
|
|
|
|
|
|
|
opravovatel |
|
|
|
opravovatel = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'opravovatel', null=True, blank=True, |
|
|
|
related_name='opravovatel_uloh') |
|
|
|
|
|
|
|
kod = models.CharField(u'lokální kód', max_length=32, blank=True, default='', |
|
|
|
help_text=u'Číslo/kód úlohy v čísle nebo kód tématu/článku/seriálu v ročníku') |
|
|
|
|
|
|
|
cislo_zadani = models.ForeignKey(Cislo, verbose_name=u'číslo zadání', blank=True, null=True) |
|
|
|
|
|
|
|
cislo_reseni = models.ForeignKey(Cislo, verbose_name=u'číslo řešení', blank=True, null=True, |
|
|
|
help_text=u'Číslo s řešením úlohy. Jen pri ') |
|
|
|
# |
|
|
|
# |
|
|
|
# class Reseni(models.Model): |
|
|
|
# |
|
|
|
# class Meta: |
|
|
|
# db_table = 'seminar_reseni' |
|
|
|
# verbose_name = u'Řešení' |
|
|
|
# verbose_name_plural = u'Řešení' |
|
|
|
# ordering = ['rocnik__rocnik', 'cislo'] |
|
|
|
# |
|
|
|
# # Interní ID |
|
|
|
# id = models.AutoField(primary_key = True) |
|
|
|
# |
|
|
|
# |
|
|
|
# |
|
|
|
cislo_zadani = models.ForeignKey(Cislo, verbose_name=u'číslo zadání', blank=True, null=True, related_name=u'zadane_problemy') |
|
|
|
|
|
|
|
cislo_reseni = models.ForeignKey(Cislo, verbose_name=u'číslo řešení', blank=True, null=True, related_name=u'resene_problemy', |
|
|
|
help_text=u'Číslo s řešením úlohy, jen pro úlohy') |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return force_unicode(u'%s (%s)' % (self.nazev, self.stav)) |
|
|
|
|
|
|
|
from feincms.content.richtext.models import RichTextContent |
|
|
|
from feincms.content.image.models import ImageContent |
|
|
|
from feincms.content.medialibrary.models import MediaFileContent |
|
|
|
|
|
|
|
Problem.register_regions( |
|
|
|
('text_problemu', 'uveřejný text zadání a řešení'), |
|
|
|
('text_problemu_org', u'organizátorský (neveřejný) text') |
|
|
|
) |
|
|
|
Problem.create_content_type(RichTextContent) |
|
|
|
Problem.create_content_type( |
|
|
|
ImageContent, |
|
|
|
POSITION_CHOICES=( |
|
|
|
('default', 'Default position'), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible |
|
|
|
class Reseni(models.Model): |
|
|
|
|
|
|
|
class Meta: |
|
|
|
db_table = 'seminar_reseni' |
|
|
|
verbose_name = u'Řešení' |
|
|
|
verbose_name_plural = u'Řešení' |
|
|
|
ordering = ['problem', 'resitel'] |
|
|
|
|
|
|
|
# Interní ID |
|
|
|
id = models.AutoField(primary_key = True) |
|
|
|
|
|
|
|
problem = models.ForeignKey(Problem, verbose_name=u'problém', related_name='reseni') |
|
|
|
|
|
|
|
resitel = models.ForeignKey(Resitel, verbose_name=u'řešitel', related_name='reseni') |
|
|
|
|
|
|
|
body = models.IntegerField(u'body', blank=True, null=True) |
|
|
|
|
|
|
|
cislo_body = models.ForeignKey(Cislo, verbose_name=u'číslo pro body', related_name='bodovana_reseni', blank=True, null=True) |
|
|
|
|
|
|
|
timestamp = models.DateTimeField(u'vytvořeno', auto_now=True) |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return force_unicode(u"%s: %s" % (self.resitel.plne_jmeno(), self.problem.nazev)) |
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible |
|
|
|
class PrilohaReseni(models.Model): |
|
|
|
|
|
|
|
class Meta: |
|
|
|
db_table = 'seminar_priloha_reseni' |
|
|
|
verbose_name = u'Příloha řešení' |
|
|
|
verbose_name_plural = u'Přílohy řešení' |
|
|
|
ordering = ['reseni', 'timestamp'] |
|
|
|
|
|
|
|
# Interní ID |
|
|
|
id = models.AutoField(primary_key = True) |
|
|
|
|
|
|
|
reseni = models.ForeignKey(Reseni, verbose_name=u'řešení', related_name='prilohy') |
|
|
|
|
|
|
|
timestamp = models.DateTimeField(u'vytvořeno', auto_now=True) |
|
|
|
|
|
|
|
def generate_filename(self, filename): |
|
|
|
clean = filename.replace('/','-').replace('\0', '') |
|
|
|
datedir = datetime.datetime.now().strftime('%Y-%m') |
|
|
|
fname = "%s_%06d_%s" % ( |
|
|
|
datetime.datetime.now().strftime('%Y-%m-%d-%H:%M'), |
|
|
|
random.randint(0,999999), |
|
|
|
clean) |
|
|
|
return os.path.join(settings.SEMINAR_RESENI_DIRNAME, datedir, fname) |
|
|
|
|
|
|
|
soubor = models.FileField(u'soubor', upload_to = generate_filename) |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return force_unicode(self.soubor) |
|
|
|
|
|
|
|
|
|
|
|