Kanchan Chauhan | e0818f8 | 2016-04-22 14:39:02 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 4 | |
Kanchan Chauhan | e0818f8 | 2016-04-22 14:39:02 +0530 | [diff] [blame] | 5 | import frappe |
Kanchan Chauhan | e0818f8 | 2016-04-22 14:39:02 +0530 | [diff] [blame] | 6 | |
| 7 | no_cache = 1 |
Kanchan Chauhan | e0818f8 | 2016-04-22 14:39:02 +0530 | [diff] [blame] | 8 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 9 | |
Anand Doshi | e3bd78e | 2016-04-22 18:53:21 +0530 | [diff] [blame] | 10 | def get_context(context): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 11 | homepage = frappe.get_doc("Homepage") |
Rushabh Mehta | 4b9238a | 2016-05-12 15:22:59 +0530 | [diff] [blame] | 12 | |
Kanchan Chauhan | 239b351 | 2016-05-02 11:43:44 +0530 | [diff] [blame] | 13 | for item in homepage.products: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 14 | route = frappe.db.get_value("Website Item", {"item_code": item.item_code}, "route") |
Anand Doshi | 771ab0c | 2016-06-27 12:04:13 +0530 | [diff] [blame] | 15 | if route: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 16 | item.route = "/" + route |
Rushabh Mehta | 4b9238a | 2016-05-12 15:22:59 +0530 | [diff] [blame] | 17 | |
Faris Ansari | 5f8b358 | 2019-03-19 11:48:32 +0530 | [diff] [blame] | 18 | homepage.title = homepage.title or homepage.company |
| 19 | context.title = homepage.title |
Rushabh Mehta | ec2d09c | 2016-08-09 16:43:15 +0530 | [diff] [blame] | 20 | context.homepage = homepage |
Faris Ansari | 5f8b358 | 2019-03-19 11:48:32 +0530 | [diff] [blame] | 21 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 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) |
Faris Ansari | 5f8b358 | 2019-03-19 11:48:32 +0530 | [diff] [blame] | 24 | |
| 25 | if homepage.slideshow: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 26 | doc = frappe.get_doc("Website Slideshow", homepage.slideshow) |
Faris Ansari | 5f8b358 | 2019-03-19 11:48:32 +0530 | [diff] [blame] | 27 | context.slideshow = homepage.slideshow |
| 28 | context.slideshow_header = doc.header |
| 29 | context.slides = doc.slideshow_items |
| 30 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 31 | context.blogs = frappe.get_all( |
| 32 | "Blog Post", |
| 33 | fields=["title", "blogger", "blog_intro", "route"], |
| 34 | filters={"published": 1}, |
| 35 | order_by="modified desc", |
| 36 | limit=3, |
Faris Ansari | 5f8b358 | 2019-03-19 11:48:32 +0530 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | # filter out homepage section which is used as hero section |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 40 | homepage_hero_section = ( |
| 41 | homepage.hero_section_based_on == "Homepage Section" and homepage.hero_section |
Faris Ansari | 5f8b358 | 2019-03-19 11:48:32 +0530 | [diff] [blame] | 42 | ) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 43 | homepage_sections = frappe.get_all( |
| 44 | "Homepage Section", |
| 45 | filters=[["name", "!=", homepage_hero_section]] if homepage_hero_section else None, |
| 46 | order_by="section_order asc", |
| 47 | ) |
| 48 | context.homepage_sections = [ |
| 49 | frappe.get_doc("Homepage Section", name) for name in homepage_sections |
| 50 | ] |
Faris Ansari | 5f8b358 | 2019-03-19 11:48:32 +0530 | [diff] [blame] | 51 | |
| 52 | context.metatags = context.metatags or frappe._dict({}) |
| 53 | context.metatags.image = homepage.hero_image or None |
| 54 | context.metatags.description = homepage.description or None |
| 55 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 56 | context.explore_link = "/all-products" |