93 lines
4.1 KiB
Python
93 lines
4.1 KiB
Python
from odoo import http
|
|
from odoo.http import request
|
|
|
|
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"""
|
|
<div style="font-family: Arial, sans-serif; padding: 20px; border: 1px solid #ddd; border-radius: 8px;">
|
|
<h2 style="color: #2BB1A5; border-bottom: 2px solid #FECD4F; padding-bottom: 10px;">New Contact Form Submission</h2>
|
|
<table style="width: 100%; border-collapse: collapse; margin-top: 15px;">
|
|
<tr>
|
|
<td style="padding: 8px; font-weight: bold; width: 30%;">Full Name:</td>
|
|
<td style="padding: 8px;">{name}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="padding: 8px; font-weight: bold;">Email:</td>
|
|
<td style="padding: 8px;">{email}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="padding: 8px; font-weight: bold;">Phone:</td>
|
|
<td style="padding: 8px;">{phone}</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="padding: 8px; font-weight: bold;">Subject:</td>
|
|
<td style="padding: 8px;">{subject}</td>
|
|
</tr>
|
|
</table>
|
|
<div style="margin-top: 20px; padding: 15px; background-color: #F8F9FA; border-left: 4px solid #2BB1A5;">
|
|
<strong style="display: block; margin-bottom: 10px;">Message:</strong>
|
|
<div style="white-space: pre-wrap;">{message}</div>
|
|
</div>
|
|
</div>
|
|
"""
|
|
|
|
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 = request.env['chennora.blog.post'].sudo().search([('active', '=', True)])
|
|
return request.render('dine360_theme_chennora.blog_page', {
|
|
'blog_posts': blog_posts,
|
|
})
|
|
|
|
@http.route(['/blog/<string:slug>'], type='http', auth='public', website=True)
|
|
def blog_detail(self, slug, **post):
|
|
blog_post = request.env['chennora.blog.post'].sudo().search([('slug', '=', slug), ('active', '=', True)], limit=1)
|
|
if not blog_post:
|
|
return request.not_found()
|
|
|
|
recent_posts = request.env['chennora.blog.post'].sudo().search([('active', '=', True), ('id', '!=', blog_post.id)], limit=3)
|
|
|
|
# Get dynamic categories and counts
|
|
all_posts = request.env['chennora.blog.post'].sudo().search([('active', '=', True)])
|
|
categories = {}
|
|
for p in all_posts:
|
|
if p.category:
|
|
categories[p.category] = categories.get(p.category, 0) + 1
|
|
|
|
return request.render('dine360_theme_chennora.blog_detail_layout', {
|
|
'blog_title': blog_post.title,
|
|
'blog_img': blog_post.image,
|
|
'blog_date': blog_post.date.strftime('%B %d, %Y') if blog_post.date else '',
|
|
'blog_category': blog_post.category,
|
|
'blog_content': blog_post.content,
|
|
'recent_posts': recent_posts,
|
|
'categories': categories,
|
|
})
|
|
|