Esempio n. 1
0
 def test_create_section_first_param_not_course(self):
     with self.assertRaises(
             TypeError,
             msg=
             "The create_section() function must take a course object as its first argument"
     ):
         create_section("hello", 83)
Esempio n. 2
0
 def test_create_section_second_param_not_int(self):
     with self.assertRaises(
             TypeError,
             msg=
             "The create_section() function must take an integer as its second argument"
     ):
         create_section(self.course1, "string")
Esempio n. 3
0
    def post(self, request):

        # sections = MySection.objects.all()
        courses = MyCourse.objects.all()
        message = create_section(request.POST['course_selection'],
                                 request.POST['section_number'])
        if type(message) is MySection:  # There was good input
            # sections.append(message)
            return render(request, "course.html", {
                "courses": courses,
                "message": "Course successfully added"
            })
        else:
            return render(request, "course.html", {
                "courses": courses,
                "message": message
            })
Esempio n. 4
0
 def test_create_section_not_enough_args(self):
     with self.assertRaises(
             TypeError,
             msg="The create_section() function must take two arguments"):
         create_section(self.course1)
Esempio n. 5
0
 def test_create_section_too_many_args(self):
     with self.assertRaises(
             TypeError,
             msg="The create_section() function must take two arguments"):
         create_section(self.course1, 456, "third")
Esempio n. 6
0
 def test_create_section_number_small(self):
     self.assertEqual(
         create_section(self.course1, 83),
         "The section number is not 3 digits long.  Try again.")
Esempio n. 7
0
 def test_create_section_number_unused(self):
     self.assertIsInstance(create_section(self.course1, 801), MySection)
Esempio n. 8
0
 def test_create_section_number_used(self):
     self.assertEqual(
         create_section(self.course1, 901),
         "A section with this number within this course has already been created.  Try again."
     )
Esempio n. 9
0
    def post(self, request):
        accounts = MyUser.objects.filter(role__in=['instructor', 'ta'])
        courses = MyCourse.objects.all()
        sections = MySection.objects.all()
        request.session['submitted'] = True
        if request.method == 'POST' and 'course_button' in request.POST:
            number = request.POST['number']
            courses = list(MyCourse.objects.all())
            message = create_course(request.POST['name'], int(number))
            if type(message) is MyCourse:  # There was good input
                courses.append(message)
                request.session['error'] = False
                return render(
                    request, "course.html", {
                        "courses": courses,
                        "message": "Course successfully added",
                        "accounts": accounts,
                        "sections": sections
                    })
            else:
                request.session['error'] = True
                return render(
                    request, "course.html", {
                        "courses": courses,
                        "message": message,
                        "accounts": accounts,
                        "sections": sections
                    })

        if request.method == 'POST' and 'section_button' in request.POST:
            message = create_section(
                MyCourse.objects.get(id=request.POST['course_selection']),
                int(request.POST['section_number']))
            if type(message) is MySection:  # There was good input
                # sections.append(message)
                request.session['error'] = False
                return render(
                    request, "course.html", {
                        "courses": courses,
                        "message": "Section successfully added",
                        "accounts": accounts,
                        "sections": sections
                    })
            else:
                request.session['error'] = True
                return render(
                    request, "course.html", {
                        "courses": courses,
                        "message": message,
                        "accounts": accounts,
                        "sections": sections
                    })

        if request.method == 'POST' and 'ass_butt' in request.POST:
            courses = MyCourse.objects.all()
            accounts = MyUser.objects.filter(role__in=['instructor', 'ta'])
            sections = MySection.objects.all()
            course_selection = request.POST['course_selection']
            course_selection = MyCourse(course_selection)
            person_selection = request.POST['person_selection']
            person_selection = MyUser(person_selection)

            course_selection.people.add(person_selection)
            accounts = MyUser.objects.filter(role__in=['instructor', 'ta'])
            return render(
                request, "course.html", {
                    "message": "Course assignments updated",
                    "courses": courses,
                    "accounts": accounts,
                    "sections": sections
                })

        if request.method == 'POST' and 'ass_section_butt' in request.POST:
            accounts = MyUser.objects.filter(role__in=['instructor', 'ta'])
            courses = MyCourse.objects.all()
            sections = MySection.objects.all()
            person_selection = request.POST['person_selection']
            person_selection = MyUser.objects.get(id=person_selection)
            #person_selection = MyUser(person_selection)
            section_selection = request.POST['section_selection']
            section_selection = MySection.objects.get(id=section_selection)
            #section_selection = MySection(section_selection)

            message = ValidTeacherForSection(person_selection,
                                             section_selection)
            request.session['error'] = message[0]
            return render(
                request, "course.html", {
                    "message": message[1],
                    "courses": courses,
                    "accounts": accounts,
                    "sections": sections
                })

        if request.method == 'POST' and 'delSButt' in request.POST:
            accounts = MyUser.objects.all()
            courses = MyCourse.objects.all()
            sections = MySection.objects.all()
            section_to_remove = request.POST['section_to_remove']
            section_to_remove = MySection(section_to_remove)
            section_to_remove.delete()

            return render(
                request, "course.html", {
                    "message": "section successfully deleted",
                    "courses": courses,
                    "accounts": accounts,
                    "sections": sections
                })

        if request.method == 'POST' and 'delCButt' in request.POST:
            accounts = MyUser.objects.filter(role__in=['instructor', 'ta'])
            sections = MySection.objects.all()
            course_to_remove = request.POST['course_to_remove']
            course_to_remove = MyCourse(course_to_remove)
            for i in sections:
                if i.course == course_to_remove:
                    i.delete()
            sections = MySection.objects.all()
            course_to_remove.delete()
            courses = MyCourse.objects.all()

            return render(
                request, "course.html", {
                    "message": "Course successfully deleted",
                    "courses": courses,
                    "accounts": accounts,
                    "sections": sections
                })