예제 #1
0
	def add_custom_context_and_script(self, context):
		'''Update context from module if standard and append script'''
		if self.web_form_module:
			new_context = self.web_form_module.get_context(context)

			if new_context:
				context.update(new_context)

			js_path = os.path.join(os.path.dirname(self.web_form_module.__file__), scrub(self.name) + '.js')
			if os.path.exists(js_path):
				script = frappe.render_template(open(js_path, 'r').read(), context)

				for path in get_code_files_via_hooks("webform_include_js", context.doc_type):
					custom_js = frappe.render_template(open(path, 'r').read(), context)
					script = "\n\n".join([script, custom_js])

				context.script = script

			css_path = os.path.join(os.path.dirname(self.web_form_module.__file__), scrub(self.name) + '.css')
			if os.path.exists(css_path):
				style = open(css_path, 'r').read()

				for path in get_code_files_via_hooks("webform_include_css", context.doc_type):
					custom_css = open(path, 'r').read()
					style = "\n\n".join([style, custom_css])

				context.style = style
예제 #2
0
    def load_assets(self):
        import os

        from frappe.modules import get_module_path, scrub

        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())
                self.script += f"\n\n//# sourceURL={page_name}.js"

        # 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 = frappe._dict({})
                        try:
                            out = frappe.get_attr(
                                "{app}.{module}.page.{page}.{page}.get_context"
                                .format(app=frappe.local.module_app[scrub(
                                    self.module)],
                                        module=scrub(self.module),
                                        page=page_name))(context)

                            if out:
                                context = out
                        except (AttributeError, ImportError):
                            pass

                        template = frappe.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 frappe.lang != "en":
            from frappe.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
예제 #3
0
파일: page.py 프로젝트: ESS-LLP/frappe
	def load_assets(self):
		from frappe.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 = frappe._dict({})
						try:
							out = frappe.get_attr("{app}.{module}.page.{page}.{page}.get_context".format(
								app = frappe.local.module_app[scrub(self.module)],
								module = scrub(self.module),
								page = page_name
							))(context)

							if out:
								context = out
						except (AttributeError, ImportError):
							pass

						template = frappe.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 frappe.lang != 'en':
			from frappe.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
예제 #4
0
    def load_assets(self):
        from frappe.modules import get_module_path, scrub
        import os

        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 = unicode(f.read(), "utf-8")

        # css
        fpath = os.path.join(path, page_name + '.css')
        if os.path.exists(fpath):
            with open(fpath, 'r') as f:
                self.style = unicode(f.read(), "utf-8")

        # 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 = unicode(f.read(), "utf-8")
                    if "<!-- jinja -->" in template:
                        context = frappe._dict({})
                        try:
                            out = frappe.get_attr(
                                "{app}.{module}.page.{page}.{page}.get_context"
                                .format(app=frappe.local.module_app[scrub(
                                    self.module)],
                                        module=scrub(self.module),
                                        page=page_name))(context)

                            if out:
                                context = out
                        except (AttributeError, ImportError):
                            pass

                        template = frappe.render_template(template, context)
                    self.script = html_to_js_template(fname,
                                                      template) + self.script

        if frappe.lang != 'en':
            from frappe.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