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 = [
|
||||
(None,
|
||||
{'fields':
|
||||
['pdf', 'cas', 'org', 'stran', 'nazev', 'komentar', 'poslat_mail']}),
|
||||
['pdf', 'cas', 'stran', 'nazev', 'orgove', 'komentar', 'poslat_mail']}),
|
||||
# (u'PDF', {'fields': ['pdf']}),
|
||||
]
|
||||
list_display = ['nazev', 'cas', 'stran', 'org']
|
||||
list_display = ['nazev', 'cas', 'stran']
|
||||
list_filter = []
|
||||
search_fields = []
|
||||
filter_horizontal = ['orgove']
|
||||
|
||||
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)
|
||||
return os.path.join(settings.KOREKTURY_PDF_DIR, fname)
|
||||
|
||||
|
||||
#@reversion.register(ignore_duplicates=True)
|
||||
class KorekturovanePDF(models.Model):
|
||||
class Meta:
|
||||
|
@ -60,9 +59,9 @@ class KorekturovanePDF(models.Model):
|
|||
|
||||
pdf = models.FileField(u'PDF', upload_to = generate_filename)
|
||||
|
||||
org = models.ForeignKey(Organizator, blank=True,
|
||||
help_text='Zodpovědný organizátor za obsah',
|
||||
null=True, default=None, on_delete=models.SET_NULL)
|
||||
orgove = models.ManyToManyField(Organizator, blank=True,
|
||||
help_text='Zodpovědní organizátoři za obsah (chodí jim maily o nových korekturách)',
|
||||
default=None)
|
||||
|
||||
stran = models.IntegerField(u'počet stran', help_text='Počet stran PDF',
|
||||
default=0)
|
||||
|
|
|
@ -188,9 +188,9 @@ class KorekturyView(generic.TemplateView):
|
|||
if email_komentujiciho:
|
||||
emails.add(email_komentujiciho)
|
||||
|
||||
# zodpovedny org
|
||||
if oprava.pdf.org:
|
||||
email_zobpovedny = oprava.pdf.org.osoba.email
|
||||
# zodpovedni orgove
|
||||
for org in oprava.pdf.orgove.all():
|
||||
email_zobpovedny = org.osoba.email
|
||||
if email_zobpovedny:
|
||||
emails.add(email_zobpovedny)
|
||||
|
||||
|
|
Loading…
Reference in a new issue