Tuesday, May 28, 2019

Re: How to use permissions on a CreateView class?

Fellipe,

Here is an example of decorating class based views from the documentation:

from django.contrib.auth.decorators import login_required  from django.utils.decorators import method_decorator  from django.views.generic import TemplateView    class ProtectedView(TemplateView):      template_name = 'secret.html'        @method_decorator(login_required)      def dispatch(self, *args, **kwargs):          return super().dispatch(*args, **kwargs)

On Tuesday, May 28, 2019 at 6:54:38 AM UTC-5, Fellipe Henrique wrote:
Hello,

I have these class, based on CreateView class... and I only want allow user with these permissions to add record...

class ClienteCreateView(ERPbrViewMixin, CreateView):
template_name = 'cadastro/cliente/form.html'
permission_required = ('cliente.can_open', 'cliente.can_edit', 'cliente.can_add')
model = Cliente
form_class = ClienteForm
But, not working... user without these permission, when type the url show the form...

Any tips how to do that?

Cheers!


T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/060a2c59-bf39-456c-a686-bf6ba104e1f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment