Browse Source

Odstranění textu a autora z opravy (přesun do prvního komentáře)

korekturovatko
Jonas Havelka 2 weeks ago
parent
commit
0dde05f102
  1. 45
      korektury/migrations/0025_remove_oprava_autor_remove_oprava_text.py
  2. 14
      korektury/models.py
  3. 1
      korektury/templates/korektury/opraf.html
  4. 6
      korektury/utils.py
  5. 18
      korektury/views.py

45
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',
),
]

14
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) 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) @reversion.register(ignore_duplicates=True)
class Komentar(models.Model): class Komentar(models.Model):

1
korektury/templates/korektury/opraf.html

@ -145,7 +145,6 @@
<!-- Existujici korektura !--> <!-- Existujici korektura !-->
<form action='' onsubmit='save_scroll(this)' method='POST'> <form action='' onsubmit='save_scroll(this)' method='POST'>
{% csrf_token %} {% csrf_token %}
<input type='hidden' name="au" value="{{o.autor}}"/>
<input type='hidden' name='id' value='{{o.id}}'> <input type='hidden' name='id' value='{{o.id}}'>
<input type='hidden' name='scroll'> <input type='hidden' name='scroll'>

6
korektury/utils.py

@ -17,7 +17,7 @@ def send_email_notification_komentar(oprava: Oprava, autor: Organizator, request
odkaz = f"{odkaz}#op{oprava.id}-pointer" odkaz = f"{odkaz}#op{oprava.id}-pointer"
from_email = 'korekturovatko@mam.mff.cuni.cz' from_email = 'korekturovatko@mam.mff.cuni.cz'
subject = 'Nová korektura od {} v {}'.format(autor, oprava.pdf.nazev) 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): for kom in Komentar.objects.filter(oprava=oprava):
texty.append((kom.autor.osoba.plne_jmeno(),kom.text)) texty.append((kom.autor.osoba.plne_jmeno(),kom.text))
optext = "\n\n\n".join([": ".join(t) for t in texty]) 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 # Prijemci e-mailu
emails = set() emails = set()
# e-mail autora korektury
email = oprava.autor.osoba.email
if email:
emails.add(email)
# nalezeni e-mailu na autory komentaru # nalezeni e-mailu na autory komentaru
for komentar in oprava.komentar_set.all(): for komentar in oprava.komentar_set.all():

18
korektury/views.py

@ -79,21 +79,17 @@ class KorekturyView(generic.TemplateView):
y = int(q.get('y')) y = int(q.get('y'))
text = q.get('txt') text = q.get('txt')
strana = int(q.get('img-id')[4:]) strana = int(q.get('img-id')[4:])
op = Oprava(x=x,y=y, strana=strana, pdf=self.pdf)
op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana, pdf=self.pdf)
op.save() op.save()
kom = Komentar(oprava=op,autor=autor,text=text)
kom.save()
send_email_notification_komentar(op, autor, request) send_email_notification_komentar(op, autor, request)
elif (action == 'del'): elif (action == 'del'):
id = int(q.get('id')) id = int(q.get('id'))
op = Oprava.objects.get(id=id) op = Oprava.objects.get(id=id)
for k in Komentar.objects.filter(oprava=op):
k.delete()
op.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: elif action in Oprava.STATUS.values:
id = int(q.get('id')) id = int(q.get('id'))
op = Oprava.objects.get(id=id) op = Oprava.objects.get(id=id)
@ -136,10 +132,6 @@ class KorekturyView(generic.TemplateView):
opravy = Oprava.objects.filter(pdf=self.pdf_id) opravy = Oprava.objects.filter(pdf=self.pdf_id)
zasluhy = {} zasluhy = {}
for o in opravy: for o in opravy:
if o.autor in zasluhy:
zasluhy[o.autor]+=1
else:
zasluhy[o.autor]=1
o.komentare = o.komentar_set.all() o.komentare = o.komentar_set.all()
for k in o.komentare: for k in o.komentare:
if k.autor in zasluhy: if k.autor in zasluhy:

Loading…
Cancel
Save