def set_variant_context(self, context): if self.has_variants: context.no_cache = True # load variants # also used in set_attribute_context context.variants = frappe.get_all("Item", filters={"variant_of": self.name, "show_variant_in_website": 1}, order_by="name asc") variant = frappe.form_dict.variant if not variant and context.variants: # the case when the item is opened for the first time from its list variant = context.variants[0] if variant: context.variant = frappe.get_doc("Item", variant) for fieldname in ("website_image", "web_long_description", "description", "website_specifications"): if context.variant.get(fieldname): value = context.variant.get(fieldname) if isinstance(value, list): value = [d.as_dict() for d in value] context[fieldname] = value if self.slideshow: if context.variant and context.variant.slideshow: context.update(get_slideshow(context.variant)) else: context.update(get_slideshow(self))
def set_variant_context(self, context): if self.has_variants: context.no_cache = True # load variants # also used in set_attribute_context context.variants = frappe.get_all("Item", filters={ "variant_of": self.name, "show_in_website": 1 }, order_by="name asc") variant = frappe.form_dict.variant if not variant and context.variants: # the case when the item is opened for the first time from its list variant = context.variants[0] if variant: context.variant = frappe.get_doc("Item", variant) for fieldname in ("website_image", "web_long_description", "description", "website_specifications"): if context.variant.get(fieldname): value = context.variant.get(fieldname) if isinstance(value, list): value = [d.as_dict() for d in value] context[fieldname] = value if self.slideshow: if context.variant and context.variant.slideshow: context.update(get_slideshow(context.variant)) else: context.update(get_slideshow(self))
def get_context(context): web_page = frappe._dict(context.doc.as_dict()) if web_page.slideshow: web_page.update(get_slideshow(web_page)) if web_page.enable_comments: web_page.comment_list = frappe.db.sql("""select comment, comment_by_fullname, creation from `tabComment` where comment_doctype="Web Page" and comment_docname=%s order by creation""", web_page.name, as_dict=1) or [] web_page.update({ "style": web_page.css or "", "script": web_page.javascript or "" }) web_page.update(context) web_page.metatags = { "name": web_page.title, "description": web_page.description or web_page.main_section[:150] } image = find_first_image(web_page.main_section) if image: web_page.metatags["image"] = image if not web_page.header: web_page.header = web_page.title return web_page
def get_context(context): app_context = {} if hasattr(context.doc, 'slideshow'): app_context["slideshow"] = context.doc.slideshow app_context.update(get_slideshow(context.doc)) return app_context
def get_context(context): item_context = context.doc.as_dict() item_context["parent_groups"] = get_parent_item_groups(context.doc.item_group) + [{"name": context.doc.name}] if context.doc.slideshow: item_context.update(get_slideshow(context.doc)) return item_context
def get_context(self, context): context["parent_groups"] = get_parent_item_groups(self.item_group) + \ [{"name": self.name}] if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(self, context): context.description = self.description context.title = self.exhibition_name context.header = self.exhibition_name context.content = self.content exhibition_images_items = frappe.db.sql("""\ select I.title, I.image from `tabExhibitions Images` I where I.parent = '{exhibition_name}' order by I.idx asc""".format(exhibition_name=self.name), as_dict=1) exhibition_images_items = [d for d in exhibition_images_items] context.update({ "parents": [{"name": frappe._("Home"), "route":"/"},{"name": frappe._("Events"), "route":"/events"}], "exhibition_image": self.image, "exhibition_starts_on": self.starts_on, "exhibition_ends_on": self.ends_on, "exhibition_location": self.location, "exhibition_images_items": exhibition_images_items, }) # if static page, get static content if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(self, context): # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) if self.template_path: # render dynamic context (if .py file exists) context = self.get_dynamic_context(frappe._dict(context)) # load content from template get_static_content(self, context) else: context.update({ "style": self.css or "", "script": self.javascript or "" }) self.set_metatags(context) if not context.header: context.header = self.title # for sidebar context.children = self.get_children() return context
def get_context(self, context): if context.main_section == None: context.main_section = '' # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) context.update({ "style": self.css or "", "script": self.javascript or "", "header": self.header, "title": self.title, "text_align": self.text_align, }) if self.description: context.setdefault("metatags", {})["description"] = self.description if not self.show_title: context["no_header"] = 1 if self.show_sidebar and self.website_sidebar: context.sidebar_items = frappe.get_all('Website Sidebar Item', filters=dict(parent=self.website_sidebar), fields=['title', 'route', '`group`'], order_by='idx asc') self.set_metatags(context) self.set_breadcrumbs(context) self.set_title_and_header(context) return context
def get_context(self, context): context.main_section = get_html_content_based_on_type( self, 'main_section', self.content_type) context.source_content_type = self.content_type self.render_dynamic(context) # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) context.update({ "style": self.css or "", "script": self.javascript or "", "header": self.header, "title": self.title, "text_align": self.text_align, }) if not self.show_title: context["no_header"] = 1 self.set_metatags(context) self.set_breadcrumbs(context) self.set_title_and_header(context) self.set_page_blocks(context) return context
def get_context(self, context): if context.main_section == None: context.main_section = '' # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) context.update({ "style": self.css or "", "script": self.javascript or "", "header": self.header, "title": self.title, "text_align": self.text_align, }) if self.description: context.setdefault("metatags", {})["description"] = self.description if not self.show_title: context["no_header"] = 1 self.set_metatags(context) self.set_breadcrumbs(context) self.set_title_and_header(context) return context
def get_context(self, context): # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) context.parents = [{'name': 'case_studies', 'title': _('Cases')}] return context
def get_context(self, context): # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) context.update({ "style": self.css or "", "script": self.javascript or "", "header": self.header, "title": self.title, "text_align": self.text_align, }) if self.description: context.setdefault("metatags", {})["description"] = self.description if not self.show_title: context["no_header"] = 1 self.set_metatags(context) self.set_breadcrumbs(context) self.set_title_and_header(context) return context
def get_context(self, context): if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) context.update({ "style": self.css or "", "script": self.javascript or "" }) if "<!-- render-jinja -->" in self.main_section: context["main_section"] = frappe.render_template( self.main_section, { "doc": self, "frappe": frappe }) context["no_cache"] = 1 context.metatags = { "name": self.title, "description": self.description or (self.main_section or "")[:150] } image = find_first_image(self.main_section or "") if image: context.metatags["image"] = image if not context.header: context.header = self.title return context
def get_context(context): web_page = context.bean if web_page.doc.slideshow: web_page.doc.fields.update(get_slideshow(web_page)) web_page.doc.meta_description = web_page.doc.description # web_page.doc.breadcrumbs = get_breadcrumbs(web_page) web_page.doc.toc_list = get_toc_list(web_page) # parent, child, next sibling links web_page.doc.links = get_navigation_links(web_page) if web_page.doc.enable_comments: web_page.doc.comment_list = frappe.db.sql("""select comment, comment_by_fullname, creation from `tabComment` where comment_doctype="Web Page" and comment_docname=%s order by creation""", web_page.doc.name, as_dict=1) or [] web_page.doc.fields.update({ "style": web_page.doc.css or "", "script": web_page.doc.javascript or "" }) web_page.doc.fields.update(context) return web_page.doc.fields
def get_context(self, context): context.show_search = True context.page_length = cint( frappe.db.get_single_value('Products Settings', 'products_per_page')) or 6 context.search_link = '/product_search' start = int(frappe.form_dict.start or 0) if start < 0: start = 0 context.update({ "items": get_product_list_for_group(product_group=self.name, start=start, limit=context.page_length + 1, search=frappe.form_dict.get("search")), "parents": get_parent_item_groups(self.parent_item_group), "title": self.name }) if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(self, context): context.main_section = self.main_section context.title = self.agent_name context.header = self.agent_name agents_item = frappe.db.sql("""\ select name,agent_name,route,image from `tabAgents Details` where published=1 order by idx asc""", as_dict=1) agents_item_details = [d for d in agents_item] agents_item_details = adjust_agents_count_items(agents_item_details) medication_type = frappe.db.sql("""\ select I.medication_type, I.name, I.image from `tabMedication Type` I right join `tabItem` S on I.name = S.medication_type and S.show_in_website = 1 and S.disabled = 0 where I.show_in_website =1 group by I.medication_type order by I.idx asc""", as_dict=1) agents_medication_type = [d for d in medication_type] agents_products_items = frappe.db.sql("""\ select I.name, I.item_name, I.item_code, I.route, I.medication_type,S.medication_type as medication_type_name, I.image, I.website_image, I.thumbnail as website_description from `tabItem` I left join `tabMedication Type` S on I.medication_type = S.name where I.show_in_website = 1 and I.disabled = 0 and I.agent_name = '{agent_name_d}' order by S.idx asc""".format( agent_name_d=self.name), as_dict=1) agents_products_items = [d for d in agents_products_items] context.update({ "parents": [{ "name": frappe._("Home"), "route": "/" }, { "name": frappe._("Agents"), "route": "/agents" }], "agents_image": self.image, "agents_medication_type": agents_medication_type, "agent_sidebar_item": agents_item_details, "agents_products_items": agents_products_items, "agent_sidebar_title": "Agents" }) # if static page, get static content if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(context): item_context = context.bean.doc.fields item_context["parent_groups"] = get_parent_item_groups(context.bean.doc.item_group) + \ [{"name":context.bean.doc.name}] if context.bean.doc.slideshow: item_group_context.update(get_slideshow(context.bean)) return item_context
def get_context(self, context): context.update({ "items": get_product_list_for_group(product_group = self.name, limit=100), "parent_groups": get_parent_item_groups(self.name), "title": self.name }) if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(context): item_group_context = context.doc.as_dict() item_group_context.update({ "items": get_product_list_for_group(product_group = context.docname, limit=100), "parent_groups": get_parent_item_groups(context.docname), "title": context.docname }) if context.doc.slideshow: item_group_context.update(get_slideshow(context.doc)) return item_group_context
def get_context(self, context): start = int(frappe.form_dict.start or 0) if start < 0: start = 0 context.update({ "items": get_product_list_for_group(product_group = self.name, start=start, limit=24), "parent_groups": get_parent_item_groups(self.name), "title": self.name }) if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(self, context): context.update({ "items": get_product_list_for_group(product_group=self.name, limit=100), "parent_groups": get_parent_item_groups(self.name), "title": self.name }) if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(context): item_group_context = context.doc.as_dict() item_group_context.update({ "items": get_product_list_for_group(product_group=context.docname, limit=100), "parent_groups": get_parent_item_groups(context.docname), "title": context.docname }) if context.doc.slideshow: item_group_context.update(get_slideshow(context.doc)) return item_group_context
def get_context(self, context): context.show_search=True start = int(frappe.form_dict.start or 0) if start < 0: start = 0 context.update({ "items": get_product_list_for_group(product_group = self.name, start=start, limit=24, search=frappe.form_dict.get("search")), "parent_groups": get_parent_item_groups(self.name), "title": self.name, "products_as_list": cint(frappe.db.get_single_value('Website Settings', 'products_as_list')) }) if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(self, context): # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) # for sidebar and breadcrumbs context.children = self.get_children() context.parents = self.get_parents(context) if self.template_path: # render dynamic context (if .py file exists) # get absolute template path considering first fragment as app name split_path = self.template_path.split(os.sep) self.template_path = os.path.join( frappe.get_app_path(split_path[0]), *split_path[1:]) context = self.get_dynamic_context(frappe._dict(context)) # load content from template self.get_static_content(context) else: context.update({ "style": self.css or "", "script": self.javascript or "", "header": self.header, "title": self.title, "text_align": self.text_align, }) if self.description: context.setdefault("metatags", {})["description"] = self.description if not self.show_title: context["no_header"] = 1 self.set_metatags(context) self.set_breadcrumbs(context) self.set_title_and_header(context) self.add_index(context) return context
def get_context(self, context): # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) # for sidebar and breadcrumbs context.children = self.get_children() context.parents = self.get_parents(context) if self.template_path: # render dynamic context (if .py file exists) # get absolute template path considering first fragment as app name if not self.template_path.startswith(os.sep): split_path = self.template_path.split(os.sep) self.template_path = os.path.join(frappe.get_app_path(split_path[0]), *split_path[1:]) context = self.get_dynamic_context(frappe._dict(context)) # load content from template self.get_static_content(context) else: context.update({ "style": self.css or "", "script": self.javascript or "", "header": self.header, "title": self.title, "text_align": self.text_align, }) if self.description: context.setdefault("metatags", {})["description"] = self.description if not self.show_title: context["no_header"] = 1 self.set_metatags(context) self.set_breadcrumbs(context) self.set_title_and_header(context) self.add_index(context) return context
def get_context(context): item_group_context = context.bean.doc.fields item_group_context.update({ "sub_groups": frappe.conn.sql("""select name, page_name from `tabItem Group` where parent_item_group=%s and ifnull(show_in_website,0)=1""", context.docname, as_dict=1), "items": get_product_list_for_group(product_group = context.docname, limit=100), "parent_groups": get_parent_item_groups(context.docname), "title": context.docname }) if context.bean.doc.slideshow: item_group_context.update(get_slideshow(context.bean)) for d in item_group_context.sub_groups: d.count = get_group_item_count(d.name) return item_group_context
def get_context(self, context): # this is for double precaution. usually it wont reach this code if not published if not cint(self.published): raise Exception("This blog has not been published yet!") # temp fields context.full_name = get_fullname(self.owner) context.updated = global_date_format(self.published_on) if self.blogger: context.blogger_info = frappe.get_doc("Website Blogger", self.blogger).as_dict() context.author = self.blogger context.content = get_html_content_based_on_type(self, 'content', self.content_type) context.description = self.blog_intro or strip_html_tags(context.content[:140]) context.metatags = { "name": self.title, "description": context.description, } image = find_first_image(context.content) context.cover_image = self.main_image if self.main_image: context.metatags["image"] = self.main_image elif image: context.metatags["image"] = image context.enable_comments = self.enable_comments self.load_comments(context) context.category = frappe.db.get_value("Website Blog Category", context.doc.blog_category, ["title", "route"], as_dict=1) context.parents = [{"name": _("Home"), "route":"/"}, {"name": "Blog", "route": "/blog"}, {"label": context.category.title, "route":context.category.route}] context.slideshow = self.slideshow if self.slideshow: context.update(get_slideshow(self)) blog_settings = frappe.get_doc("Website Blog Settings", "Website Blog Settings") context.blog_settings = blog_settings
def get_context(self, context): context.show_search = True context.search_link = "/search" context.body_class = "product-page" context.parents = get_parent_item_groups(self.item_group, from_item=True) # breadcumbs self.attributes = frappe.get_all( "Item Variant Attribute", fields=["attribute", "attribute_value"], filters={"parent": self.item_code}) if self.slideshow: context.update(get_slideshow(self)) self.set_variant_context(context) self.set_attribute_context(context) self.set_disabled_attributes(context) self.set_metatags(context) self.set_shopping_cart_data(context) settings = context.shopping_cart.cart_settings self.get_product_details_section(context) if settings.get("enable_reviews"): reviews_data = get_item_reviews(self.name) context.update(reviews_data) context.reviews = context.reviews[:4] context.wished = False if frappe.db.exists("Wishlist Item", { "item_code": self.item_code, "parent": frappe.session.user }): context.wished = True context.user_is_customer = check_if_user_is_customer() context.recommended_items = None if settings and settings.enable_recommendations: context.recommended_items = self.get_recommended_items(settings) return context
def get_context(self, context): start = int(frappe.form_dict.start or 0) if start < 0: start = 0 context.update({ "items": get_product_list_for_group(product_group=self.name, start=start, limit=24), "parent_groups": get_parent_item_groups(self.name), "title": self.name }) if self.slideshow: context.update(get_slideshow(self)) return context
def get_context(self, context): context.parent_groups = get_parent_item_groups(self.item_group) + \ [{"name": self.name}] if self.slideshow: context.update(get_slideshow(self)) if self.has_variants: attribute_values_available = {} context.attribute_values = {} # load variants context.variants = frappe.get_all("Item", filters={"variant_of": self.name, "show_in_website": 1}) # load attributes for v in context.variants: v.attributes = frappe.get_all("Item Variant Attribute", fields=["attribute", "attribute_value"], filters={"parent": v.name}) for attr in v.attributes: values = attribute_values_available.setdefault(attr.attribute, []) if attr.attribute_value not in values: values.append(attr.attribute_value) # filter attributes, order based on attribute table for attr in self.attributes: values = context.attribute_values.setdefault(attr.attribute, []) # get list of values defined (for sequence) for attr_value in frappe.db.get_all("Item Attribute Value", fields=["attribute_value"], filters={"parent": attr.attribute}, order_by="idx asc"): if attr_value.attribute_value in attribute_values_available.get(attr.attribute, []): values.append(attr_value.attribute_value) context.variant_info = json.dumps(context.variants) context.parents = self.get_parents(context) return context
def get_context(self, context): # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) # for sidebar and breadcrumbs context.children = self.get_children() context.parents = self.get_parents(context) if self.template_path: # render dynamic context (if .py file exists) context = self.get_dynamic_context(frappe._dict(context)) # load content from template self.get_static_content(context) else: context.update({ "style": self.css or "", "script": self.javascript or "", "header": self.header, "title": self.title, "text_align": self.text_align, }) if self.description: context.setdefault("metatags", {})["description"] = self.description if not self.show_title: context["no_header"] = 1 self.set_metatags(context) return context
def get_context(self, context): context.main_section = get_html_content_based_on_type( self, 'main_section', self.content_type) context.source_content_type = self.content_type context.title = self.title if self.context_script: _locals = dict(context=frappe._dict()) safe_exec(self.context_script, None, _locals) context.update(_locals['context']) self.render_dynamic(context) # if static page, get static content if context.slideshow: context.update(get_slideshow(self)) if self.enable_comments: context.comment_list = get_comment_list(self.doctype, self.name) context.guest_allowed = True context.update({ "style": self.css or "", "script": self.javascript or "", "header": self.header, "text_align": self.text_align, }) if not self.show_title: context["no_header"] = 1 self.set_metatags(context) self.set_breadcrumbs(context) self.set_title_and_header(context) self.set_page_blocks(context) return context
if start < 0: start = 0 context.update({ "items": get_product_list_for_group(product_group = self.name, start=start, <<<<<<< HEAD limit=context.page_length, search=frappe.form_dict.get("search")), ======= limit=context.page_length, search=frappe.form_dict.get("search")), >>>>>>> 4a121d60db136daa86f1bf72f34e694fc803c13b "parent_groups": get_parent_item_groups(self.name), "title": self.name, "products_as_list": cint(frappe.db.get_single_value('Website Settings', 'products_as_list')) }) if self.slideshow: context.update(get_slideshow(self)) return context @frappe.whitelist(allow_guest=True) def get_product_list_for_group(product_group=None, start=0, limit=10, search=None): child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(product_group)]) # base query query = """select name, item_name, item_code, route, image, website_image, thumbnail, item_group, description, web_long_description as website_description from `tabItem` where show_in_website = 1 and disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %(today)s) and (variant_of = '' or variant_of is null)