|
@ -4,6 +4,7 @@ from django.views import generic |
|
|
from django.utils.translation import ugettext as _ |
|
|
from django.utils.translation import ugettext as _ |
|
|
from django.conf import settings |
|
|
from django.conf import settings |
|
|
from django.http import HttpResponseForbidden |
|
|
from django.http import HttpResponseForbidden |
|
|
|
|
|
from django.core.mail import send_mail |
|
|
|
|
|
|
|
|
from .models import Oprava,Komentar,KorekturovanePDF, Organizator |
|
|
from .models import Oprava,Komentar,KorekturovanePDF, Organizator |
|
|
from .forms import OpravaForm |
|
|
from .forms import OpravaForm |
|
@ -83,6 +84,7 @@ class KorekturyView(generic.TemplateView): |
|
|
text = q.get('txt') |
|
|
text = q.get('txt') |
|
|
kom = Komentar(oprava=op,autor=autor,text=text) |
|
|
kom = Komentar(oprava=op,autor=autor,text=text) |
|
|
kom.save() |
|
|
kom.save() |
|
|
|
|
|
self.send_email_notification_komentar(op, autor, text) |
|
|
elif (action == u'update-comment'): |
|
|
elif (action == u'update-comment'): |
|
|
id = int(q.get('id')) |
|
|
id = int(q.get('id')) |
|
|
kom = Komentar.objects.get(id=id) |
|
|
kom = Komentar.objects.get(id=id) |
|
@ -116,6 +118,29 @@ class KorekturyView(generic.TemplateView): |
|
|
context['autor'] = autor |
|
|
context['autor'] = autor |
|
|
return render(request, 'korektury/opraf.html',context) |
|
|
return render(request, 'korektury/opraf.html',context) |
|
|
|
|
|
|
|
|
|
|
|
def send_email_notification_komentar(self, oprava, autor, text): |
|
|
|
|
|
''' Rozesle e-mail pri pridani komentare, |
|
|
|
|
|
ktery obsahuje text komentare. |
|
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
# parametry e-mailu |
|
|
|
|
|
from_email = 'korekturovatko@mam.mff.cuni.cz' |
|
|
|
|
|
subject = u'Nová korektura od {}'.format(autor) |
|
|
|
|
|
text = u"Text komentáře:\n\n{}\n\n=== Konec textu komentáře ===\n\ |
|
|
|
|
|
\nVaše korekturovátko\n".format(text) |
|
|
|
|
|
|
|
|
|
|
|
# Prijemci e-mailu |
|
|
|
|
|
emails = set() |
|
|
|
|
|
email = oprava.autor.user.email |
|
|
|
|
|
if email: |
|
|
|
|
|
emails.add(email) |
|
|
|
|
|
for komentar in oprava.komentar_set.all(): |
|
|
|
|
|
email = komentar.autor.user.email |
|
|
|
|
|
if email: |
|
|
|
|
|
emails.add(email) |
|
|
|
|
|
|
|
|
|
|
|
send_mail(subject, text, from_email, list(emails)) |
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
def get_context_data(self, **kwargs): |
|
|
context = super(KorekturyView,self).get_context_data(**kwargs) |
|
|
context = super(KorekturyView,self).get_context_data(**kwargs) |
|
|
pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf']) |
|
|
pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf']) |
|
|