korektury | posilani emailů na komentare
This commit is contained in:
		
							parent
							
								
									46cd63f621
								
							
						
					
					
						commit
						f0e7fac79f
					
				
					 1 changed files with 25 additions and 0 deletions
				
			
		|  | @ -4,6 +4,7 @@ from django.views import generic | |||
| from django.utils.translation import ugettext as _ | ||||
| from django.conf import settings | ||||
| from django.http import HttpResponseForbidden | ||||
| from django.core.mail import send_mail | ||||
| 
 | ||||
| from .models import Oprava,Komentar,KorekturovanePDF, Organizator | ||||
| from .forms import OpravaForm | ||||
|  | @ -83,6 +84,7 @@ class KorekturyView(generic.TemplateView): | |||
|             text = q.get('txt') | ||||
|             kom = Komentar(oprava=op,autor=autor,text=text) | ||||
|             kom.save() | ||||
|             self.send_email_notification_komentar(op, autor, text) | ||||
|         elif (action == u'update-comment'): | ||||
|             id = int(q.get('id')) | ||||
|             kom = Komentar.objects.get(id=id) | ||||
|  | @ -116,6 +118,29 @@ class KorekturyView(generic.TemplateView): | |||
|         context['autor'] = autor | ||||
|         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): | ||||
|         context = super(KorekturyView,self).get_context_data(**kwargs) | ||||
|         pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf']) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Bc. Petr Pecha
						Bc. Petr Pecha