Example #1
0
def build_page(page_name):
	if not webnotes.conn:
		webnotes.connect()

	sitemap = get_website_sitemap()
	page_options = sitemap.get(page_name)
	
	if not page_options:
		if page_name=="index":
			# page not found, try home page
			home_page = get_home_page()
			page_options = sitemap.get(home_page)
			if not page_options:
				raise PageNotFoundError
			page_options["page_name"] = home_page
		else:
			raise PageNotFoundError
	else:
		page_options["page_name"] = page_name
	
	basepath = webnotes.utils.get_base_path()
	module = None
	no_cache = False
	
	if page_options.get("controller"):
		module = webnotes.get_module(page_options["controller"])
		no_cache = getattr(module, "no_cache", False)

	# if generator, then load bean, pass arguments
	if page_options.get("is_generator"):
		if not module:
			raise Exception("Generator controller not defined")
		
		name = webnotes.conn.get_value(module.doctype, {
			page_options.get("page_name_field", "page_name"): page_options["page_name"]})
		obj = webnotes.get_obj(module.doctype, name, with_children=True)

		if hasattr(obj, 'get_context'):
			obj.get_context()

		context = webnotes._dict(obj.doc.fields)
		context["obj"] = obj
	else:
		# page
		context = webnotes._dict({ 'name': page_name })
		if module and hasattr(module, "get_context"):
			context.update(module.get_context())
	
	context.update(get_website_settings())

	jenv = webnotes.get_jenv()
	context["base_template"] = jenv.get_template(webnotes.get_config().get("base_template"))
	
	template_name = page_options['template']	
	html = jenv.get_template(template_name).render(context)
	
	if not no_cache:
		webnotes.cache().set_value("page:" + page_name, html)
	return html
Example #2
0
def build_page(page_name):
    if not webnotes.conn:
        webnotes.connect()

    sitemap_options = webnotes.doc("Website Sitemap", page_name).fields

    page_options = webnotes.doc(
        "Website Sitemap Config",
        sitemap_options.get("website_sitemap_config")).fields.update({
            "page_name":
            sitemap_options.page_name,
            "docname":
            sitemap_options.docname
        })

    if not page_options:
        raise PageNotFoundError
    else:
        page_options["page_name"] = page_name

    basepath = webnotes.utils.get_base_path()
    no_cache = page_options.get("no_cache")

    # if generator, then load bean, pass arguments
    if page_options.get("page_or_generator") == "Generator":
        doctype = page_options.get("ref_doctype")
        obj = webnotes.get_obj(doctype,
                               page_options["docname"],
                               with_children=True)

        if hasattr(obj, 'get_context'):
            obj.get_context()

        context = webnotes._dict(obj.doc.fields)
        context["obj"] = obj
    else:
        # page
        context = webnotes._dict({'name': page_name})
        if page_options.get("controller"):
            module = webnotes.get_module(page_options.get("controller"))
            if module and hasattr(module, "get_context"):
                context.update(module.get_context())

    context.update(get_website_settings())

    jenv = webnotes.get_jenv()
    context["base_template"] = jenv.get_template(
        webnotes.get_config().get("base_template"))

    template_name = page_options['template_path']
    html = jenv.get_template(template_name).render(context)

    if not no_cache:
        webnotes.cache().set_value("page:" + page_name, html)
    return html
Example #3
0
def build_page(page_name):
	if not webnotes.conn:
		webnotes.connect()

	sitemap_options = webnotes.doc("Website Sitemap", page_name).fields
	
	page_options = webnotes.doc("Website Sitemap Config", 
		sitemap_options.get("website_sitemap_config")).fields.update({
			"page_name":sitemap_options.page_name,
			"docname":sitemap_options.docname
		})
		
	if not page_options:
		raise PageNotFoundError
	else:
		page_options["page_name"] = page_name
	
	basepath = webnotes.utils.get_base_path()
	no_cache = page_options.get("no_cache")
	

	# if generator, then load bean, pass arguments
	if page_options.get("page_or_generator")=="Generator":
		doctype = page_options.get("ref_doctype")
		obj = webnotes.get_obj(doctype, page_options["docname"], with_children=True)

		if hasattr(obj, 'get_context'):
			obj.get_context()

		context = webnotes._dict(obj.doc.fields)
		context["obj"] = obj
	else:
		# page
		context = webnotes._dict({ 'name': page_name })
		if page_options.get("controller"):
			module = webnotes.get_module(page_options.get("controller"))
			if module and hasattr(module, "get_context"):
				context.update(module.get_context())
	
	context.update(get_website_settings())

	jenv = webnotes.get_jenv()
	context["base_template"] = jenv.get_template(webnotes.get_config().get("base_template"))
	
	template_name = page_options['template_path']	
	html = jenv.get_template(template_name).render(context)
	
	if not no_cache:
		webnotes.cache().set_value("page:" + page_name, html)
	return html
Example #4
0
def add_embedded_js(doc):
	"""embed all require files"""

	import re, os
	from webnotes import conf

	js = doc.fields.get('__js') or ''

	# custom script
	custom = webnotes.conn.get_value("Custom Script", {"dt": doc.name, 
		"script_type": "Client"}, "script") or ""
	js = (js + '\n' + custom).encode("utf-8")

	if "{% include" in js:
		js = webnotes.get_jenv().from_string(js).render()
	
	doc.fields["__js"] = js
Example #5
0
def build_page(page_name):
    if not webnotes.conn:
        webnotes.connect()

    sitemap = get_website_sitemap()
    page_options = sitemap.get(page_name)

    if not page_options:
        if page_name == "index":
            # page not found, try home page
            home_page = get_home_page()
            page_options = sitemap.get(home_page)
            if not page_options:
                raise PageNotFoundError
            page_options["page_name"] = home_page
        else:
            raise PageNotFoundError
    else:
        page_options["page_name"] = page_name

    basepath = webnotes.utils.get_base_path()
    module = None
    no_cache = False

    if page_options.get("controller"):
        module = webnotes.get_module(page_options["controller"])
        no_cache = getattr(module, "no_cache", False)

    # if generator, then load bean, pass arguments
    if page_options.get("is_generator"):
        if not module:
            raise Exception("Generator controller not defined")

        name = webnotes.conn.get_value(
            module.doctype, {
                page_options.get("page_name_field", "page_name"):
                page_options["page_name"]
            })
        obj = webnotes.get_obj(module.doctype, name, with_children=True)

        if hasattr(obj, 'get_context'):
            obj.get_context()

        context = webnotes._dict(obj.doc.fields)
        context["obj"] = obj
    else:
        # page
        context = webnotes._dict({'name': page_name})
        if module and hasattr(module, "get_context"):
            context.update(module.get_context())

    context.update(get_website_settings())

    jenv = webnotes.get_jenv()
    context["base_template"] = jenv.get_template(
        webnotes.get_config().get("base_template"))

    template_name = page_options['template']
    html = jenv.get_template(template_name).render(context)

    if not no_cache:
        webnotes.cache().set_value("page:" + page_name, html)
    return html