Example #1
0
def build_context(sitemap_options):
    """get_context method of doc or module is supposed to render content templates and push it into context"""
    context = frappe._dict(sitemap_options)
    context.update(get_website_settings())

    # provide doc
    if context.doc:
        context.update(context.doc.as_dict())
        if hasattr(context.doc, "get_context"):
            ret = context.doc.get_context(context)
            if ret:
                context.update(ret)

        for prop in ("no_cache", "no_sitemap"):
            if not prop in context:
                context[prop] = getattr(context.doc, prop, False)

    elif context.controller:
        module = frappe.get_module(context.controller)

        if module:
            if hasattr(module, "get_context"):
                ret = module.get_context(context)
                if ret:
                    context.update(ret)
            if hasattr(module, "get_children"):
                context.children = module.get_children(context)

    add_metatags(context)

    if context.get("base_template_path") != context.get(
            "template") and not context.get("rendered"):
        context.data = render_blocks(context)

    return context
Example #2
0
def build_context(sitemap_options):
    """get_context method of doc or module is supposed to render content templates and push it into context"""
    context = frappe._dict(sitemap_options)
    context.update(get_website_settings())

    # provide doc
    if context.doc:
        context.update(context.doc.as_dict())
        if hasattr(context.doc, "get_context"):
            context.update(context.doc.get_context(context) or {})

    elif context.controller:
        module = frappe.get_module(context.controller)

        if module:
            if hasattr(module, "get_context"):
                context.update(module.get_context(context) or {})
            if hasattr(module, "get_children"):
                context.get_children = module.get_children

    add_metatags(context)

    if context.get("base_template_path") != context.get(
            "template") and not context.get("rendered"):
        context.data = render_blocks(context)

    return context
Example #3
0
def update_website_context(context):

    from frappe.utils.jinja import get_jenv

    if not frappe.form_dict._lang:
        frappe.local.flags.redirect_location = (frappe.local.request.path + (not frappe.local.request.path.endswith("?") and "?" or "") +
                                                (frappe.form_dict and
                                                 ("&".join("{0}={1}".format(key, value) for key, value in frappe.form_dict.items()) + "&") or "")
                                                + "_lang=ar")
        raise frappe.Redirect
    jenv = get_jenv()

    frappe.local.jenv.globals["get_context"] = get_context

    return

    if frappe.local.flags.in_context_update:
        return context

    frappe.local.flags.in_context_update = True

    from frappe.website.doctype.website_settings.website_settings import get_website_settings

    cookie_manager = frappe.request.cookies

    frappe.local.lang =  cookie_manager and cookie_manager.get("lang", "en")

    context.update(get_website_settings())

    frappe.local.flags.in_context_update = False
def build_context(context):
    """get_context method of doc or module is supposed to render
		content templates and push it into context"""
    context = frappe._dict(context)

    if not "url_prefix" in context:
        context.url_prefix = ""

    if context.url_prefix and context.url_prefix[-1] != '/':
        context.url_prefix += '/'

    context.update(get_website_settings())
    context.update(frappe.local.conf.get("website_context") or {})

    # provide doc
    if context.doc:
        context.update(context.doc.as_dict())
        context.update(context.doc.website)
        if hasattr(context.doc, "get_context"):
            ret = context.doc.get_context(context)

            if ret:
                context.update(ret)

        for prop in ("no_cache", "no_sitemap"):
            if not prop in context:
                context[prop] = getattr(context.doc, prop, False)

    elif context.controller:
        module = frappe.get_module(context.controller)

        if module:
            # get config fields
            for prop in ("base_template_path", "template", "no_cache",
                         "no_sitemap", "condition_field"):
                if hasattr(module, prop):
                    context[prop] = getattr(module, prop)

            if hasattr(module, "get_context"):
                ret = module.get_context(context)
                if ret:
                    context.update(ret)

            if hasattr(module, "get_children"):
                context.children = module.get_children(context)

    add_metatags(context)

    if context.show_sidebar:
        add_sidebar_data(context)

    # determine templates to be used
    if not context.base_template_path:
        app_base = frappe.get_hooks("base_template")
        context.base_template_path = app_base[
            0] if app_base else "templates/base.html"

    return context
Example #5
0
def build_context(context):
	"""get_context method of doc or module is supposed to render
		content templates and push it into context"""
	context = frappe._dict(context)

	if not "url_prefix" in context:
		context.url_prefix = ""

	if context.url_prefix and context.url_prefix[-1]!='/':
		context.url_prefix += '/'

	context.update(get_website_settings())
	context.update(frappe.local.conf.get("website_context") or {})

	# provide doc
	if context.doc:
		context.update(context.doc.as_dict())
		context.update(context.doc.website)
		if hasattr(context.doc, "get_context"):
			ret = context.doc.get_context(context)

			if ret:
				context.update(ret)

		for prop in ("no_cache", "no_sitemap"):
			if not prop in context:
				context[prop] = getattr(context.doc, prop, False)

	elif context.controller:
		module = frappe.get_module(context.controller)

		if module:
			# get config fields
			for prop in ("base_template_path", "template", "no_cache", "no_sitemap",
				"condition_field"):
				if hasattr(module, prop):
					context[prop] = getattr(module, prop)

			if hasattr(module, "get_context"):
				ret = module.get_context(context)
				if ret:
					context.update(ret)

			if hasattr(module, "get_children"):
				context.children = module.get_children(context)

	add_metatags(context)

	if context.show_sidebar:
		add_sidebar_data(context)

	# determine templates to be used
	if not context.base_template_path:
		app_base = frappe.get_hooks("base_template")
		context.base_template_path = app_base[0] if app_base else "templates/base.html"

	return context
