Esempio n. 1
0
def get_context(path):
    context = None
    context_cache = {}

    def add_data_path(context):
        if not context.data:
            context.data = {}

        context.data["path"] = path

    # try from cache
    if can_cache():
        context_cache = frappe.cache().hget("page_context", path) or {}
        context = context_cache.get(frappe.local.lang, None)

    if not context:
        context = get_route_info(path)
        context = build_context(context)

        add_data_path(context)

        if can_cache(context.no_cache):
            context_cache[frappe.local.lang] = context
            frappe.cache().hset("page_context", path, context_cache)

    else:
        add_data_path(context)

    context.update(context.data or {})

    return context
Esempio n. 2
0
def get_context(path):
    context = None
    cache_key = "page_context:{0}:{1}".format(path, frappe.local.lang)

    def add_data_path(context):
        if not context.data:
            context.data = {}

        context.data["path"] = path

    # try from memcache
    if can_cache():
        context = frappe.cache().get_value(cache_key)

    if not context:
        context = get_route_info(path)
        context = build_context(context)
        add_data_path(context)

        if can_cache(context.no_cache):
            frappe.cache().set_value(cache_key, context)

    else:
        add_data_path(context)

    context.update(context.data or {})

    return context
Esempio n. 3
0
def get_context(path, args=None):
	context = None
	context_cache = {}

	def add_data_path(context):
		if not context.data:
			context.data = {}

		context.data["path"] = path

	# try from cache
	if can_cache():
		context_cache = frappe.cache().hget("page_context", path) or {}
		context = context_cache.get(frappe.local.lang, None)

	if not context:
		context = get_route_info(path)
		if args:
			context.update(args)
		context = build_context(context)

		add_data_path(context)

		if can_cache(context.no_cache):
			context_cache[frappe.local.lang] = context
			frappe.cache().hset("page_context", path, context_cache)

	else:
		add_data_path(context)

	context.update(context.data or {})

	return context
Esempio n. 4
0
def get_context(path):
    context = None
    cache_key = "page_context:{}".format(path)

    def add_data_path(context):
        if not context.data:
            context.data = {}

        context.data["path"] = path

    # try from memcache
    if can_cache():
        context = frappe.cache().get_value(cache_key)

    if not context:
        context = get_route_info(path)

        # permission may be required for rendering
        context["access"] = frappe._dict({"public_read": 1, "public_write": 1})

        context = build_context(context)
        add_data_path(context)

        if can_cache(context.no_cache):
            frappe.cache().set_value(cache_key, context)

    else:
        context["access"] = frappe._dict({"public_read": 1, "public_write": 1})
        add_data_path(context)

    context.update(context.data or {})

    return context
Esempio n. 5
0
    def get_parents(self, context):
        # already set
        if context.parents:
            return context.parents

        home_page = get_home_page()

        parents = []
        me = self
        while me:
            _parent_field = me.website.parent_website_route_field
            _parent_val = me.get(_parent_field) if _parent_field else None

            # if no parent and not home page, then parent is home page
            if not _parent_val and me.get_route() != home_page:
                parents.append(
                    frappe._dict(name=home_page,
                                 title=get_route_info(home_page).title))
                break

            elif _parent_val:
                df = me.meta.get_field(_parent_field)
                if not df:
                    break
                parent_doc = frappe.get_doc(df.options, _parent_val)

                if not parent_doc.website_published():
                    break

                if parent_doc:
                    parent_info = frappe._dict(
                        name=parent_doc.get_route(),
                        title=parent_doc.get(
                            parent_doc.website.page_title_field or "name"))
                else:
                    parent_info = frappe._dict(
                        name=self.parent_website_route,
                        title=self.parent_website_route.replace("_",
                                                                " ").title())

                if parent_info.name in [p.name for p in parents]:
                    raise frappe.ValidationError, "Recursion in parent link"

                parents.append(parent_info)
                me = parent_doc
            else:
                # parent route is a page e.g. "blog"
                if me.get("parent_website_route"):
                    page_route = get_page_route(me.parent_website_route)
                    if page_route:
                        parents.append(
                            frappe._dict(name=page_route.name,
                                         title=page_route.page_title))
                me = None

        parents.reverse()
        return parents
Esempio n. 6
0
def get_context(path, args=None):
    context = get_route_info(path)

    if args:
        context.update(args)

    context = build_context(context)
    context["path"] = path

    return context
Esempio n. 7
0
def get_context(path, args=None):
	context = get_route_info(path)

	if args:
		context.update(args)

	context = build_context(context)
	context["path"] = path

	return context
Esempio n. 8
0
def get_context(path, args=None):
	context = get_route_info(path)

	if args:
		context.update(args)

	context = build_context(context)
	context["path"] = path

	# set using frappe.respond_as_web_page
	if hasattr(frappe.local, 'response') and frappe.local.response.get('context'):
		context.update(frappe.local.response.context)

	return context
	def get_parents(self, context):
		# already set
		if context.parents:
			return context.parents

		home_page = get_home_page()

		parents = []
		me = self
		while me:
			_parent_field = me.website.parent_website_route_field
			_parent_val = me.get(_parent_field) if _parent_field else None

			# if no parent and not home page, then parent is home page
			if not _parent_val and me.get_route() != home_page:
				parents.append(frappe._dict(name=home_page, title=get_route_info(home_page).title))
				break

			elif _parent_val:
				df = me.meta.get_field(_parent_field)
				if not df:
					break
				parent_doc = frappe.get_doc(df.options, _parent_val)

				if not parent_doc.website_published():
					break

				if parent_doc:
					parent_info = frappe._dict(name = parent_doc.get_route(),
						title= parent_doc.get(parent_doc.website.page_title_field or "name"))
				else:
					parent_info = frappe._dict(name=self.parent_website_route,
						title=self.parent_website_route.replace("_", " ").title())

				if parent_info.name in [p.name for p in parents]:
					raise frappe.ValidationError, "Recursion in parent link"

				parents.append(parent_info)
				me = parent_doc
			else:
				# parent route is a page e.g. "blog"
				if me.get("parent_website_route"):
					page_route = get_page_route(me.parent_website_route)
					if page_route:
						parents.append(frappe._dict(name = page_route.name,
							title=page_route.page_title))
				me = None

		parents.reverse()
		return parents
Esempio n. 10
0
def get_context(path):
    context = None
    cache_key = "page_context:{}".format(path)

    def add_data_path(context):
        if not context.data:
            context.data = {}

        context.data["path"] = path

    # try from memcache
    if can_cache():
        context = frappe.cache().get_value(cache_key)

    if not context:
        context = get_route_info(path)

        # permission may be required for rendering
        if context.doc and context.doc.doctype == "Website Group":
            context["access"] = get_access(context.doc, context.pathname)
        else:
            context["access"] = frappe._dict({
                "public_read": 1,
                "public_write": 1
            })

        context = build_context(context)
        add_data_path(context)

        if can_cache(context.no_cache):
            frappe.cache().set_value(cache_key, context)

    else:
        context["access"] = frappe._dict({"public_read": 1, "public_write": 1})
        add_data_path(context)

    context.update(context.data or {})

    return context