def put(self, request, format="json"): if not request.user.is_authenticated() or not request.user.is_staff: raise PermissionDenied() email_data = request.data fmt = email_data.pop('format') body = email_data.pop('body') if fmt == 'mixed': email_data['text_body'] = body email_data['html_body'] = markdown.markdown(body) elif fmt == 'text': email_data['text_body'] = body email_data['html_body'] = None elif fmt == 'html': email_data['text_body'] = '' email_data['html_body'] = body debug = False if debug: import pprint, time print pprint.pprint(email_data) time.sleep(1) if '*****@*****.**' in email_data['bcc_list']: return HttpResponse("Invalid email address", content_type="text/plain", status=403) else: import wsrc.utils.email_utils as email_utils email_utils.send_email(**email_data) return HttpResponse(status=204)
def notify(template_name, kwargs, subject, to_list, cc_list, from_address, attachments=None): template_obj = EmailContent.objects.get(name=template_name) email_template = Template(template_obj.markup) context = Context(kwargs) context["content_type"] = "text/html" html_body = markdown.markdown(email_template.render(context)) context["content_type"] = "text/plain" text_body = email_template.render(context) email_utils.send_email(subject, text_body, html_body, from_address, to_list, cc_list=cc_list, extra_attachments=attachments)
def put(self, request, format="json"): competition_id = request.data.pop('competition_id') template_name = request.data.pop('template_name') subject = request.data.pop('subject') from_address = request.data.pop('from_address') competition = Competition.objects.get(pk=competition_id) to_list = [entrant.player1.user.email for entrant in competition.entrant_set.all()] email_template = EmailContent.objects.get(name=template_name) email_template = Template(email_template.markup) context = Context({"competition": competition}) context["content_type"] = "text/html" html_body = markdown.markdown(email_template.render(context)) context["content_type"] = "text/plain" text_body = email_template.render(context) email_utils.send_email(subject, text_body, html_body, from_address, to_list) return HttpResponse(status=204)