Esempio n. 1
0
    def edit_applicant_role_types(user):
        if user.is_anonymous:
            return []

        if is_admin(user):
            return [
                'admin', 'fum', 'board', 'presidium', 'group_leader', 'engaged'
            ]
        elif is_fum(user):
            return ['board', 'presidium']
        elif is_board(user):
            return ['presidium']
        elif is_presidium(user):
            return ['group_leader', 'engaged']
        elif is_group_leader(user):
            return ['engaged']

        return []
Esempio n. 2
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