Exemple #1
0
    def test_student(self):
        is_student = pu.is_student(self.student)
        self.assertEqual(is_student, True)

        is_student_of_module_success = pu.is_student_of_module(
            self.student, self.module_ed_assigned)
        # print('student: ' + str(self.student.university_number))
        # print('module: ' + self.module_unassigned.code)
        # print('is_student: ' + str(is_student_of_module_success))
        self.assertEqual(is_student_of_module_success, True)

        is_student_of_module_failure = pu.is_student_of_module(
            self.student, self.module_ed_unassigned)
        # print('student: '+self.student.university_number)
        # print('module: '+self.module_unassigned.code)
        # print('is_student: '+str(is_student_of_module_failure))
        # print("assigned: " + self.module_ed_assigned.code)
        # print("unassigned: "+self.module_ed_unassigned.code)
        self.assertEqual(is_student_of_module_failure, False)

        self.assertEqual(pu.is_coordinator(self.student), False)
        self.assertEqual(pu.is_coordinator_assistant(self.student), False)
        self.assertEqual(pu.is_study_adviser(self.student), False)
        self.assertEqual(pu.is_teacher(self.student), False)
        self.assertEqual(pu.is_teaching_assistant(self.student), False)
Exemple #2
0
 def dispatch(self, request, *args, **kwargs):
     self.person = Person.objects.filter(user=request.user).first()
     if pu.is_coordinator_or_assistant(self.person) or pu.is_teacher(
             self.person) or pu.is_study_adviser(
                 self.person) or pu.is_teaching_assistant(self.person):
         return super(PersonsView, self).dispatch(request, *args, **kwargs)
     else:
         raise PermissionDenied('You are not a module coordinator')
Exemple #3
0
def manual_view(request):
    person = Person.objects.filter(user=request.user).first()
    if pu.is_coordinator_or_assistant(person) or pu.is_study_adviser(
            person) or pu.is_teacher(person) or pu.is_teaching_assistant(
                person):
        try:
            return FileResponse(open('{}Seth/Seth/manual.pdf'.format(OS_PATH),
                                     'rb'),
                                content_type='application/pdf')
        except FileNotFoundError:
            return not_found(request)
    else:
        return permission_denied(request)
Exemple #4
0
    def test_teacher(self):
        is_teacher = pu.is_teacher(self.teacher)
        self.assertEqual(is_teacher, True)

        is_teacher_of_module_part_success = pu.is_teacher_of_part(
            self.teacher, self.module_part_assigned)
        self.assertEqual(is_teacher_of_module_part_success, True)

        is_teacher_of_module_part_failure = pu.is_teacher_of_part(
            self.teacher, self.module_part_unassigned)
        self.assertEqual(is_teacher_of_module_part_failure, False)

        self.assertEqual(pu.is_coordinator(self.teacher), False)
        self.assertEqual(pu.is_coordinator_assistant(self.teacher), False)
        self.assertEqual(pu.is_study_adviser(self.teacher), False)
        self.assertEqual(pu.is_teaching_assistant(self.teacher), False)
        self.assertEqual(pu.is_student(self.teacher), False)
Exemple #5
0
    def dispatch(self, request, **kwargs):
        """
        Checks the type of logged in user and directs to an appropriate dashboard with relevant information.

        :param **kwargs:
        :param request: Django request for authentication
        :return: Redirect to appropriate dashboard (based on type of user)
        """
        person = Person.objects.filter(user=self.request.user).first()

        if pu.is_coordinator_or_assistant(person):
            context = {
                'modules': self.make_modules_context()['module_editions'],
                'time': get_current_date(),
                'person': Person.objects.filter(user=request.user)[0]
            }
            return render(request, 'dashboard/index.html', context)
        if pu.is_study_adviser(person):
            return redirect('sa_dashboard')
            # return render(request, 'dashboard/sa_index.html')
        if pu.is_teacher(person):
            print(self.make_module_parts_context()['module_parts'])
            context = {
                'module_parts':
                self.make_module_parts_context()['module_parts'],
                'person': Person.objects.filter(user=request.user)[0]
            }
            return render(request, 'dashboard/teacher_index.html', context)
        if pu.is_teaching_assistant(person):
            print(Person.objects.filter(user=request.user))
            context = {
                'module_parts':
                self.make_module_parts_context()['module_parts'],
                'person': Person.objects.filter(user=request.user)[0]
            }
            return render(request, 'dashboard/ta_index.html', context)
        if pu.is_student(person):
            studying = Studying.objects.filter(person=person)
            return redirect(
                'grades:student',
                studying.get(person__user=self.request.user).person.id)
        else:
            return redirect('not_in_seth')
Exemple #6
0
    def test_adviser(self):
        is_adviser = pu.is_study_adviser(self.adviser)
        self.assertEqual(is_adviser, True)

        is_adviser_of_study_success = pu.is_study_adviser_of_study(
            self.adviser, self.study_assigned)
        # print(Study.objects.filter(pk=self.study_assigned.pk)[0].advisers.all())
        # print(self.adviser)
        self.assertEqual(is_adviser_of_study_success, True)

        is_adviser_of_study_failure = pu.is_study_adviser_of_study(
            self.adviser, self.study_unassigned)
        self.assertEqual(is_adviser_of_study_failure, False)

        self.assertEqual(pu.is_coordinator(self.adviser), False)
        self.assertEqual(pu.is_coordinator_assistant(self.adviser), False)
        self.assertEqual(pu.is_teacher(self.adviser), False)
        self.assertEqual(pu.is_teaching_assistant(self.adviser), False)
        self.assertEqual(pu.is_student(self.adviser), False)
Exemple #7
0
    def test_coordinator_assistant(self):
        is_coordinator_assistant = pu.is_coordinator_assistant(
            self.coordinator_assistant)
        self.assertEqual(is_coordinator_assistant, True)

        is_coordinator_assistant_of_module_success = pu.is_coordinator_assistant_of_module(
            self.coordinator_assistant, self.module_ed_assigned)
        self.assertEqual(is_coordinator_assistant_of_module_success, True)

        is_coordinator_assistant_of_module_failure = pu.is_coordinator_assistant_of_module(
            self.coordinator_assistant, self.module_ed_unassigned)
        self.assertEqual(is_coordinator_assistant_of_module_failure, False)

        self.assertEqual(pu.is_coordinator(self.coordinator_assistant), False)
        self.assertEqual(pu.is_study_adviser(self.coordinator_assistant),
                         False)
        self.assertEqual(pu.is_teacher(self.coordinator_assistant), False)
        self.assertEqual(pu.is_teaching_assistant(self.coordinator_assistant),
                         False)
        self.assertEqual(pu.is_student(self.coordinator_assistant), False)
Exemple #8
0
def known_persons(person):
    """
    Returns all Person-objects that are considered to be related to a given user.
    Case Coordinator/Coordinator-assistant: Return all students from all modules that are coordinated by that person
    Case Teacher: Return all students from moduleparts that are taught by that person
    Case Adviser: Return all students that are in all modules of all studies that have that person as adviser
    Users can be part of multiple cases.

    :param person: The person all other persons must be related to.
    :return: All persons related to the given user.
    """
    qs = Person.objects.none()
    if pu.is_coordinator_or_assistant(person):
        qs = qs.union(
            Person.objects.filter(
                Q(studying__module_edition__coordinators=person)
                | Q(coordinator__module_edition__coordinators=person)
                | Q(teacher__module_part__module_edition__coordinators=person)
            ).order_by('university_number').distinct('university_number'))
    if pu.is_teacher(person) or pu.is_teaching_assistant(person):
        qs = qs.union(
            Person.objects.filter(
                Q(studying__module_edition__modulepart__teachers=person)
                | Q(coordinator__module_edition__modulepart__teachers=person)
                | Q(teacher__module_part__module_edition__modulepart__teachers=
                    person)).order_by('university_number').distinct(
                        'university_number'))
    if pu.is_study_adviser(person):
        qs = qs.union(
            Person.objects.filter(
                Q(studying__module_edition__module__study__advisers=person)
                | Q(moduleedition__module__study__advisers=person) |
                Q(teacher__module_part__module_edition__module__study__advisers
                  =person)).order_by('university_number').distinct(
                      'university_number'))
    return qs