Example #6
0
def build_context(context):
	"""get_context method of doc or module is supposed to render
		content templates and push it into context"""
	context = frappe._dict(context)

	if not "url_prefix" in context:
		context.url_prefix = ""

	if context.url_prefix and context.url_prefix[-1]!='/':
		context.url_prefix += '/'

	context.update(get_website_settings())
	context.update(frappe.local.conf.get("website_context") or {})

	# provide doc
	if context.doc:
		context.update(context.doc.as_dict())
		context.update(context.doc.website)
		if hasattr(context.doc, "get_context"):
			ret = context.doc.get_context(context)

			if ret:
				context.update(ret)

		for prop in ("no_cache", "no_sitemap"):
			if not prop in context:
				context[prop] = getattr(context.doc, prop, False)

	elif context.controller:
		# controller based context
		update_controller_context(context, context.controller)

		# controller context extensions
		context_controller_hooks = frappe.get_hooks("extend_website_page_controller_context") or {}
		for controller, extension in context_controller_hooks.items():
			if isinstance(extension, list):
				for ext in extension:
					if controller == context.controller:
						update_controller_context(context, ext)
			else:
				update_controller_context(context, extension)

	add_metatags(context)

	if context.show_sidebar:
		context.no_cache = 1
		add_sidebar_data(context)

	# determine templates to be used
	if not context.base_template_path:
		app_base = frappe.get_hooks("base_template")
		context.base_template_path = app_base[0] if app_base else "templates/base.html"

	return context
Example #7
0
def get_settings():
    ahong_settings = frappe.get_single("Ahong eCommerce Settings")
    website_settings = get_website_settings()

    return merge(
        keyfilter(lambda x: x in ["copyright", "footer_address"], website_settings),
        {
            "privacy": bool(ahong_settings.privacy),
            "terms": bool(ahong_settings.terms),
            "show_about_us": bool(ahong_settings.show_about_us),
            "hide_build_info": bool(ahong_settings.hide_build_info),
        },
    )
Example #8
0
def get_settings():
    from frappe.website.doctype.website_settings.website_settings import (
        get_website_settings, )

    leiteng_settings = frappe.get_single("Leiteng Website Settings")
    allcat_groups = [x.item_group for x in leiteng_settings.allcat_groups]
    slideshow = _get_slideshow_settings(leiteng_settings)

    settings = get_website_settings()

    return merge(
        pick(["copyright", "footer_address"], settings),
        {
            "root_groups": _get_root_groups(),
            "allcat_groups": allcat_groups,
            "slideshow": slideshow,
            "privacy": bool(leiteng_settings.privacy),
            "terms": bool(leiteng_settings.terms),
            "show_about_us": bool(leiteng_settings.show_about_us),
            "hide_build_info": bool(leiteng_settings.hide_build_info),
        },
    )
Example #9
0
def build_context(sitemap_options):
    """get_context method of bean or module is supposed to render content templates and push it into context"""
    context = frappe._dict(sitemap_options)
    context.update(get_website_settings())

    # provide bean
    if context.doctype and context.docname:
        context.bean = frappe.bean(context.doctype, context.docname)

    if context.controller:
        module = frappe.get_module(context.controller)
        if module and hasattr(module, "get_context"):
            context.update(module.get_context(context) or {})

    if context.get("base_template_path") != context.get(
            "template_path") and not context.get("rendered"):
        context.data = render_blocks(context)

    # remove bean, as it is not pickle friendly and its purpose is over
    if context.bean:
        del context["bean"]

    return context
Example #10
0
def build_context(context):
	"""get_context method of doc or module is supposed to render
		content templates and push it into context"""
	context = frappe._dict(context)

	if not "url_prefix" in context:
		context.url_prefix = ""

	if context.url_prefix and context.url_prefix[-1]!='/':
		context.url_prefix += '/'

	# for backward compatibility
	context.docs_base_url = '/docs'

	context.update(get_website_settings())
	context.update(frappe.local.conf.get("website_context") or {})

	# provide doc
	if context.doc:
		context.update(context.doc.as_dict())
		context.update(context.doc.get_website_properties())

		if not context.template:
			context.template = context.doc.meta.get_web_template()

		if hasattr(context.doc, "get_context"):
			ret = context.doc.get_context(context)

			if ret:
				context.update(ret)

		for prop in ("no_cache", "no_sitemap"):
			if not prop in context:
				context[prop] = getattr(context.doc, prop, False)

	elif context.controller:
		# controller based context
		update_controller_context(context, context.controller)

		# controller context extensions
		context_controller_hooks = frappe.get_hooks("extend_website_page_controller_context") or {}
		for controller, extension in context_controller_hooks.items():
			if isinstance(extension, list):
				for ext in extension:
					if controller == context.controller:
						update_controller_context(context, ext)
			else:
				update_controller_context(context, extension)

	add_metatags(context)
	add_sidebar_and_breadcrumbs(context)

	# determine templates to be used
	if not context.base_template_path:
		app_base = frappe.get_hooks("base_template")
		context.base_template_path = app_base[0] if app_base else "templates/base.html"

	if context.title_prefix and context.title and not context.title.startswith(context.title_prefix):
		context.title = '{0} - {1}'.format(context.title_prefix, context.title)

	return context
