def form_valid(self, form): subject = "Mediathread Contact Us Request" form_data = form.cleaned_data tmpl = loader.get_template('main/contact_description.txt') form_data['description'] = smart_text(tmpl.render(form_data)) # POST to the task assignment destination task_url = getattr(settings, 'TASK_ASSIGNMENT_DESTINATION', None) if task_url is not None: response = requests.post(task_url, data=form_data) if not response.status_code == 200: # send to server email instead send_mail(subject, form_data['description'], settings.SERVER_EMAIL, (settings.SERVER_EMAIL,)) # POST to the support email support_email = getattr(settings, 'SUPPORT_DESTINATION', None) if support_email is None: send_template_email( subject, 'main/contact_email_response.txt', form_data, form_data['email']) else: recipients = (support_email,) send_mail(subject, form_data['description'], settings.SERVER_EMAIL, recipients) return super(ContactUsView, self).form_valid(form)
def form_valid(self, form): subject = "Mediathread Contact Us Request" form_data = form.cleaned_data tmpl = loader.get_template('main/contact_description.txt') form_data['description'] = smart_text(tmpl.render(form_data)) # POST to the task assignment destination task_url = getattr(settings, 'TASK_ASSIGNMENT_DESTINATION', None) if task_url is not None: response = requests.post(task_url, data=form_data) if not response.status_code == 200: # send to server email instead send_mail(subject, form_data['description'], settings.SERVER_EMAIL, (settings.SERVER_EMAIL, )) # POST to the support email support_email = getattr(settings, 'SUPPORT_DESTINATION', None) if support_email is None: send_template_email(subject, 'main/contact_email_response.txt', form_data, form_data['email']) else: recipients = (support_email, ) send_mail(subject, form_data['description'], settings.SERVER_EMAIL, recipients) return super(ContactUsView, self).form_valid(form)
def notify_staff(self, course): data = { 'course': course, 'domain': self.request.POST.get('domain'), 'user': self.request.user } send_template_email('Mediathread Course Connected', 'main/notify_lti_course_connect.txt', data, settings.SERVER_EMAIL)
def test_send_template_email(self): with self.settings(SERVER_EMAIL='*****@*****.**'): send_template_email('foo', 'main/contact_email_response.txt', {'name': 'bar'}, '*****@*****.**') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, 'foo') self.assertEquals(mail.outbox[0].from_email, '*****@*****.**') self.assertTrue(mail.outbox[0].to, ['*****@*****.**'])
def notify_staff(self, course): data = { 'course': course, 'domain': self.request.POST.get('domain'), 'user': self.request.user } send_template_email( 'Mediathread Course Connected', 'main/notify_lti_course_connect.txt', data, settings.SERVER_EMAIL)
def send_email(self, course, author, item): data = { 'course': course, 'domain': get_current_site(self.request).domain, # @todo FIX 'item': item } email_address = (author.email or '{}@columbia.edu'.format(author.username)) send_template_email('Mediathread submission now available', 'main/mediathread_submission.txt', data, email_address)
def post(self, request): unis = request.POST.get('unis', None) url = reverse('course-roster', args=[request.course.pk]) if unis is None: msg = 'Please enter a comma-separated list of UNIs' messages.add_message(request, messages.ERROR, msg) return HttpResponseRedirect(url) subj = u"Mediathread: {}".format(self.request.course.title) ctx = { 'course': self.request.course, 'domain': get_current_site(self.request).domain } for uni in unis_list(unis): uni = uni.lower().strip() if not self.validate_uni(uni): msg = (u'{} is not a valid UNI. To add a student without ' u'a UNI, click the "Invite Non-Columbia Affiliate" ' u'button below') msg = msg.format(uni) messages.add_message(request, messages.ERROR, msg) continue user = self.get_or_create_user(uni) display_name = user_display_name(user) if self.request.course.is_true_member(user): msg = u'{} ({}) is already a course member'.format( display_name, uni) messages.add_message(request, messages.WARNING, msg) else: email = u'{}@columbia.edu'.format(uni) self.request.course.group.user_set.add(user) send_template_email(subj, self.email_template, ctx, email) msg = (u'{} is now a course member. An email was sent to ' u'{} notifying the user.').format(display_name, email) messages.add_message(request, messages.INFO, msg) return HttpResponseRedirect( reverse('course-roster', args=[request.course.pk]))
def post(self, request): unis = request.POST.get('unis', None) url = reverse('course-roster') if unis is None: msg = 'Please enter a comma-separated list of UNIs' messages.add_message(request, messages.ERROR, msg) return HttpResponseRedirect(url) subj = u"Mediathread: {}".format(self.request.course.title) ctx = { 'course': self.request.course, 'domain': get_current_site(self.request).domain } for uni in unis_list(unis): uni = uni.lower().strip() if not self.validate_uni(uni): msg = (u'{} is not a valid UNI. To add a student without ' u'a UNI, click the "Invite Non-Columbia Affiliate" ' u'button below') msg = msg.format(uni) messages.add_message(request, messages.ERROR, msg) continue user = self.get_or_create_user(uni) display_name = user_display_name(user) if self.request.course.is_true_member(user): msg = u'{} ({}) is already a course member'.format( display_name, uni) messages.add_message(request, messages.WARNING, msg) else: email = u'{}@columbia.edu'.format(uni) self.request.course.group.user_set.add(user) send_template_email(subj, self.email_template, ctx, email) msg = ( u'{} is now a course member. An email was sent to ' u'{} notifying the user.').format(display_name, email) messages.add_message(request, messages.INFO, msg) return HttpResponseRedirect(reverse('course-roster'))
def add_existing_user(self, user): add_template = 'dashboard/email_add_user.txt' display_name = user_display_name(user) if self.request.course.is_true_member(user): msg = u'{} ({}) is already a course member'.format( display_name, user.email) messages.add_message(self.request, messages.INFO, msg) return # add existing user to course and notify them via email self.request.course.group.user_set.add(user) subject = u"Mediathread: {}".format(self.request.course.title) ctx = { 'course': self.request.course, 'domain': get_current_site(self.request).domain, 'user': user } send_template_email(subject, add_template, ctx, user.email) msg = (u'{} is now a course member. An email was sent to {} ' u'notifying the user.').format(display_name, user.email) messages.add_message(self.request, messages.INFO, msg)
def thank_faculty(self, course): send_template_email('Mediathread Course Connected', 'main/lti_course_connect.txt', {'course': course}, self.request.user.email)
def thank_faculty(self, course): send_template_email( 'Mediathread Course Connected', 'main/lti_course_connect.txt', {'course': course}, self.request.user.email)