def send_flag_email(self, form): # TODO: Make it a Celery task. from django.template import Context, loader from django.conf import settings context = Context({ 'user': self.request.user, 'user_url': self.request.build_absolute_uri( self.request.user.get_absolute_url()), 'package': self.object, 'package_url': self.request.build_absolute_uri(self.object.get_absolute_url()), 'reason': form.cleaned_data['reason'], }) subject_template = 'packages/flag_email/subject.txt' body_text_template = 'packages/flag_email/body.txt' subject = loader.render_to_string(subject_template, context) subject = ''.join(subject.splitlines()) body_text = loader.render_to_string(body_text_template, context) #sending email is delegated to celery send_email.delay( subject=subject, message=body_text, from_email=settings.DEFAULT_FROM_EMAIL, recipient_list=settings.FLAG_EMAIL_ALERTS or [], ) return True
def send_flag_email(self, form): # TODO: Make it a Celery task. from django.template import Context, loader from django.conf import settings context = Context({ 'user': self.request.user, 'user_url': self.request.build_absolute_uri( self.request.user.get_absolute_url()), 'package': self.object, 'package_url': self.request.build_absolute_uri( self.object.get_absolute_url()), 'reason': form.cleaned_data['reason'], }) subject_template = 'packages/flag_email/subject.txt' body_text_template = 'packages/flag_email/body.txt' subject = loader.render_to_string(subject_template, context) subject = ''.join(subject.splitlines()) body_text = loader.render_to_string(body_text_template, context) #sending email is delegated to celery send_email.delay( subject=subject, message=body_text, from_email=settings.DEFAULT_FROM_EMAIL, recipient_list=settings.FLAG_EMAIL_ALERTS or [], ) return True
def notify(self, to, status): """Sends email notification to users or admins. args: to -> takes to possible values "users" or "admins" status -> takes the status that needs to be notified. eg. notify('admins', 'Needs_Review') #send email alerting admins that a project needs review. """ # import pdb; pdb.set_trace() subject, body = self._get_email_content(status) to = self._get_to_addresses(to) send_email.delay(subject, body, settings.DEFAULT_FROM_EMAIL, to)