Víc orgů k jednomu PDF v korekturovátku
This commit is contained in:
parent
c0958d79db
commit
d895cd0636
4 changed files with 50 additions and 9 deletions
|
@ -36,12 +36,13 @@ class KorekturovanePDFAdmin(VersionAdmin):
|
||||||
fieldsets = [
|
fieldsets = [
|
||||||
(None,
|
(None,
|
||||||
{'fields':
|
{'fields':
|
||||||
['pdf', 'cas', 'org', 'stran', 'nazev', 'komentar', 'poslat_mail']}),
|
['pdf', 'cas', 'stran', 'nazev', 'orgove', 'komentar', 'poslat_mail']}),
|
||||||
# (u'PDF', {'fields': ['pdf']}),
|
# (u'PDF', {'fields': ['pdf']}),
|
||||||
]
|
]
|
||||||
list_display = ['nazev', 'cas', 'stran', 'org']
|
list_display = ['nazev', 'cas', 'stran']
|
||||||
list_filter = []
|
list_filter = []
|
||||||
search_fields = []
|
search_fields = []
|
||||||
|
filter_horizontal = ['orgove']
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
def save_model(self, request, obj, form, change):
|
||||||
"""
|
"""
|
||||||
|
|
41
korektury/migrations/0024_vic_orgu_k_pdf.py
Normal file
41
korektury/migrations/0024_vic_orgu_k_pdf.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# Generated by Django 4.2.13 on 2024-06-11 23:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
def pridej_orgy(apps, schema_editor):
|
||||||
|
PDF = apps.get_model('korektury', 'KorekturovanePDF')
|
||||||
|
for pdf in PDF.objects.all(): # Tohle by asi mělo jít udělat pomocí update, ale moc práce a rychlé hledání taky nepomohlo.
|
||||||
|
pdf.orgove.add(pdf.org)
|
||||||
|
pdf.save() # ig?
|
||||||
|
|
||||||
|
def vyber_orga(apps, schema_editor):
|
||||||
|
PDF = apps.get_model('korektury', 'KorekturovanePDF')
|
||||||
|
for pdf in PDF.objects.all():
|
||||||
|
orgove = pdf.orgove.all()
|
||||||
|
if len(orgove) > 1:
|
||||||
|
raise migrations.exceptions.IrreversibleError(f'PDF {pdf.id} má víc než jednoho zodpovědného orga, nejde odmigrovat na verzi, která umí jen jednoho.')
|
||||||
|
if len(orgove) == 0:
|
||||||
|
pdf.org = None
|
||||||
|
else:
|
||||||
|
pdf.org = orgove[0]
|
||||||
|
pdf.save()
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('personalni', '0011_osloveni_vsechny_choices'),
|
||||||
|
('korektury', '0023_personalni_post_migrate'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='korekturovanepdf',
|
||||||
|
name='orgove',
|
||||||
|
field=models.ManyToManyField(blank=True, default=None, help_text='Zodpovědní organizátoři za obsah (chodí jim maily o nových korekturách)', to='personalni.organizator'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(pridej_orgy, vyber_orga),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='korekturovanepdf',
|
||||||
|
name='org',
|
||||||
|
),
|
||||||
|
]
|
|
@ -40,7 +40,6 @@ def generate_filename(self, filename):
|
||||||
clean)
|
clean)
|
||||||
return os.path.join(settings.KOREKTURY_PDF_DIR, fname)
|
return os.path.join(settings.KOREKTURY_PDF_DIR, fname)
|
||||||
|
|
||||||
|
|
||||||
#@reversion.register(ignore_duplicates=True)
|
#@reversion.register(ignore_duplicates=True)
|
||||||
class KorekturovanePDF(models.Model):
|
class KorekturovanePDF(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -60,9 +59,9 @@ class KorekturovanePDF(models.Model):
|
||||||
|
|
||||||
pdf = models.FileField(u'PDF', upload_to = generate_filename)
|
pdf = models.FileField(u'PDF', upload_to = generate_filename)
|
||||||
|
|
||||||
org = models.ForeignKey(Organizator, blank=True,
|
orgove = models.ManyToManyField(Organizator, blank=True,
|
||||||
help_text='Zodpovědný organizátor za obsah',
|
help_text='Zodpovědní organizátoři za obsah (chodí jim maily o nových korekturách)',
|
||||||
null=True, default=None, on_delete=models.SET_NULL)
|
default=None)
|
||||||
|
|
||||||
stran = models.IntegerField(u'počet stran', help_text='Počet stran PDF',
|
stran = models.IntegerField(u'počet stran', help_text='Počet stran PDF',
|
||||||
default=0)
|
default=0)
|
||||||
|
|
|
@ -188,9 +188,9 @@ class KorekturyView(generic.TemplateView):
|
||||||
if email_komentujiciho:
|
if email_komentujiciho:
|
||||||
emails.add(email_komentujiciho)
|
emails.add(email_komentujiciho)
|
||||||
|
|
||||||
# zodpovedny org
|
# zodpovedni orgove
|
||||||
if oprava.pdf.org:
|
for org in oprava.pdf.orgove.all():
|
||||||
email_zobpovedny = oprava.pdf.org.osoba.email
|
email_zobpovedny = org.osoba.email
|
||||||
if email_zobpovedny:
|
if email_zobpovedny:
|
||||||
emails.add(email_zobpovedny)
|
emails.add(email_zobpovedny)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue