示例#1
0
	def _sendNotification(self, user, current_user,email_text,template_code):
		"""
		Send a notification to user from current user based on template
		"""
		template = loader.get_template('mus/emails/attach_development_plan_%s.html' % template_code)
		if template_code=="da":
			subject = "NXT LVL - Udfyld forberedelsesguide"
		elif template_code=="en":
			subject = "NXT LVL - Fill out preparation guide"
		else:
			raise Exception("Unknown template: %s" % template_code)
		employee =user.employee_user.first()
		if employee.plaintext_password=='':
			password = generate_password(8)
			employee.plaintext_password = my_encrypt(password)
			user.set_password(password)
			user.save()
			employee.save()
		else:
			password =my_decrypt(user.employee_user.first().plaintext_password)
		htmlbody = template.render(
				Context({
					'user': user,
					'text' : email_text,
					'sender': current_user,
					'password' : password
				})
			)
		send_mail(
			subject,
			strip_tags(htmlbody),
			settings.DEFAULT_FROM_MAIL,
			("%s <%s>" % (user.get_full_name(),user.email),),
			html_message=htmlbody
		)
示例#2
0
	def send(self):

		emp = Employee.objects.get(user=self.created_by)
		""":type Employee"""
		language_code = emp.language_code

		if language_code == 'da':
			subject = self.template.subject_da
			body = self.template.body_da
		else:
			subject = self.template.subject_en
			body = self.template.body_en

		message = html_message=body.format(
			self.created_by.get_full_name(),
			self.comment.replace('\n','<br />\n')
		)

		send_mail(
			subject,
			strip_tags(message),
			settings.DEFAULT_FROM_MAIL,
			("%s <%s>" % (self.created_by.get_full_name(),self.created_by.email),),
			html_message=message

		)

		self.markSent()
示例#3
0
	def sendCommentNotification(self, type, recipient, peer):
		"""
		Sends an email to the recipient, that a comment has been added by peer.

		:type type: str
		1 for mail to employee, 2 = manager

		:type recipient: User
		:type peer: User

		"""

		rcpt_emp = Employee.objects.get(user=recipient)
		""":type Employee"""

		language_code = rcpt_emp.language_code

		if type == 1:
			tmpl_file = 'mus/emails/action_comment_employee_%s.html' % language_code

			if language_code == 'da':
				subject = "Din medarbejder har en kommentar og venter godkendelse"
			else:
				subject = "Your employee has added a comment and awaits approval"

		else:
			tmpl_file = 'mus/emails/action_comment_manager_%s.html' % language_code

			if language_code == 'da':
				subject = "Din leder har en kommentar og venter godkendelse"
			else:
				subject = "Your manager has added a comment and awaits approval"


		template = loader.get_template(tmpl_file)

		htmlbody = template.render(
			Context({
				'peer': peer,
				'recipient': recipient,
				'comment' : self.text
			})
		)

		send_mail(
			subject,
			strip_tags(htmlbody),
			settings.DEFAULT_FROM_MAIL,
			("%s <%s>" % (recipient.get_full_name(),recipient.email),),
			html_message=htmlbody
		)
示例#4
0
	def send_approval_notification(self):
		if self.created_by==self.employee.user:

			language_code = self.employee.manager.language_code
			template = loader.get_template('mus/emails/approve_employee_action_%s.html' % language_code)
			if language_code == 'da':
				subject = "Din medarbejder har oprettet en indsats og venter godkendelse"
			elif language_code =='en':
				subject = "Your employee has created a contribution and awaits approval"
			else:
				raise PermissionDenied()
			htmlbody = template.render(
					Context({
						'employee_user': self.employee.user,
						'user': self.employee.manager.user
					})
				)
			send_mail(
				subject,
				strip_tags(htmlbody),
				settings.DEFAULT_FROM_MAIL,
				("%s <%s>" % (self.employee.manager.user.get_full_name(),self.employee.manager.user.email),),
				html_message=htmlbody
				)
		else:
			language_code = self.employee.language_code
			template = loader.get_template('mus/emails/approve_manager_action_%s.html' % language_code)
			if language_code == 'da':
				subject = "Din leder har oprettet en indsats og venter godkendelse"
			elif language_code =='en':
				subject = "Your manager has created a contribution and awaits approval"
			else:
				raise PermissionDenied()
			if self.employee.manager:
				manager_user = self.employee.manager.user
			else:
				manager_user = self.created_by
			htmlbody = template.render(
					Context({
						'manager_user': manager_user,
						'user': self.employee.user,
					})
				)
			send_mail(
				subject,
				strip_tags(htmlbody),
				settings.DEFAULT_FROM_MAIL,
				("%s <%s>" % (self.employee.user.get_full_name(),self.employee.user.email),),
				html_message=htmlbody
				)
示例#5
0
	def _sendWelcomeMail(self, user, password):
		"""
		Send welcome mail to user
		"""
		template = loader.get_template('mus/create_user_mail.tpl')
		send_mail(
			settings.WELCOME_MAIL_SUBJECT,
			template.render(
				Context({
					'user': user,
					'password': password,
					'url': self.request.build_absolute_uri('/login/'),
					'sender': self.user
				})
			),
			self.user.email,
			[user.email]
		)
示例#6
0
	def save(self):
		employee = Employee.objects.get(user__email__exact=self.cleaned_data['email'])
		subject = _("NXT LVL: new password")
		password = generate_password(8)
		employee.user.set_password(password)
		employee.user.save()

		template = loader.get_template('mus/emails/reset_password_%s.html' % employee.language_code)
		htmlbody = template.render(
				Context({
					'user': employee.user,
					'access_code': employee.getAccessCode(),
					'newpassword' : password
				})
			)
		send_mail(
			subject,
			strip_tags(htmlbody),
			settings.DEFAULT_FROM_MAIL,
			(employee.user.email,),
			html_message=htmlbody
		)
示例#7
0
	def _sendDoneNotifications(self):
		"""
		Send notifications to employee/manager and receipt to self.user when done
		"""
		language_code=self.getDevelopmentPlan().language_code
		if self.isManagers():
			template = loader.get_template('mus/emails/finished_manager_development_plan_%s.html' % language_code)
			if language_code == 'da':
				subject = "Din leder har udfyldt sin forberedelsesguide"
			elif language_code =='en':
				subject = "Your manager has finished the preparation guide"
			else:
				raise PermissionDenied()
			htmlbody = template.render(
					Context({
						'manager_user': self.user,
						'user': self.getDevelopmentPlan().owner.user
					})
				)
			send_mail(
				subject,
				strip_tags(htmlbody),
				settings.DEFAULT_FROM_MAIL,
				("%s <%s>" % (self.getDevelopmentPlan().owner.user.get_full_name(),self.getDevelopmentPlan().owner.user.email),),
				html_message=htmlbody
			)
			template = loader.get_template('mus/emails/receipt_manager_development_plan_%s.html' % language_code)
			if language_code == 'da':
				subject = "Forberedelsesguide udfyldt for %s" % self.getDevelopmentPlan().owner.user.get_full_name()
			elif language_code =='en':
				subject = "Preparation guide finished for %s" % self.getDevelopmentPlan().owner.user.get_full_name()
			else:
				raise PermissionDenied()
			htmlbody = template.render(
					Context({
						'employee_user': self.getDevelopmentPlan().owner.user,
						'user': self.user,
					})
				)
			send_mail(
				subject,
				strip_tags(htmlbody),
				settings.DEFAULT_FROM_MAIL,
				("%s <%s>" % (self.user.get_full_name(),self.user.email),),
				html_message=htmlbody,
				attachment=[self.getPDFfile()]
			)
		else:
			template = loader.get_template('mus/emails/finished_employee_development_plan_%s.html' % language_code)
			if language_code == 'da':
				subject = "En medarbejder har udfyldt sin forberedelsesguide"
			elif language_code =='en':
				subject = "An employee has finished the preparation guide"
			else:
				raise PermissionDenied()
			htmlbody = template.render(
					Context({
						'employee_user': self.user,
						'user': self.user.employee_user.first().manager.user
					})
				)
			send_mail(
				subject,
				strip_tags(htmlbody),
				settings.DEFAULT_FROM_MAIL,
				("%s <%s>" % (self.user.employee_user.first().manager.user.get_full_name(),self.user.employee_user.first().manager.user.email),),
				html_message=htmlbody
			)
			template = loader.get_template('mus/emails/receipt_employee_development_plan_%s.html' % language_code)
			if language_code == 'da':
				subject = "Din forberedelsesguide er udfyldt"
			elif language_code =='en':
				subject = "Your preparation guide is finished"
			else:
				raise PermissionDenied()
			htmlbody = template.render(
					Context({
						'user': self.user,
					})
				)
			send_mail(
				subject,
				strip_tags(htmlbody),
				settings.DEFAULT_FROM_MAIL,
				("%s <%s>" % (self.user.get_full_name(),self.user.email),),
				html_message=htmlbody,
				attachment=[self.getPDFfile()]
			)