Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

__init__.py 3.1 KiB

13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. """
  24. Utilities for using modules
  25. """
  26. import webnotes, os, conf
  27. transfer_types = ['Role', 'Print Format','DocType','Page','DocType Mapper',
  28. 'GL Mapper','Search Criteria', 'Patch', 'Report']
  29. lower_case_files_for = ['DocType', 'Page', 'Search Criteria', 'Report',
  30. "Workflow", 'Module Def', 'Desktop Item', 'Workflow State', 'Workflow Action']
  31. code_fields_dict = {
  32. 'Page':[('script', 'js'), ('content', 'html'), ('style', 'css'), ('static_content', 'html'), ('server_code', 'py')],
  33. 'DocType':[('server_code_core', 'py'), ('client_script_core', 'js')],
  34. 'Search Criteria':[('report_script', 'js'), ('server_script', 'py'), ('custom_query', 'sql')],
  35. 'Patch':[('patch_code', 'py')],
  36. 'Stylesheet':['stylesheet', 'css'],
  37. 'Page Template':['template', 'html'],
  38. 'Control Panel':[('startup_code', 'js'), ('startup_css', 'css')]
  39. }
  40. def scrub(txt):
  41. return txt.replace(' ','_').replace('-', '_').replace('/', '_').lower()
  42. def scrub_dt_dn(dt, dn):
  43. """Returns in lowercase and code friendly names of doctype and name for certain types"""
  44. ndt, ndn = dt, dn
  45. if dt in lower_case_files_for:
  46. ndt, ndn = scrub(dt), scrub(dn)
  47. return ndt, ndn
  48. def get_module_path(module):
  49. """Returns path of the given module"""
  50. m = scrub(module)
  51. app_path = os.path.dirname(conf.__file__)
  52. if m in ('core'):
  53. return os.path.join(app_path, 'lib', 'core')
  54. else:
  55. return os.path.join(app_path, 'app', m)
  56. def get_doc_path(module, doctype, name):
  57. dt, dn = scrub_dt_dn(doctype, name)
  58. return os.path.join(get_module_path(module), dt, dn)
  59. def reload_doc(module, dt=None, dn=None):
  60. from webnotes.modules.import_file import import_files
  61. return import_files(module, dt, dn)
  62. def export_doc(doctype, name, module=None):
  63. """write out a doc"""
  64. from webnotes.modules.export_file import write_document_file
  65. import webnotes.model.doc
  66. if not module: module = webnotes.conn.get_value(doctype, name, 'module')
  67. doclist = [d.fields for d in webnotes.model.doc.get(doctype, name)]
  68. write_document_file(doclist, module)