Пример #1
0
def get_script(report_name):
	report = get_report_doc(report_name)

	module = report.module or frappe.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 = "frappe.query_reports['%s']={}" % report_name

	# load translations
	if frappe.lang != "en":
		send_translations(frappe.get_lang_dict("report", report_name))

	return {
		"script": script,
		"html_format": html_format
	}
Пример #2
0
	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 = frappe.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)
Пример #3
0
	def add_code(self):
		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 = frappe.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')
		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_custom_script()
		self.add_html_templates(path)
Пример #4
0
	def load_templates(self):
		module = load_doctype_module(self.name)
		app = module.__name__.split(".")[0]
		templates = {}
		if hasattr(module, "form_grid_templates"):
			for key, path in module.form_grid_templates.iteritems():
				templates[key] = get_html_format(frappe.get_app_path(app, path))

			self.set("__form_grid_templates", templates)
Пример #5
0
	def load_templates(self):
		if not self.custom:
			module = load_doctype_module(self.name)
			app = module.__name__.split(".")[0]
			templates = {}
			if hasattr(module, "form_grid_templates"):
				for key, path in module.form_grid_templates.iteritems():
					templates[key] = get_html_format(frappe.get_app_path(app, path))

				self.set("__form_grid_templates", templates)
Пример #6
0
	def add_code(self):
		path = os.path.join(get_module_path(self.module), 'doctype', scrub(self.name))
		def _get_path(fname):
			return os.path.join(path, scrub(fname))

		self._add_code(_get_path(self.name + '.js'), '__js')
		self._add_code(_get_path(self.name + '.css'), "__css")
		self._add_code(_get_path(self.name + '_list.js'), '__list_js')
		self._add_code(_get_path(self.name + '_calendar.js'), '__calendar_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_custom_script()
Пример #7
0
	def add_code(self):
		path = os.path.join(get_module_path(self.module), 'doctype', scrub(self.name))
		def _get_path(fname):
			return os.path.join(path, scrub(fname))

		self._add_code(_get_path(self.name + '.js'), '__js')
		self._add_code(_get_path(self.name + '.css'), "__css")
		self._add_code(_get_path(self.name + '_list.js'), '__list_js')
		self._add_code(_get_path(self.name + '_calendar.js'), '__calendar_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_custom_script()
Пример #8
0
def get_script(report_name):
    report = get_report_doc(report_name)
    module = report.module or frappe.db.get_value("DocType",
                                                  report.ref_doctype, "module")

    is_custom_module = frappe.get_cached_value("Module Def", module, "custom")

    # custom modules are virtual modules those exists in DB but not in disk.
    module_path = '' if is_custom_module else get_module_path(module)
    report_folder = module_path and os.path.join(module_path, "report",
                                                 scrub(report.name))
    script_path = report_folder and os.path.join(report_folder,
                                                 scrub(report.name) + ".js")
    print_path = report_folder and 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()
            script += f"\n\n//# sourceURL={scrub(report.name)}.js"

    html_format = get_html_format(print_path)

    if not script and report.javascript:
        script = report.javascript
        script += f"\n\n//# sourceURL={scrub(report.name)}__custom"

    if not script:
        script = "frappe.query_reports['%s']={}" % report_name

    # load translations
    if frappe.lang != "en":
        send_translations(frappe.get_lang_dict("report", report_name))

    return {
        "script":
        render_include(script),
        "html_format":
        html_format,
        "execution_time":
        frappe.cache().hget("report_execution_time", report_name) or 0,
    }