Пример #1
0
    def __init__(self, available_roles=None, *args, **kwargs):
        """
        Custom logic to reduce the available permissions
        """
        super(GymUserPermissionForm, self).__init__(*args, **kwargs)

        if available_roles is None:
            available_roles = []
        field_choices = [(self.USER, _('User'))]
        if 'trainer' in available_roles:
            field_choices.append((self.TRAINER, _('Trainer')))
        if 'admin' in available_roles:
            field_choices.append((self.GYM_ADMIN, _('Gym administrator')))
        if 'manager' in available_roles:
            field_choices.append((self.MANAGER, _('General manager')))

        self.fields['role'] = forms.MultipleChoiceField(
            choices=field_choices,
            initial=User,
            widget=BootstrapSelectMultiple(),
        )
        self.helper = FormHelper()
        self.helper.form_class = 'wger-form'
        self.helper.add_input(
            Submit('submit', _("Save"), css_class='btn-success btn-block'))
Пример #2
0
 class Meta:
     model = User
     widgets = {'role': BootstrapSelectMultiple()}
     fields = (
         'first_name',
         'last_name',
         'username',
         'email',
         'role',
     )
Пример #3
0
    def __init__(self, available_roles=[], *args, **kwargs):
        '''
        Custom logic to reduce the available permissions
        '''
        super(GymUserPermisssionForm, self).__init__(*args, **kwargs)

        field_choices = [(self.USER, _('User'))]
        if 'trainer' in available_roles:
            field_choices.append((self.TRAINER, _('Trainer')))
        if 'admin' in available_roles:
            field_choices.append((self.GYM_ADMIN, _('Gym administrator')))
        if 'manager' in available_roles:
            field_choices.append((self.MANAGER, _('General manager')))

        self.fields['role'] = forms.MultipleChoiceField(choices=field_choices,
                                                        initial=User,
                                                        widget=BootstrapSelectMultiple())