Coverage for src/model_permissions/templatetags/model_permissions.py: 100.00%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2django-model-permissions - simple object permissions for django.
4Copyright (C) 2018 Mathias Stelzer
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with this program. If not, see <http://www.gnu.org/licenses/>.
18"""
19from django import template
21from model_permissions.views import ObjPermWrapper
24register = template.Library()
27@register.simple_tag(takes_context=True)
28def get_perms(context, obj=None):
29 """
30 Return a lookup dict to access permissions.
32 This will try to use the ``object`` in the context if none is given.
33 The lookup dict will **not** contain any object permissions if the context doesn't have an
34 ``'object'`` key or if it's ``None``.
36 """
37 user = context['user']
38 if obj is None:
39 obj = context.get('object', None)
40 return ObjPermWrapper(user, obj)