def reset_doc(doctype): ''' doctype = name of the DocType that you want to reset ''' # fetch module name module = dataent.db.get_value('DocType', doctype, 'module') app = utils.get_module_app(module) # get path for doctype's json and its equivalent git url doc_path = os.path.join(get_module_path(module), 'doctype', scrub(doctype), scrub(doctype) + '.json') try: git_link = '/'.join(['https://raw.githubusercontent.com/dataent',\ app, branch, doc_path.split('apps/'+app)[1]]) original_file = urlopen(git_link).read() except: print('Did not find {0} in {1}'.format(doctype, app)) return # load local and original json objects local_doc = json.loads(open(doc_path, 'r').read()) original_doc = json.loads(original_file) remove_duplicate_fields(doctype) set_property_setter(doctype, local_doc, original_doc) make_custom_fields(doctype, local_doc, original_doc) with open(doc_path, 'w+') as f: f.write(original_file) f.close() setup_perms_for(doctype) dataent.db.commit()
def get_file_path(module, dt, dn): dt, dn = scrub_dt_dn(dt, dn) path = os.path.join(get_module_path(module), os.path.join(dt, dn, dn + ".json")) return path
def add_code(self): if self.custom: return path = os.path.join(get_module_path(self.module), 'doctype', scrub(self.name)) def _get_path(fname): return os.path.join(path, scrub(fname)) system_country = dataent.get_system_settings("country") self._add_code(_get_path(self.name + '.js'), '__js') if system_country: self._add_code(_get_path(os.path.join('regional', system_country + '.js')), '__js') self._add_code(_get_path(self.name + '.css'), "__css") self._add_code(_get_path(self.name + '_list.js'), '__list_js') if system_country: self._add_code(_get_path(os.path.join('regional', system_country + '_list.js')), '__list_js') self._add_code(_get_path(self.name + '_calendar.js'), '__calendar_js') self._add_code(_get_path(self.name + '_tree.js'), '__tree_js') listview_template = _get_path(self.name + '_list.html') if os.path.exists(listview_template): self.set("__listview_template", get_html_format(listview_template)) self.add_code_via_hook("doctype_js", "__js") self.add_code_via_hook("doctype_list_js", "__list_js") self.add_code_via_hook("doctype_tree_js", "__tree_js") self.add_code_via_hook("doctype_calendar_js", "__calendar_js") self.add_html_templates(path)
def get_script(report_name): report = get_report_doc(report_name) module = report.module or dataent.db.get_value( "DocType", report.ref_doctype, "module") module_path = get_module_path(module) report_folder = os.path.join(module_path, "report", scrub(report.name)) script_path = os.path.join(report_folder, scrub(report.name) + ".js") print_path = os.path.join(report_folder, scrub(report.name) + ".html") script = None if os.path.exists(script_path): with open(script_path, "r") as f: script = f.read() html_format = get_html_format(print_path) if not script and report.javascript: script = report.javascript if not script: script = "dataent.query_reports['%s']={}" % report_name # load translations if dataent.lang != "en": send_translations(dataent.get_lang_dict("report", report_name)) return { "script": render_include(script), "html_format": html_format, "execution_time": dataent.cache().hget('report_execution_time', report_name) or 0 }
def load_assets(self): from dataent.modules import get_module_path, scrub import os self.script = '' page_name = scrub(self.name) path = os.path.join(get_module_path(self.module), 'page', page_name) # script fpath = os.path.join(path, page_name + '.js') if os.path.exists(fpath): with open(fpath, 'r') as f: self.script = render_include(f.read()) # css fpath = os.path.join(path, page_name + '.css') if os.path.exists(fpath): with open(fpath, 'r') as f: self.style = safe_decode(f.read()) # html as js template for fname in os.listdir(path): if fname.endswith(".html"): with open(os.path.join(path, fname), 'r') as f: template = f.read() if "<!-- jinja -->" in template: context = dataent._dict({}) try: out = dataent.get_attr("{app}.{module}.page.{page}.{page}.get_context".format( app = dataent.local.module_app[scrub(self.module)], module = scrub(self.module), page = page_name ))(context) if out: context = out except (AttributeError, ImportError): pass template = dataent.render_template(template, context) self.script = html_to_js_template(fname, template) + self.script # flag for not caching this page self._dynamic_page = True if dataent.lang != 'en': from dataent.translate import get_lang_js self.script += get_lang_js("page", self.name) for path in get_code_files_via_hooks("page_js", self.name): js = get_js(path) if js: self.script += "\n\n" + js
def create_folder(module, dt, dn, create_init): module_path = get_module_path(module) dt, dn = scrub_dt_dn(dt, dn) # create folder folder = os.path.join(module_path, dt, dn) dataent.create_folder(folder) # create init_py_files if create_init: create_init_py(module_path, dt, dn) return folder
def on_update(self): # update custom fields in mappings self.make_custom_fields_for_mappings() if dataent.flags.in_import or dataent.flags.in_test: return if dataent.local.conf.get('developer_mode'): record_list =[['Data Migration Plan', self.name]] for m in self.mappings: record_list.append(['Data Migration Mapping', m.mapping]) export_to_files(record_list=record_list, record_module=self.module) for m in self.mappings: dt, dn = scrub_dt_dn('Data Migration Mapping', m.mapping) create_init_py(get_module_path(self.module), dt, dn)