Ejemplo n.º 1
0
    def test_course_email_form(self):
        """
            Tests the CourseEmailForm with one valid and one invalid input dataset.
        """
        course = create_course_with_responsible_and_editor()
        data = {"body": "wat", "subject": "some subject", "recipients": [EmailTemplate.DUE_PARTICIPANTS]}
        form = CourseEmailForm(course=course, data=data)
        self.assertTrue(form.is_valid())
        form.send(None)

        data = {"body": "wat", "subject": "some subject"}
        form = CourseEmailForm(course=course, data=data)
        self.assertFalse(form.is_valid())
Ejemplo n.º 2
0
    def test_course_email_form(self):
        """
            Tests the CourseEmailForm with one valid and one invalid input dataset.
        """
        course = Course.objects.get(pk="1")
        data = {"body": "wat", "subject": "some subject", "recipients": ["due_participants"]}
        form = CourseEmailForm(instance=course, data=data)
        self.assertTrue(form.is_valid())
        form.all_recepients_reachable()
        form.send()

        data = {"body": "wat", "subject": "some subject"}
        form = CourseEmailForm(instance=course, data=data)
        self.assertFalse(form.is_valid())
Ejemplo n.º 3
0
    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": [EmailTemplate.DUE_PARTICIPANTS]}
        form = CourseEmailForm(course=course, data=data)
        self.assertTrue(form.is_valid())
        form.send(None)

        data = {"body": "wat", "subject": "some subject"}
        form = CourseEmailForm(course=course, data=data)
        self.assertFalse(form.is_valid())
Ejemplo n.º 4
0
    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())
Ejemplo n.º 5
0
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))
Ejemplo n.º 6
0
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()

        if form.all_recepients_reachable():
            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=form.missing_email_addresses()))
        return custom_redirect('evap.staff.views.semester_view', semester_id, tab=get_tab(request))
    else:
        return render(request, "staff_course_email.html", dict(semester=semester, course=course, form=form))
Ejemplo n.º 7
0
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, semester=semester)
    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()
        messages.success(request, _("Successfully sent emails for '%s'.") % course.name)
        return custom_redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_course_email.html", dict(semester=semester, course=course, form=form))
Ejemplo n.º 8
0
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))