Exemplo n.º 1
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
	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
Exemplo n.º 3
0
    def get_parents(self, context):
        # already set
        if context.parents:
            return context.parents

        parents = []
        parent = self
        while parent:
            _parent_field = getattr(parent, "parent_website_route_field", None)
            _parent_val = parent.get(_parent_field) if _parent_field else None
            if _parent_val:
                df = parent.meta.get_field(_parent_field)
                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(
                            getattr(parent_doc, "page_title_field", "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)
                parent = parent_doc
            else:
                # parent route is a page e.g. "blog"
                if parent.get("parent_website_route"):
                    page_route = get_page_route(parent.parent_website_route)
                    if page_route:
                        parents.append(
                            frappe._dict(name=page_route.name,
                                         title=page_route.page_title))
                parent = None

        parents.reverse()
        return parents
Exemplo n.º 4
0
	def get_parents(self):
		parents = []
		parent = self
		while parent:
			_parent_field = getattr(parent, "parent_website_route_field", None)
			_parent_val = parent.get(_parent_field) if _parent_field else None
			if _parent_val:
				df = parent.meta.get_field(_parent_field)
				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(getattr(parent_doc, "page_title_field", "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)
				parent = parent_doc
			else:
				# parent route is a page e.g. "blog"
				if parent.get("parent_website_route"):
					page_route = get_page_route(parent.parent_website_route)
					if page_route:
						parents.append(frappe._dict(name = page_route.name,
							title=page_route.page_title))
				parent = None

		parents.reverse()
		return parents