root/lib/sct/sphenecoll/sphene/community/context_processors.py

Revision 147:942e3ce3d7d2, 1.8 kB (checked in by Daniele Varrazzo <piro@develer.com>, 1 year ago)

Sphene package updated to r803.

Line 
1 from django.conf import settings
2 from sphene.community.models import Navigation
3 from sphene.community.permissionutils import has_permission_flag
4 from sphene.community.sphutils import SphSettings
5 from sphene.community.middleware import get_current_group, get_current_sphdata, get_current_user
6
7
8 class PermissionFlagLookup(object):
9     def __getitem__(self, flag_name):
10         return has_permission_flag(get_current_user(), flag_name)
11
12
13 def navigation(request):
14     if hasattr(request, 'attributes') and 'group' in request.attributes:
15         group = request.attributes['group']
16     else:
17         group = get_current_group()
18     sphdata = get_current_sphdata()
19
20     sph_settings = getattr( settings, 'SPH_SETTINGS', None )
21     sphdata['installed_apps'] = settings.INSTALLED_APPS
22     sphdata['current_url'] = request.path
23     querystring = request.META.get('QUERY_STRING', None)
24     if querystring:
25         sphdata['current_url'] += '?'+querystring
26     # urlPrefix is deprecated, don't use it.
27     urlPrefix = ''
28     if hasattr(request, 'attributes'):
29         urlPrefix = request.attributes.get('urlPrefix', '')
30     if group:
31         return { 'navigation_left': Navigation.objects.filter( group = group,
32                                                                navigationType = 0 ),
33                  'navigation_top': Navigation.objects.filter( group = group,
34                                                                navigationType = 1 ),
35                  'urlPrefix': urlPrefix,
36                  'group': group,
37                  'sph': sphdata,
38                  'sph_settings': SphSettings(),
39                  'sph_perms': PermissionFlagLookup(),
40                  }
41     return { 'sph': sphdata,
42              'sph_settings': SphSettings(),
43              'sph_perms': PermissionFlagLookup(),
44              }
Note: See TracBrowser for help on using the browser.