コード例 #1
0
ファイル: wagtail_hooks.py プロジェクト: vaids-vipra/moore
 def get_queryset(self, request):
     if is_super(request.user):
         return super(RoleAdmin, self).get_queryset(request)
     else:
         qs = Role.edit_role_types_of(request.user)
         ordering = self.get_ordering(request)
         if ordering:
             qs = qs.order_by(*ordering)
         return qs
コード例 #2
0
ファイル: wagtail_hooks.py プロジェクト: vaids-vipra/moore
 def get_queryset(self, request):
     if is_super(request.user):
         return super(ContactCardAdmin, self).get_queryset(request)
     else:
         roles = Role.edit_applicant_permission_of(request.user)
         qs = ContactCard.objects.filter(position__role__in=roles, )
         ordering = self.get_ordering(request)
         if ordering:
             qs = qs.order_by(*ordering)
         return qs
コード例 #3
0
    def get_form(self):
        form = super(PositionCreateView, self).get_form()
        queryset = form.fields['role'].queryset
        if not is_super(self.request.user):
            queryset = Role.edit_role_types_of(self.request.user)

        queryset = queryset.filter(archived=False)

        form.fields['role'].queryset = queryset
        return form
コード例 #4
0
ファイル: wagtail_hooks.py プロジェクト: vaids-vipra/moore
 def get_queryset(self, request):
     if is_super(request.user):
         return super(PositionAdmin, self).get_queryset(request)
     else:
         roles = Role.edit_role_types_of(request.user)
         qs = Position.objects.filter(role__in=roles)
         ordering = self.get_ordering(request)
         if ordering:
             qs = qs.order_by(*ordering)
         return qs
コード例 #5
0
    def get_form(self, form_class=None):
        form = super(PositionEditView, self).get_form(form_class=form_class)
        queryset = form.fields['role'].queryset
        if not is_super(self.request.user):
            queryset = Role.edit_role_types_of(self.request.user)

        init = Role.objects.get(pk=form.initial['role'])
        if not init.archived:
            queryset = queryset.filter(archived=False)

        form.fields['role'].queryset = queryset
        return form
コード例 #6
0
 def get_queryset(self, request):
     if is_super(request.user):
         return super(ApplicationAdmin, self).get_queryset(request)
     else:
         roles = Role.edit_applicant_permission_of(request.user)
         qs = Application.objects.filter(
             status__in=['turned_down', 'submitted',
                         'approved', 'disapproved'],
             position__role__in=roles,
         )
         ordering = self.get_ordering(request)
         if ordering:
             qs = qs.order_by(*ordering)
         return qs
コード例 #7
0
    def get_form(self, form_class=None):
        form = super(ApplicationEditView, self).get_form(form_class=form_class)

        if not is_super(self.request.user) \
                and not is_admin(self.request.user):
            # Filter status
            form.fields['status'].choices = form.fields['status'].choices[1:]
            accepted_choices = ['submitted', 'approved', 'disapproved']
            filtered_choices = []
            for choice in form.fields['status'].choices:
                if choice[0] in accepted_choices:
                    filtered_choices.append(choice)
            form.fields['status'].choices = filtered_choices

            # Filter position
            position_qs = form.fields['position'].queryset
            roles = Role.edit_role_types_of(self.request.user)
            position_qs = position_qs.filter(role__in=roles)
            form.fields['position'].queryset = position_qs

        return form
コード例 #8
0
def can_modify_role(user, role):
    return role.role_type in Role.editable_role_types(user)
コード例 #9
0
def can_set_applicant(user, position):
    return position.role.role_type in Role.edit_applicant_role_types(user)