blob: 3e23fc7253b56d99453bc74853ff724d04007124 [file] [log] [blame]
Kanchan Chauhane0818f82016-04-22 14:39:02 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
Chillar Anand915b3432021-09-02 16:44:59 +05305
Kanchan Chauhane0818f82016-04-22 14:39:02 +05306import frappe
Kanchan Chauhane0818f82016-04-22 14:39:02 +05307
8no_cache = 1
Kanchan Chauhane0818f82016-04-22 14:39:02 +05309
Anand Doshie3bd78e2016-04-22 18:53:21 +053010def get_context(context):
11 homepage = frappe.get_doc('Homepage')
Rushabh Mehta4b9238a2016-05-12 15:22:59 +053012
Kanchan Chauhan239b3512016-05-02 11:43:44 +053013 for item in homepage.products:
marination37a246e2021-02-23 14:06:38 +053014 route = frappe.db.get_value('Website Item', {"item_code": item.item_code}, 'route')
Anand Doshi771ab0c2016-06-27 12:04:13 +053015 if route:
16 item.route = '/' + route
Rushabh Mehta4b9238a2016-05-12 15:22:59 +053017
Faris Ansari5f8b3582019-03-19 11:48:32 +053018 homepage.title = homepage.title or homepage.company
19 context.title = homepage.title
Rushabh Mehtaec2d09c2016-08-09 16:43:15 +053020 context.homepage = homepage
Faris Ansari5f8b3582019-03-19 11:48:32 +053021
22 if homepage.hero_section_based_on == 'Homepage Section' and homepage.hero_section:
23 homepage.hero_section_doc = frappe.get_doc('Homepage Section', homepage.hero_section)
24
25 if homepage.slideshow:
26 doc = frappe.get_doc('Website Slideshow', homepage.slideshow)
27 context.slideshow = homepage.slideshow
28 context.slideshow_header = doc.header
29 context.slides = doc.slideshow_items
30
31 context.blogs = frappe.get_all('Blog Post',
32 fields=['title', 'blogger', 'blog_intro', 'route'],
33 filters={
34 'published': 1
35 },
36 order_by='modified desc',
37 limit=3
38 )
39
40 # filter out homepage section which is used as hero section
41 homepage_hero_section = homepage.hero_section_based_on == 'Homepage Section' and homepage.hero_section
42 homepage_sections = frappe.get_all('Homepage Section',
43 filters=[['name', '!=', homepage_hero_section]] if homepage_hero_section else None,
44 order_by='section_order asc'
45 )
46 context.homepage_sections = [frappe.get_doc('Homepage Section', name) for name in homepage_sections]
47
48 context.metatags = context.metatags or frappe._dict({})
49 context.metatags.image = homepage.hero_image or None
50 context.metatags.description = homepage.description or None
51
52 context.explore_link = '/all-products'