예제 #1
0
파일: views.py 프로젝트: ccnmtl/mediathread
    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)
예제 #2
0
    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)
예제 #3
0
 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)
예제 #4
0
 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, ['*****@*****.**'])
예제 #5
0
 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, ['*****@*****.**'])
예제 #6
0
파일: views.py 프로젝트: ccnmtl/mediathread
 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)
예제 #7
0
    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)
예제 #8
0
    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]))
예제 #9
0
파일: views.py 프로젝트: ccnmtl/mediathread
    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'))
예제 #10
0
    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)
예제 #11
0
파일: views.py 프로젝트: ccnmtl/mediathread
    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)
예제 #12
0
 def thank_faculty(self, course):
     send_template_email('Mediathread Course Connected',
                         'main/lti_course_connect.txt', {'course': course},
                         self.request.user.email)
예제 #13
0
파일: views.py 프로젝트: ccnmtl/mediathread
 def thank_faculty(self, course):
     send_template_email(
         'Mediathread Course Connected',
         'main/lti_course_connect.txt',
         {'course': course}, self.request.user.email)