Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2Library of context processors. 

3 

4""" 

5 

6# Imports 

7 

8from django.conf import settings 

9 

10# Exports 

11 

12__all__ = ( 

13 "settings_in_context", 

14) 

15 

16# Processors 

17 

18 

19# noinspection PyUnusedLocal 

20def settings_in_context(request): 

21 """Insert certain Django settings into the context. 

22 

23 :param request: The request instance is not used. 

24 :type: request: object 

25 

26 :rtype: dict 

27 

28 To identify the settings to be included in the request context, use the ``SETTINGS_IN_CONTEXT`` in your 

29 ``settings.py`` file. 

30 

31 .. code-block:: py 

32 

33 COPYRIGHT_NAME = "Pleasant Tents, LLC" 

34 

35 MENU_ITEMS = [ 

36 ("home", "Home"), 

37 ("dashboard", "Dashboard"), 

38 ("profile", "Profile"), 

39 ] 

40 

41 SITE_TITLE = "Example Site" 

42 

43 SUPERDJANGO_SETTINGS_IN_CONTEXT = [ 

44 "COPYRIGHT_NAME", 

45 "MENU_ITEMS", 

46 "SITE_TITLE", 

47 ] 

48 

49 """ 

50 context = dict() 

51 

52 if not hasattr(settings, "SUPERDJANGO_SETTINGS_IN_CONTEXT"): 

53 return context 

54 

55 names = getattr(settings, "SUPERDJANGO_SETTINGS_IN_CONTEXT") 

56 

57 for name in names: 

58 try: 

59 context[name] = getattr(settings, name) 

60 except AttributeError: 

61 context[name] = None 

62 

63 return context