示例#1
0
 def get_queryset(self):
     if UserType.get_user_type(self.request) in (UserType.CHAIRMAN,
                                                 UserType.FACULTY):
         return self.model.objects.filter(
             mother_department=UserType.get_department_id(self.request))
     elif UserType.get_user_type(self.request) == UserType.NONE:
         return self.model.objects.none()
     else:
         return self.model.objects.all()
示例#2
0
    def dispatch(self, request, *args, **kwargs):
        if UserType.get_user_type(request) == UserType.CHAIRMAN:
            self.course = get_object_or_404(
                Course,
                pk=kwargs.get('pk', 0),
                mother_department=UserType.get_department_id(request),
            )
        else:
            self.course = get_object_or_404(
                Course,
                pk=kwargs.get('pk', 0),
            )

        return super().dispatch(request, *args, **kwargs)
def show_user_and_type(context):
    request = context['request']
    return format_html(
        '<span class="user_name">{user_name}</span>&nbsp;&nbsp;'
        '(<span class="user_type">{user_type}</span>)&nbsp;&nbsp;',
        user_name=get_full_name(request.user),
        user_type=UserType.get_user_type(request),
    )
示例#4
0
    def get_context_data(self, *, object_list=None, **kwargs):
        context = super().get_context_data(object_list=object_list, **kwargs)
        context['can_create_course'] = bool(
            UserType.get_user_type(self.request) == UserType.CHAIRMAN)

        paginator, page, queryset, is_paginated = self.paginate_queryset(
            self.get_queryset(), self.paginate_by)
        context['caretakers'] = get_courses_caretakers(queryset)

        if UserType.get_user_type(self.request) in (UserType.CHAIRMAN,
                                                    UserType.FACULTY):
            context['department_name'] = get_department_name(
                UserType.get_department_id(self.request))
            college_id = get_college_id(
                UserType.get_department_id(self.request))
            context['college_name'] = get_college_name(college_id)

        context['can_assign_caretakers'] = context['can_create_course']
        return context
def define_session_variables(sender, request, **kwargs):
    UserType.set_user_type(request)
def define_session_variables_for_impersonator(sender, request, impersonator,
                                              impersonating, **kwargs):
    UserType.set_user_type(request, impersonating)
示例#7
0
 def form_valid(self, form):
     new_course = form.save(commit=False)
     new_course.mother_department = UserType.get_department_id(self.request)
     new_course.save()
     return redirect(
         reverse_lazy('main_app:assign_caretakers', args=(new_course.pk, )))
示例#8
0
 def test_func(self):
     if self.allowed_user_types == '__all__':
         return True
     else:
         return UserType.get_user_type(
             self.request) in self.allowed_user_types