From d895cd0636b05d83161a0e256771bdba21ac610b Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 12 Jun 2024 02:02:37 +0200 Subject: [PATCH 1/3] =?UTF-8?q?V=C3=ADc=20org=C5=AF=20k=20jednomu=20PDF=20?= =?UTF-8?q?v=20korekturov=C3=A1tku?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/admin.py | 5 ++- korektury/migrations/0024_vic_orgu_k_pdf.py | 41 +++++++++++++++++++++ korektury/models.py | 7 ++-- korektury/views.py | 6 +-- 4 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 korektury/migrations/0024_vic_orgu_k_pdf.py diff --git a/korektury/admin.py b/korektury/admin.py index 5f92c542..a116e260 100644 --- a/korektury/admin.py +++ b/korektury/admin.py @@ -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): """ diff --git a/korektury/migrations/0024_vic_orgu_k_pdf.py b/korektury/migrations/0024_vic_orgu_k_pdf.py new file mode 100644 index 00000000..b0776303 --- /dev/null +++ b/korektury/migrations/0024_vic_orgu_k_pdf.py @@ -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', + ), + ] diff --git a/korektury/models.py b/korektury/models.py index ca1bb877..9f2f82f7 100644 --- a/korektury/models.py +++ b/korektury/models.py @@ -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) diff --git a/korektury/views.py b/korektury/views.py index 1bdfaa92..4408254a 100644 --- a/korektury/views.py +++ b/korektury/views.py @@ -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) From 8a5659420d0ac959fe244210847c26218e215bbc Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 12 Jun 2024 02:25:01 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Na=20v=C3=BDb=C4=9Br=20org=C5=AF=20pro=20PD?= =?UTF-8?q?F=20chceme=20autocomplete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/korektury/admin.py b/korektury/admin.py index a116e260..459932a3 100644 --- a/korektury/admin.py +++ b/korektury/admin.py @@ -42,7 +42,7 @@ class KorekturovanePDFAdmin(VersionAdmin): list_display = ['nazev', 'cas', 'stran'] list_filter = [] search_fields = [] - filter_horizontal = ['orgove'] + autocomplete_fields = ['orgove'] def save_model(self, request, obj, form, change): """ From 2304a8282c4d69881146d3553b790848c3e61a1b Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sat, 15 Jun 2024 22:50:20 +0200 Subject: [PATCH 3/3] =?UTF-8?q?PDF=20nemus=C3=AD=20m=C3=ADt=20zodpov=C4=9B?= =?UTF-8?q?dn=C3=A9ho=20orga!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/migrations/0024_vic_orgu_k_pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/korektury/migrations/0024_vic_orgu_k_pdf.py b/korektury/migrations/0024_vic_orgu_k_pdf.py index b0776303..96af9d93 100644 --- a/korektury/migrations/0024_vic_orgu_k_pdf.py +++ b/korektury/migrations/0024_vic_orgu_k_pdf.py @@ -5,7 +5,7 @@ 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) + if pdf.org is not None: pdf.orgove.add(pdf.org) pdf.save() # ig? def vyber_orga(apps, schema_editor):