Example #11
0
def build_context(context):
    """get_context method of doc or module is supposed to render
		content templates and push it into context"""
    context = frappe._dict(context)

    if not "url_prefix" in context:
        context.url_prefix = ""

    if context.url_prefix and context.url_prefix[-1] != '/':
        context.url_prefix += '/'

    # for backward compatibility
    context.docs_base_url = '/docs'

    context.update(get_website_settings(context))
    context.update(frappe.local.conf.get("website_context") or {})

    # provide doc
    if context.doc:
        context.update(context.doc.as_dict())
        context.update(context.doc.get_website_properties())

        if not context.template:
            context.template = context.doc.meta.get_web_template()

        if hasattr(context.doc, "get_context"):
            ret = context.doc.get_context(context)

            if ret:
                context.update(ret)

        for prop in ("no_cache", "sitemap"):
            if not prop in context:
                context[prop] = getattr(context.doc, prop, False)

    elif context.controller:
        # controller based context
        update_controller_context(context, context.controller)

        # controller context extensions
        context_controller_hooks = frappe.get_hooks(
            "extend_website_page_controller_context") or {}
        for controller, extension in context_controller_hooks.items():
            if isinstance(extension, list):
                for ext in extension:
                    if controller == context.controller:
                        update_controller_context(context, ext)
            else:
                update_controller_context(context, extension)

    add_metatags(context)
    add_sidebar_and_breadcrumbs(context)

    # determine templates to be used
    if not context.base_template_path:
        app_base = frappe.get_hooks("base_template")
        context.base_template_path = app_base[
            -1] if app_base else "templates/base.html"

    if context.title_prefix and context.title and not context.title.startswith(
            context.title_prefix):
        context.title = '{0} - {1}'.format(context.title_prefix, context.title)

    # apply context from hooks
    update_website_context = frappe.get_hooks('update_website_context')
    for method in update_website_context:
        values = frappe.get_attr(method)(context)
        if values:
            context.update(values)

    return context
Example #12
0
def get_footer_description():
	return get_website_settings().address
Example #13
0
def get_footer_brand():
	return "<img src='{0}' style='max-height:84px;width:auto;'>".format(get_website_settings().footer_brand)
Example #14
0
 def init_context(self):
     self.context = frappe._dict()
     self.context.update(get_website_settings())
     self.context.update(frappe.local.conf.get("website_context") or {})
Example #15
0
def build_context(context):
	"""get_context method of doc or module is supposed to render
		content templates and push it into context"""
	context = frappe._dict(context)

	if not "url_prefix" in context:
		context.url_prefix = ""

	if context.url_prefix and context.url_prefix[-1]!='/':
		context.url_prefix += '/'

	context.update(get_website_settings())
	context.update(frappe.local.conf.get("website_context") or {})

	# provide doc
	if context.doc:
		context.update(context.doc.as_dict())
		context.update(context.doc.get_website_properties())

		if not context.template:
			context.template = context.doc.meta.get_web_template()

		if hasattr(context.doc, "get_context"):
			ret = context.doc.get_context(context)

			if ret:
				context.update(ret)

		for prop in ("no_cache", "no_sitemap"):
			if not prop in context:
				context[prop] = getattr(context.doc, prop, False)

	elif context.controller:
		# controller based context
		update_controller_context(context, context.controller)

		# controller context extensions
		context_controller_hooks = frappe.get_hooks("extend_website_page_controller_context") or {}
		for controller, extension in context_controller_hooks.items():
			if isinstance(extension, list):
				for ext in extension:
					if controller == context.controller:
						update_controller_context(context, ext)
			else:
				update_controller_context(context, extension)

	add_metatags(context)

	if context.show_sidebar:
		context.no_cache = 1
		add_sidebar_data(context)
	else:
		if context.basepath:
			sidebar_json_path = os.path.join(context.basepath, '_sidebar.json')
			if os.path.exists(sidebar_json_path):
				with open(sidebar_json_path, 'r') as sidebarfile:
					context.sidebar_items = json.loads(sidebarfile.read())
					context.show_sidebar = 1


	# determine templates to be used
	if not context.base_template_path:
		app_base = frappe.get_hooks("base_template")
		context.base_template_path = app_base[0] if app_base else "templates/base.html"

	if context.title_prefix and context.title and not context.title.startswith(context.title_prefix):
		context.title = '{0} - {1}'.format(context.title_prefix, context.title)

	return context