|
|
|
import os
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.core.files.storage import FileSystemStorage
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
from reversion import revisions as reversion
|
|
|
|
from solo.models import SingletonModel
|
|
|
|
|
|
|
|
|
|
|
|
@reversion.register(ignore_duplicates=True)
|
|
|
|
class Nastaveni(SingletonModel):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = 'seminar_nastaveni'
|
|
|
|
verbose_name = 'Nastavení semináře'
|
|
|
|
|
|
|
|
# aktualni_rocnik = models.ForeignKey("tvorba.Rocnik", verbose_name='aktuální ročník',
|
|
|
|
# null=False, on_delete=models.PROTECT)
|
|
|
|
|
|
|
|
aktualni_cislo = models.ForeignKey("tvorba.Cislo", verbose_name='Aktuální číslo',
|
|
|
|
null=True, blank=False, on_delete=models.PROTECT,
|
|
|
|
)
|
|
|
|
|
|
|
|
cena_sous = models.IntegerField(null=False,
|
|
|
|
verbose_name="Účastnický poplatek za soustředění",
|
|
|
|
default=1000)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def aktualni_rocnik(self):
|
|
|
|
return self.aktualni_cislo.rocnik
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Nastavení semináře'
|
|
|
|
|
|
|
|
def admin_url(self):
|
|
|
|
return reverse('admin:various_nastaveni_change', args=(self.id, ))
|
|
|
|
|
|
|
|
def verejne(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class OverwriteStorage(FileSystemStorage):
|
|
|
|
""" Varianta FileSystemStorage, která v případě, že soubor cílového
|
|
|
|
jména již existuje, ho smaže a místo něj uloží soubor nový"""
|
|
|
|
def get_available_name(self,name, max_length=None):
|
|
|
|
if self.exists(name):
|
|
|
|
os.remove(os.path.join(self.location,name))
|
|
|
|
return super().get_available_name(name,max_length)
|
|
|
|
|
|
|
|
|
|
|
|
class SeminarModelBase(models.Model):
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
def verejne(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# def get_absolute_url(self):
|
|
|
|
# return "https://" + str(get_current_site(None)) + self.verejne_url()
|
|
|
|
|
|
|
|
def admin_url(self):
|
|
|
|
app_name = self._meta.app_label
|
|
|
|
model_name = self._meta.model_name
|
|
|
|
return reverse('admin:{}_{}_change'.format(app_name, model_name), args=(self.id, ))
|