blob: 751a5b0b50ed926ab920f02f9025544b6e29a741 [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
Chillar Anand915b3432021-09-02 16:44:59 +05304
Kanchan Chauhane0818f82016-04-22 14:39:02 +05305import frappe
Kanchan Chauhane0818f82016-04-22 14:39:02 +05306
7no_cache = 1
Kanchan Chauhane0818f82016-04-22 14:39:02 +05308
Ankush Menat494bd9e2022-03-28 18:52:46 +05309
Anand Doshie3bd78e2016-04-22 18:53:21 +053010def get_context(context):
Ankush Menat25762352022-04-01 11:55:19 +053011 homepage = frappe.get_cached_doc("Homepage")
Rushabh Mehta4b9238a2016-05-12 15:22:59 +053012
Faris Ansari5f8b3582019-03-19 11:48:32 +053013 homepage.title = homepage.title or homepage.company
14 context.title = homepage.title
Rushabh Mehtaec2d09c2016-08-09 16:43:15 +053015 context.homepage = homepage
Faris Ansari5f8b3582019-03-19 11:48:32 +053016
Ankush Menat494bd9e2022-03-28 18:52:46 +053017 if homepage.hero_section_based_on == "Homepage Section" and homepage.hero_section:
Ankush Menat25762352022-04-01 11:55:19 +053018 homepage.hero_section_doc = frappe.get_cached_doc("Homepage Section", homepage.hero_section)
Faris Ansari5f8b3582019-03-19 11:48:32 +053019
20 if homepage.slideshow:
Ankush Menat25762352022-04-01 11:55:19 +053021 doc = frappe.get_cached_doc("Website Slideshow", homepage.slideshow)
Faris Ansari5f8b3582019-03-19 11:48:32 +053022 context.slideshow = homepage.slideshow
23 context.slideshow_header = doc.header
24 context.slides = doc.slideshow_items
25
Ankush Menat494bd9e2022-03-28 18:52:46 +053026 context.blogs = frappe.get_all(
27 "Blog Post",
28 fields=["title", "blogger", "blog_intro", "route"],
29 filters={"published": 1},
30 order_by="modified desc",
31 limit=3,
Faris Ansari5f8b3582019-03-19 11:48:32 +053032 )
33
34 # filter out homepage section which is used as hero section
Ankush Menat494bd9e2022-03-28 18:52:46 +053035 homepage_hero_section = (
36 homepage.hero_section_based_on == "Homepage Section" and homepage.hero_section
Faris Ansari5f8b3582019-03-19 11:48:32 +053037 )
Ankush Menat494bd9e2022-03-28 18:52:46 +053038 homepage_sections = frappe.get_all(
39 "Homepage Section",
40 filters=[["name", "!=", homepage_hero_section]] if homepage_hero_section else None,
41 order_by="section_order asc",
42 )
43 context.homepage_sections = [
Ankush Menat25762352022-04-01 11:55:19 +053044 frappe.get_cached_doc("Homepage Section", name) for name in homepage_sections
Ankush Menat494bd9e2022-03-28 18:52:46 +053045 ]
Faris Ansari5f8b3582019-03-19 11:48:32 +053046
47 context.metatags = context.metatags or frappe._dict({})
48 context.metatags.image = homepage.hero_image or None
49 context.metatags.description = homepage.description or None