Created
August 4, 2018 00:06
-
-
Save olivx/d19547c253450c0fa3298f9d9127659e to your computer and use it in GitHub Desktop.
protect acess url views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.auth import REDIRECT_FIELD_NAME | |
| from django.contrib.auth.decorators import user_passes_test | |
| from account.models import Profile | |
| def client_user_denied(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url='account:login'): | |
| actual_decorator = user_passes_test( | |
| lambda u: u.is_active and u.profile.type > 0, | |
| login_url=login_url, redirect_field_name=redirect_field_name | |
| ) | |
| if function: | |
| return actual_decorator(function) | |
| return actual_decorator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.auth.decorators import login_required | |
| from django.utils.decorators import method_decorator | |
| from account.decorator import client_user_denied | |
| from django.contrib.auth.mixins import LoginRequiredMixin | |
| @client_user_denied | |
| @login_required | |
| def home(request): | |
| return render(request, 'index.html', {}) | |
| @method_decorator([client_user_denied], name='dispatch') | |
| class ProductList(LoginRequiredMixin, ListView): | |
| model = Produto | |
| paginate_by = 5 | |
| template_name = 'product_list.html' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment