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: