コード例 #1
0
ファイル: views.py プロジェクト: lmm-git/EvaP
def course_email(request, semester_id, course_id):
    semester = get_object_or_404(Semester, id=semester_id)
    course = get_object_or_404(Course, id=course_id)
    form = CourseEmailForm(request.POST or None,
                           instance=course,
                           export='export' in request.POST)

    if form.is_valid():
        if form.export:
            email_addresses = '; '.join(form.email_addresses())
            messages.info(request, _('Recipients: ') + '\n' + email_addresses)
            return render(request, "staff_course_email.html",
                          dict(semester=semester, course=course, form=form))
        form.send()

        missing_email_addresses = form.missing_email_addresses()
        if missing_email_addresses == 0:
            messages.success(
                request,
                _("Successfully sent emails for '%s'.") % course.name)
        else:
            messages.warning(
                request,
                _("Successfully sent some emails for '{course}', but {count} could not be reached as they do not have an email address."
                  ).format(course=course.name, count=missing_email_addresses))
        return custom_redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_course_email.html",
                      dict(semester=semester, course=course, form=form))
コード例 #2
0
ファイル: test_forms.py プロジェクト: tomkellog/EvaP
    def test_course_email_form(self):
        """
            Tests the CourseEmailForm with one valid and one invalid input dataset.
        """
        course = course_with_responsible_and_editor()
        mommy.make(Contribution, course=course)
        data = {"body": "wat", "subject": "some subject", "recipients": ["due_participants"]}
        form = CourseEmailForm(instance=course, data=data)
        self.assertTrue(form.is_valid())
        self.assertTrue(form.missing_email_addresses() == 0)
        form.send()

        data = {"body": "wat", "subject": "some subject"}
        form = CourseEmailForm(instance=course, data=data)
        self.assertFalse(form.is_valid())
コード例 #3
0
ファイル: views.py プロジェクト: dietzi96/EvaP
def course_email(request, semester_id, course_id):
    semester = get_object_or_404(Semester, id=semester_id)
    course = get_object_or_404(Course, id=course_id)
    form = CourseEmailForm(request.POST or None, instance=course)

    if form.is_valid():
        form.send()

        missing_email_addresses = form.missing_email_addresses()
        if missing_email_addresses == 0:
            messages.success(request, _("Successfully sent emails for '%s'.") % course.name)
        else:
            messages.warning(request, _("Successfully sent some emails for '{course}', but {count} could not be reached as they do not have an email address.").format(course=course.name, count=missing_email_addresses))
        return custom_redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_course_email.html", dict(semester=semester, course=course, form=form))