Odstranění textu a autora z opravy (přesun do prvního komentáře)
This commit is contained in:
parent
3528a44d3c
commit
0dde05f102
5 changed files with 51 additions and 33 deletions
|
@ -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',
|
||||
),
|
||||
]
|
|
@ -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):
|
||||
|
|
|
@ -145,7 +145,6 @@
|
|||
<!-- Existujici korektura !-->
|
||||
<form action='' onsubmit='save_scroll(this)' method='POST'>
|
||||
{% csrf_token %}
|
||||
<input type='hidden' name="au" value="{{o.autor}}"/>
|
||||
<input type='hidden' name='id' value='{{o.id}}'>
|
||||
<input type='hidden' name='scroll'>
|
||||
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue