25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
1.4 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. import webnotes.utils
  9. lower_case_files_for = ['DocType', 'Page', 'Report',
  10. "Workflow", 'Module Def', 'Desktop Item', 'Workflow State', 'Workflow Action']
  11. def scrub(txt):
  12. return webnotes.scrub(txt)
  13. def scrub_dt_dn(dt, dn):
  14. """Returns in lowercase and code friendly names of doctype and name for certain types"""
  15. ndt, ndn = dt, dn
  16. if dt in lower_case_files_for:
  17. ndt, ndn = scrub(dt), scrub(dn)
  18. return ndt, ndn
  19. def get_module_path(module):
  20. """Returns path of the given module"""
  21. return webnotes.get_module_path(module)
  22. def get_doc_path(module, doctype, name):
  23. dt, dn = scrub_dt_dn(doctype, name)
  24. return os.path.join(get_module_path(module), dt, dn)
  25. def reload_doc(module, dt=None, dn=None, force=True):
  26. from webnotes.modules.import_file import import_files
  27. return import_files(module, dt, dn, force=force)
  28. def export_doc(doctype, name, module=None):
  29. """write out a doc"""
  30. from webnotes.modules.export_file import write_document_file
  31. import webnotes.model.doc
  32. if not module: module = webnotes.conn.get_value(doctype, name, 'module')
  33. write_document_file(webnotes.model.doc.get(doctype, name), module)
  34. def get_doctype_module(doctype):
  35. return webnotes.conn.get_value('DocType', doctype, 'module') or "core"