Rozesílání zveřejněného čísla
This commit is contained in:
		
							parent
							
								
									f5871457c9
								
							
						
					
					
						commit
						5aaa2760a9
					
				
					 4 changed files with 39 additions and 3 deletions
				
			
		|  | @ -162,7 +162,7 @@ class KorekturyView(generic.TemplateView): | ||||||
| 		if email: | 		if email: | ||||||
| 			emails.discard(email) | 			emails.discard(email) | ||||||
| 
 | 
 | ||||||
| 		if not settings.SEND_EMAIL_NOTIFICATIONS: | 		if not settings.POSLI_MAILOVOU_NOTIFIKACI: | ||||||
| 			print("Poslal bych upozornění na tyto adresy: ", " ".join(emails)) | 			print("Poslal bych upozornění na tyto adresy: ", " ".join(emails)) | ||||||
| 			return | 			return | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -279,4 +279,4 @@ CISLO_IMG_DIR = os.path.join('cislo', 'img') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # E-MAIL NOTIFICATIONS | # E-MAIL NOTIFICATIONS | ||||||
| SEND_EMAIL_NOTIFICATIONS = False | POSLI_MAILOVOU_NOTIFIKACI = False | ||||||
|  |  | ||||||
|  | @ -66,4 +66,4 @@ LOGGING['handlers']['registration_error_log']['filename'] = '/home/mam-web/logs/ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # E-MAIL NOTIFICATIONS | # E-MAIL NOTIFICATIONS | ||||||
| SEND_EMAIL_NOTIFICATIONS = True | POSLI_MAILOVOU_NOTIFIKACI = True | ||||||
|  |  | ||||||
|  | @ -32,6 +32,8 @@ from seminar.treelib import safe_pred | ||||||
| 
 | 
 | ||||||
| from polymorphic.models import PolymorphicModel | from polymorphic.models import PolymorphicModel | ||||||
| 
 | 
 | ||||||
|  | from django.core.mail import EmailMessage | ||||||
|  | from seminar.utils import aktivniResitele | ||||||
| 
 | 
 | ||||||
| class SeminarModelBase(models.Model): | class SeminarModelBase(models.Model): | ||||||
| 
 | 
 | ||||||
|  | @ -539,9 +541,43 @@ class Cislo(SeminarModelBase): | ||||||
| 			return None | 			return None | ||||||
| 		return c | 		return c | ||||||
| 
 | 
 | ||||||
|  | 	def __init__(self, *args, **kwargs): | ||||||
|  | 		super().__init__(*args, **kwargs) | ||||||
|  | 		self.__original_verejne = self.verejne_db | ||||||
|  | 
 | ||||||
|  | 	def posli_cislo_mailem(self): | ||||||
|  | 		# parametry e-mailu | ||||||
|  | 		odkaz = self.get_absolute_url() | ||||||
|  | 
 | ||||||
|  | 		poslat_z_mailu = 'zadani@mam.mff.cuni.cz' | ||||||
|  | 		predmet = 'Vyšlo číslo {}'.format(self.kod()) | ||||||
|  | 		text_mailu = 'Ahoj,\n' \ | ||||||
|  | 			   'na adrese {} najdete nejnovější číslo.\n' \ | ||||||
|  | 			   'Vaše M&M\n'.format(odkaz) | ||||||
|  | 
 | ||||||
|  | 		# Prijemci e-mailu | ||||||
|  | 		emaily = map(lambda r: r.osoba.email, aktivniResitele(self 	)) | ||||||
|  | 
 | ||||||
|  | 		if not settings.POSLI_MAILOVOU_NOTIFIKACI: | ||||||
|  | 			print("Poslal bych upozornění na tyto adresy: ", " ".join(emaily)) | ||||||
|  | 			return | ||||||
|  | 
 | ||||||
|  | 		email = EmailMessage( | ||||||
|  | 			subject=predmet, | ||||||
|  | 			body=text_mailu, | ||||||
|  | 			from_email=poslat_z_mailu, | ||||||
|  | 			bcc=list(emaily) | ||||||
|  | 			#bcc = příjemci skryté kopie | ||||||
|  | 		) | ||||||
|  | 
 | ||||||
|  | 		email.send() | ||||||
|  | 
 | ||||||
| 	def save(self, *args, **kwargs): | 	def save(self, *args, **kwargs): | ||||||
| 		super().save(*args, **kwargs) | 		super().save(*args, **kwargs) | ||||||
| 		self.vygeneruj_nahled() | 		self.vygeneruj_nahled() | ||||||
|  | 		# Při zveřejnění pošle mail | ||||||
|  | 		if self.verejne_db and not self.__original_verejne: | ||||||
|  | 			self.posli_cislo_mailem() | ||||||
| 		# *Node.save() aktualizuje název *Nodu. | 		# *Node.save() aktualizuje název *Nodu. | ||||||
| 		try: | 		try: | ||||||
| 			self.cislonode.save() | 			self.cislonode.save() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Jonas Havelka
						Jonas Havelka