Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

171 rinda
3.6 KiB

  1. """
  2. startup info for the app
  3. client needs info that is static across all users
  4. and user specific info like roles and defaults
  5. so calling will be:
  6. index.cgi?cmd=webnotes.startup.common_info
  7. index.cgi?cmd=webnotes.startup.user_info&user=x@y.com
  8. to clear startup,
  9. you must clear all files in the vcs starting with index.cgi?cmd=webnotes.startup
  10. """
  11. import webnotes
  12. def get_letter_heads():
  13. """
  14. get letter head
  15. """
  16. import webnotes
  17. try:
  18. lh = {}
  19. ret = webnotes.conn.sql("select name, content from `tabLetter Head` where ifnull(disabled,0)=0")
  20. for r in ret:
  21. lh[r[0]] = r[1]
  22. return lh
  23. except Exception, e:
  24. if e.args[0]==1146:
  25. return {}
  26. else:
  27. raise Exception, e
  28. def get_content_user():
  29. """
  30. get user specific content
  31. """
  32. import webnotes
  33. import webnotes.utils
  34. import webnotes.widgets.page
  35. import webnotes.widgets.menus
  36. user = webnotes.form_dict['user']
  37. doclist, ret = [], {}
  38. webnotes.conn.begin()
  39. ret['profile'] = webnotes.user.load_profile()
  40. home_page = webnotes.user.get_home_page()
  41. if home_page:
  42. doclist += webnotes.widgets.page.get(home_page)
  43. ret['sysdefaults'] = webnotes.utils.get_defaults()
  44. ret['home_page'] = home_page or ''
  45. # role-wise menus
  46. ret['start_items'] = webnotes.widgets.menus.get_menu_items()
  47. # bundle
  48. webnotes.session['data']['profile'] = ret['profile']
  49. if webnotes.session['data'].get('ipinfo'):
  50. ret['ipinfo'] = webnotes.session['data']['ipinfo']
  51. webnotes.conn.commit()
  52. webnotes.response['docs'] = doclist
  53. return ret
  54. def get_content_common():
  55. """
  56. build common startup info
  57. """
  58. import webnotes
  59. import webnotes.model.doc
  60. import webnotes.model.doctype
  61. import webnotes.model
  62. doclist, ret = [], {}
  63. doclist += webnotes.model.doc.get('Control Panel')
  64. doclist += webnotes.model.doctype.get('Event')
  65. doclist += webnotes.model.doctype.get('Search Criteria')
  66. cp = doclist[0]
  67. ret['account_name'] = cp.account_id or ''
  68. ret['letter_heads'] = get_letter_heads()
  69. ret['dt_labels'] = webnotes.model.get_dt_labels()
  70. webnotes.response['docs'] = doclist
  71. return ret
  72. def common_info():
  73. """
  74. get common startup info (from version or live)
  75. """
  76. get_info('index.cgi?cmd=webnotes.startup.common_info', 'common')
  77. def user_info():
  78. """
  79. get user info
  80. """
  81. user = webnotes.form_dict['user']
  82. get_info('index.cgi?cmd=webnotes.startup.user_info&user='+user, 'user')
  83. def get_info(fname, key):
  84. """
  85. get info from version or re-build
  86. """
  87. from build.version import VersionControl
  88. vc = VersionControl()
  89. # from versions (same static)
  90. if vc.exists(fname):
  91. content = vc.get_file(fname)['content']
  92. else:
  93. content = globals().get('get_content_'+key)()
  94. import json
  95. content = json.dumps(content)
  96. # add in vcs
  97. vc.add(fname=fname, content=content)
  98. vc.commit()
  99. vc.close()
  100. webnotes.response['content'] = content
  101. return
  102. def clear_info(info_type=None):
  103. """
  104. clear startup info and force a new version
  105. parameter: info_type = 'user' or 'common' or 'all'
  106. """
  107. if not info_type:
  108. info_type = webnotes.form_dict.get('info_type')
  109. from build.version import VersionControl
  110. vc = VersionControl()
  111. flist = []
  112. if info_type=='common':
  113. flist = ['index.cgi?cmd=webnotes.startup.common_info']
  114. elif info_type=='user':
  115. flist = [f[0] for f in vc.repo.sql("""select fname from files where fname like ?""",\
  116. ('index.cgi?cmd=webnotes.startup.user_info%',))]
  117. elif info_type=='all':
  118. flist = [f[0] for f in vc.repo.sql("""select fname from files where fname like ?""",\
  119. ('index.cgi?cmd=webnotes.startup%',))]
  120. else:
  121. webnotes.msgprint("info_type not found: %s" % info_type)
  122. for f in flist:
  123. print 'clearing %s' % f
  124. vc.remove(f)
  125. vc.commit()
  126. vc.close()