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

9 statements  

1""" 

2django-model-permissions - simple object permissions for django. 

3 

4Copyright (C) 2018 Mathias Stelzer 

5 

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. 

10 

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. 

15 

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 

20 

21from model_permissions.views import ObjPermWrapper 

22 

23 

24register = template.Library() 

25 

26 

27@register.simple_tag(takes_context=True) 

28def get_perms(context, obj=None): 

29 """ 

30 Return a lookup dict to access permissions. 

31 

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``. 

35 

36 """ 

37 user = context['user'] 

38 if obj is None: 

39 obj = context.get('object', None) 

40 return ObjPermWrapper(user, obj)