Beispiel #1
0
 def dispatch(self, request, *args, **kwargs):
     person = Person.objects.filter(user=request.user).first()
     if pu.is_coordinator_or_assistant(person):
         return super(UpdatePerson, self).dispatch(request, *args, **kwargs)
     else:
         raise PermissionDenied(
             'You are not allowed to access the details of this user')
Beispiel #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')
Beispiel #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)
Beispiel #4
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')
Beispiel #5
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
Beispiel #6
0
 def dispatch(self, request, *args, **kwargs):
     person = Person.objects.filter(user=request.user).first()
     if pu.is_coordinator_or_assistant(person) or request.user.is_superuser:
         return super(CreatePerson, self).dispatch(request, *args, **kwargs)
     else:
         raise PermissionDenied('You are not allowed to create a user.')