Exemplo n.º 1
0
    def get_form(self, *args, **kwargs):
        """
        Return a form with the organizations limited to the organizations
        this user has access to. Returns a form with all availble
        organizations for super users.

        Since mixin is used in views that subclass CreateView or UpdateView
        I am relying on those to provide the `get_form` as implemented
        in the `FormMixin` both of those inherit
        """
        form = FormMixin.get_form(self, *args, **kwargs)
        if self.request.user.is_superuser:
            return form

        form.controller_form.fields['organization'].queryset = (
            self.request.user.organization_set.all())
        return form
Exemplo n.º 2
0
    def get_form(self, *args, **kwargs):
        """
        Return a form with the organizations limited to the organizations
        this user has access to. Returns a form with all availble
        organizations for super users.

        Since mixin is used in views that subclass CreateView or UpdateView
        I am relying on those to provide the `get_form` as implemented
        in the `FormMixin` both of those inherit
        """
        form = FormMixin.get_form(self, *args, **kwargs)
        if self.request.user.is_superuser:
            return form

        form.controller_form.fields['organization'].queryset = (
            self.request.user.organization_set.all())
        return form