Guest User

Untitled

a guest
Jul 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1.  
  2. from json import load, JSONDecoder
  3. from tg import config
  4. import os
  5.  
  6.  
  7. def parsetagstomap (jsondata, tags = dict()):
  8. for tag in jsondata:
  9. if 'data' in tag:
  10. tags[tag['attributes']['id']] = tag['data']
  11. tags[tag['data']] = tag['attributes']['id']
  12. if 'children' in tag:
  13. tags = parsetagstomap (tag['children'], tags)
  14. return tags
  15.  
  16. def gettagmap ():
  17. with open('wiki20/public/tags.json', 'r') as f:
  18. entry = load(f)
  19. return parsetagstomap(entry)
  20.  
  21.  
  22. app_globals.py
  23. # -*- coding: utf-8 -*-
  24.  
  25. from wiki20.utils.jsonutil import gettagmap
  26.  
  27. """The application's Globals object"""
  28.  
  29. __all__ = ['Globals']
  30.  
  31.  
  32. class Globals(object):
  33. """Container for objects available throughout the life of the application.
  34.  
  35. One instance of Globals is created during application initialization and
  36. is available during requests via the 'app_globals' variable.
  37.  
  38. """
  39.  
  40. def __init__(self):
  41. """Do nothing, by default."""
  42. self.tagmap = gettagmap ()
Add Comment
Please, Sign In to add comment