From 0dde05f1027131337b61cfa0d6d07cb47f373841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Thu, 12 Dec 2024 11:50:17 +0100 Subject: [PATCH] =?UTF-8?q?Odstran=C4=9Bn=C3=AD=20textu=20a=20autora=20z?= =?UTF-8?q?=20opravy=20(p=C5=99esun=20do=20prvn=C3=ADho=20koment=C3=A1?= =?UTF-8?q?=C5=99e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._remove_oprava_autor_remove_oprava_text.py | 45 +++++++++++++++++++ korektury/models.py | 14 ------ korektury/templates/korektury/opraf.html | 1 - korektury/utils.py | 6 +-- korektury/views.py | 18 +++----- 5 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 korektury/migrations/0025_remove_oprava_autor_remove_oprava_text.py diff --git a/korektury/migrations/0025_remove_oprava_autor_remove_oprava_text.py b/korektury/migrations/0025_remove_oprava_autor_remove_oprava_text.py new file mode 100644 index 00000000..82f23ba2 --- /dev/null +++ b/korektury/migrations/0025_remove_oprava_autor_remove_oprava_text.py @@ -0,0 +1,45 @@ +# Generated by Django 4.2.16 on 2024-12-12 10:25 + +from django.db import migrations + +import datetime +from django.utils import timezone + + +def oprava2komentar(apps, schema_editor): + Oprava = apps.get_model('korektury', 'Oprava') + Komentar = apps.get_model('korektury', 'Komentar') + + for o in Oprava.objects.all(): + Komentar.objects.create(oprava=o, text=o.text, autor=o.autor, cas=timezone.make_aware(datetime.datetime.fromtimestamp(0))) + +def komentar2oprava(apps, schema_editor): + Oprava = apps.get_model('korektury', 'Oprava') + Komentar = apps.get_model('korektury', 'Komentar') + + for o in Oprava.objects.all(): + k = Komentar.objects.filter(oprava=o).first() + o.text = k.text + o.autor = k.autor + o.save() + k.delete() + + + +class Migration(migrations.Migration): + + dependencies = [ + ('korektury', '0024_vic_orgu_k_pdf'), + ] + + operations = [ + migrations.RunPython(oprava2komentar, komentar2oprava), + migrations.RemoveField( + model_name='oprava', + name='autor', + ), + migrations.RemoveField( + model_name='oprava', + name='text', + ), + ] diff --git a/korektury/models.py b/korektury/models.py index 5df14d6f..2f2480c1 100644 --- a/korektury/models.py +++ b/korektury/models.py @@ -157,20 +157,6 @@ class Oprava(models.Model): status = models.CharField(u'stav opravy',max_length=16, choices=STATUS.choices, blank=False, default = STATUS.K_OPRAVE) - autor = models.ForeignKey(Organizator, blank = True, - help_text='Autor opravy', - null = True, on_delete=models.SET_NULL) - - text = models.TextField(u'text opravy',blank = True, help_text='Text opravy') - -# def __init__(self,dictionary): -# for k,v in dictionary.items(): -# setattr(self,k,v) - - def __str__(self): - return '{} od {}: {}'.format(self.status,self.autor,self.text) - - @reversion.register(ignore_duplicates=True) class Komentar(models.Model): diff --git a/korektury/templates/korektury/opraf.html b/korektury/templates/korektury/opraf.html index 783c6910..176e6fe6 100644 --- a/korektury/templates/korektury/opraf.html +++ b/korektury/templates/korektury/opraf.html @@ -145,7 +145,6 @@
{% csrf_token %} - diff --git a/korektury/utils.py b/korektury/utils.py index e7a3bc62..e25947af 100644 --- a/korektury/utils.py +++ b/korektury/utils.py @@ -17,7 +17,7 @@ def send_email_notification_komentar(oprava: Oprava, autor: Organizator, request odkaz = f"{odkaz}#op{oprava.id}-pointer" from_email = 'korekturovatko@mam.mff.cuni.cz' subject = 'Nová korektura od {} v {}'.format(autor, oprava.pdf.nazev) - texty = [(oprava.autor.osoba.plne_jmeno(),oprava.text)] + texty = [] for kom in Komentar.objects.filter(oprava=oprava): texty.append((kom.autor.osoba.plne_jmeno(),kom.text)) optext = "\n\n\n".join([": ".join(t) for t in texty]) @@ -27,10 +27,6 @@ def send_email_notification_komentar(oprava: Oprava, autor: Organizator, request # Prijemci e-mailu emails = set() - # e-mail autora korektury - email = oprava.autor.osoba.email - if email: - emails.add(email) # nalezeni e-mailu na autory komentaru for komentar in oprava.komentar_set.all(): diff --git a/korektury/views.py b/korektury/views.py index 9c52b20e..93cffb7e 100644 --- a/korektury/views.py +++ b/korektury/views.py @@ -79,21 +79,17 @@ class KorekturyView(generic.TemplateView): y = int(q.get('y')) text = q.get('txt') strana = int(q.get('img-id')[4:]) - - op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana, pdf=self.pdf) + op = Oprava(x=x,y=y, strana=strana, pdf=self.pdf) op.save() + kom = Komentar(oprava=op,autor=autor,text=text) + kom.save() send_email_notification_komentar(op, autor, request) elif (action == 'del'): id = int(q.get('id')) op = Oprava.objects.get(id=id) + for k in Komentar.objects.filter(oprava=op): + k.delete() op.delete() - elif (action == 'update'): - id = int(q.get('id')) - op = Oprava.objects.get(id=id) - text = q.get('txt') - op.autor = autor - op.text = text - op.save() elif action in Oprava.STATUS.values: id = int(q.get('id')) op = Oprava.objects.get(id=id) @@ -136,10 +132,6 @@ class KorekturyView(generic.TemplateView): opravy = Oprava.objects.filter(pdf=self.pdf_id) zasluhy = {} for o in opravy: - if o.autor in zasluhy: - zasluhy[o.autor]+=1 - else: - zasluhy[o.autor]=1 o.komentare = o.komentar_set.all() for k in o.komentare: if k.autor in zasluhy: