選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

55 行
1.7 KiB

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