mv SeminarModelBase a OverwriteStorage
This commit is contained in:
parent
a372aa1bc2
commit
62a42675f8
11 changed files with 44 additions and 58 deletions
|
@ -10,13 +10,13 @@ from django.utils import timezone
|
|||
from django.conf import settings
|
||||
|
||||
from tvorba.models import Problem, Deadline, Cislo, Uloha, aux_generate_filename
|
||||
from seminar.models import base as bm
|
||||
from various.models import SeminarModelBase
|
||||
|
||||
from odevzdavatko.utils import vzorecek_na_prepocet, inverze_vzorecku_na_prepocet
|
||||
from personalni.models import Resitel
|
||||
|
||||
@reversion.register(ignore_duplicates=True)
|
||||
class Reseni(bm.SeminarModelBase):
|
||||
class Reseni(SeminarModelBase):
|
||||
|
||||
class Meta:
|
||||
db_table = 'seminar_reseni'
|
||||
|
@ -88,7 +88,7 @@ class Reseni(bm.SeminarModelBase):
|
|||
# self.cislo_body = self.problem.cislo_reseni
|
||||
# super(Reseni, self).save(*args, **kwargs)
|
||||
|
||||
class Hodnoceni(bm.SeminarModelBase):
|
||||
class Hodnoceni(SeminarModelBase):
|
||||
class Meta:
|
||||
db_table = 'seminar_hodnoceni'
|
||||
verbose_name = 'Hodnocení'
|
||||
|
@ -181,7 +181,7 @@ def generate_filename(self, filename):
|
|||
|
||||
|
||||
@reversion.register(ignore_duplicates=True)
|
||||
class PrilohaReseni(bm.SeminarModelBase):
|
||||
class PrilohaReseni(SeminarModelBase):
|
||||
|
||||
class Meta:
|
||||
db_table = 'seminar_priloha_reseni'
|
||||
|
|
|
@ -11,7 +11,7 @@ from django_countries.fields import CountryField
|
|||
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from seminar.models.base import SeminarModelBase
|
||||
from various.models import SeminarModelBase
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# Generated by Django 2.2.24 on 2021-11-29 22:54
|
||||
|
||||
from django.db import migrations, models
|
||||
import seminar.models.tvorba
|
||||
import various.models
|
||||
import seminar.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -14,6 +15,6 @@ class Migration(migrations.Migration):
|
|||
migrations.AlterField(
|
||||
model_name='cislo',
|
||||
name='pdf',
|
||||
field=models.FileField(blank=True, help_text='PDF čísla, které si mohou řešitelé stáhnout', null=True, storage=seminar.models.tvorba.OverwriteStorage(), upload_to=seminar.models.tvorba.cislo_pdf_filename, verbose_name='pdf'),
|
||||
field=models.FileField(blank=True, help_text='PDF čísla, které si mohou řešitelé stáhnout', null=True, storage=various.models.OverwriteStorage(), upload_to=seminar.models.cislo_pdf_filename, verbose_name='pdf'),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
from .tvorba import *
|
||||
from .base import *
|
||||
|
||||
from various.models import Nastaveni
|
||||
from personalni.models import Organizator, Resitel, Skola, Prijemce, Osoba
|
||||
from soustredeni.models import Soustredeni, Soustredeni_Ucastnici, Soustredeni_Organizatori, Konfera, Konfery_Ucastnici
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
from django.urls import reverse
|
||||
from django.db import models
|
||||
|
||||
|
||||
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, ))
|
||||
|
||||
# def verejne_url(self):
|
||||
# return None
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
import os
|
||||
import logging
|
||||
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
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)
|
|
@ -9,7 +9,7 @@ from django.conf import settings
|
|||
|
||||
from personalni.models import Resitel, Organizator
|
||||
|
||||
from seminar.models.base import SeminarModelBase
|
||||
from various.models import SeminarModelBase
|
||||
from tvorba.models import Rocnik, Problem, aux_generate_filename
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
@ -8,7 +8,7 @@ from unidecode import unidecode # Používám pro získání ID odkazu (ještě
|
|||
|
||||
from polymorphic.models import PolymorphicModel
|
||||
|
||||
from seminar.models import SeminarModelBase
|
||||
from various.models import SeminarModelBase
|
||||
|
||||
from personalni.models import Organizator
|
||||
from odevzdavatko.models import Reseni
|
||||
|
|
|
@ -4,7 +4,7 @@ import datetime
|
|||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
import seminar.models.tvorba
|
||||
import various.models
|
||||
import tvorba.models
|
||||
import taggit.managers
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Migration(migrations.Migration):
|
|||
('datum_vydani', models.DateField(blank=True, help_text='Datum vydání finální verze', null=True, verbose_name='datum vydání')),
|
||||
('verejne_db', models.BooleanField(db_column='verejne', default=False, verbose_name='číslo zveřejněno')),
|
||||
('poznamka', models.TextField(blank=True, help_text='Neveřejná poznámka k číslu (plain text)', verbose_name='neveřejná poznámka')),
|
||||
('pdf', models.FileField(blank=True, help_text='PDF čísla, které si mohou řešitelé stáhnout', null=True, storage=seminar.models.tvorba.OverwriteStorage(), upload_to=tvorba.models.cislo_pdf_filename, verbose_name='pdf')),
|
||||
('pdf', models.FileField(blank=True, help_text='PDF čísla, které si mohou řešitelé stáhnout', null=True, storage=various.models.OverwriteStorage(), upload_to=tvorba.models.cislo_pdf_filename, verbose_name='pdf')),
|
||||
('titulka_nahled', models.ImageField(blank=True, help_text='Obrázek titulní strany, generuje se automaticky', null=True, upload_to=tvorba.models.cislo_png_filename, verbose_name='Obrázek titulní strany')),
|
||||
('rocnik', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='cisla', to='tvorba.rocnik', verbose_name='ročník')),
|
||||
],
|
||||
|
|
|
@ -31,8 +31,7 @@ from polymorphic.models import PolymorphicModel
|
|||
|
||||
from django.core.mail import EmailMessage
|
||||
|
||||
from seminar.models.base import SeminarModelBase
|
||||
from seminar.models.tvorba import OverwriteStorage
|
||||
from various.models import SeminarModelBase, OverwriteStorage
|
||||
from personalni.models import Prijemce, Organizator
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
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
|
||||
|
||||
from tvorba.models import Cislo
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
@reversion.register(ignore_duplicates=True)
|
||||
class Nastaveni(SingletonModel):
|
||||
|
@ -14,10 +15,10 @@ class Nastaveni(SingletonModel):
|
|||
db_table = 'seminar_nastaveni'
|
||||
verbose_name = 'Nastavení semináře'
|
||||
|
||||
# aktualni_rocnik = models.ForeignKey(Rocnik, verbose_name='aktuální ročník',
|
||||
# aktualni_rocnik = models.ForeignKey("tvorba.Rocnik", verbose_name='aktuální ročník',
|
||||
# null=False, on_delete=models.PROTECT)
|
||||
|
||||
aktualni_cislo = models.ForeignKey(Cislo, verbose_name='Aktuální číslo',
|
||||
aktualni_cislo = models.ForeignKey("tvorba.Cislo", verbose_name='Aktuální číslo',
|
||||
null=True, blank=False, on_delete=models.PROTECT,
|
||||
)
|
||||
|
||||
|
@ -37,3 +38,28 @@ class Nastaveni(SingletonModel):
|
|||
|
||||
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, ))
|
||||
|
|
Loading…
Reference in a new issue