from markupsafe import Markup import json import os from odoo import http from odoo.http import request # Helper to load blogs from JSON def get_blogs(): json_path = os.path.join(os.path.dirname(__file__), '../data/blogs.json') if os.path.exists(json_path): with open(json_path, 'r', encoding='utf-8') as f: return json.load(f) return [] class ContactController(http.Controller): @http.route('/contactus/submit', type='http', auth="public", website=True, csrf=True) def contact_submit(self, **post): name = post.get('name') email = post.get('email_from') phone = post.get('phone') subject = post.get('subject') message = post.get('description') # Format the email content email_content = f"""

New Contact Form Submission

Full Name: {name}
Email: {email}
Phone: {phone}
Subject: {subject}
Message:
{message}
""" mail_values = { 'subject': f"Contact Form: {subject or 'Inquiry'} from {name}", 'body_html': email_content, 'email_to': 'alaguraj0361@gmail.com', 'email_from': request.env.user.company_id.email or 'noreply@chennora.com', 'reply_to': email, } # Create and send the mail try: mail = request.env['mail.mail'].sudo().create(mail_values) mail.send() except Exception as e: # You might want to log the error pass return request.render('dine360_theme_chennora.contact_thank_you') class BlogController(http.Controller): @http.route(['/blog'], type='http', auth='public', website=True) def blog_list(self, **post): blog_posts = get_blogs() return request.render('dine360_theme_chennora.blog_page', { 'blog_posts': blog_posts, }) @http.route(['/blog/'], type='http', auth='public', website=True) def blog_detail(self, slug, **post): all_blogs = get_blogs() blog_post = next((b for b in all_blogs if b['slug'] == slug), None) if not blog_post: return request.not_found() recent_posts = [b for b in all_blogs if b['slug'] != slug][:3] # Get categories and counts categories = {} for b in all_blogs: cat = b.get('category', 'Restaurant') categories[cat] = categories.get(cat, 0) + 1 return request.render('dine360_theme_chennora.blog_detail_layout', { 'blog_title': blog_post.get('title'), 'blog_img': blog_post.get('image'), 'blog_date': blog_post.get('date'), 'blog_category': blog_post.get('category'), 'blog_content': Markup(blog_post.get('content') or ''), 'recent_posts': recent_posts, 'categories': categories, })