您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

52 行
1.5 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. """
  5. Utilities for using modules
  6. """
  7. import webnotes, os, conf
  8. lower_case_files_for = ['DocType', 'Page', 'Report',
  9. "Workflow", 'Module Def', 'Desktop Item', 'Workflow State', 'Workflow Action']
  10. def scrub(txt):
  11. return txt.replace(' ','_').replace('-', '_').replace('/', '_').lower()
  12. def scrub_dt_dn(dt, dn):
  13. """Returns in lowercase and code friendly names of doctype and name for certain types"""
  14. ndt, ndn = dt, dn
  15. if dt in lower_case_files_for:
  16. ndt, ndn = scrub(dt), scrub(dn)
  17. return ndt, ndn
  18. def get_module_path(module):
  19. """Returns path of the given module"""
  20. m = scrub(module)
  21. app_path = os.path.dirname(conf.__file__)
  22. if m in ('core', 'website'):
  23. return os.path.join(app_path, 'lib', m)
  24. else:
  25. return os.path.join(app_path, 'app', m)
  26. def get_doc_path(module, doctype, name):
  27. dt, dn = scrub_dt_dn(doctype, name)
  28. return os.path.join(get_module_path(module), dt, dn)
  29. def reload_doc(module, dt=None, dn=None, force=True):
  30. from webnotes.modules.import_file import import_files
  31. return import_files(module, dt, dn, force)
  32. def export_doc(doctype, name, module=None):
  33. """write out a doc"""
  34. from webnotes.modules.export_file import write_document_file
  35. import webnotes.model.doc
  36. if not module: module = webnotes.conn.get_value(doctype, name, 'module')
  37. write_document_file(webnotes.model.doc.get(doctype, name), module)
  38. def get_doctype_module(doctype):
  39. return webnotes.conn.get_value('DocType', doctype, 'module')