[IMP] website_crm

- added error management in contact us form, using a new error argument in the view;
- improved thanks template, to display more like contactus with company description;
- extracted company description in website to be able to re-use it in thanks template
- added optional company_name in contactus form, used to flil partner_name in lead

bzr revid: tde@openerp.com-20131002114818-y369gu6u32uxry1m
This commit is contained in:
Thibault Delavallée
2013-10-02 13:48:18 +02:00
parent 7d7cbce6fd
commit fabe8d7208
3 changed files with 92 additions and 46 deletions
+15 -12
View File
@@ -271,6 +271,20 @@
</t>
</template>
<template id="company_description" name="Company Description">
<address>
<strong t-field="res_company.name">Name</strong><br />
<span t-field="res_company.street"></span> <span t-field="res_company.state_id"></span><br />
<span t-field="res_company.zip"></span> <span t-field="res_company.city"></span><br />
<span t-field="res_company.country_id"> </span><br />
<br />
<span>&amp;#x2706; <span t-field="res_company.phone"></span></span><br />
<i class="icon-envelope"></i> <span t-field="res_company.email"></span>
</address>
<a t-att-href="res_company.partner_id.google_map_link()" target="_BLANK">
<img class="thumbnail img-responsive" t-att-src="res_company.partner_id.google_map_img()" />
</a>
</template>
<template id="contactus" name="Contact us" page="True">
<t t-call="website.layout">
@@ -292,18 +306,7 @@
</div>
</div>
<div class="col-md-4">
<address>
<strong t-field="res_company.name">Name</strong><br />
<span t-field="res_company.street"></span> <span t-field="res_company.state_id"></span><br />
<span t-field="res_company.zip"></span> <span t-field="res_company.city"></span><br />
<span t-field="res_company.country_id"> </span><br />
<br />
<span>&amp;#x2706; <span t-field="res_company.phone"></span></span><br />
<i class="icon-envelope"></i> <span t-field="res_company.email"></span>
</address>
<a t-att-href="res_company.partner_id.google_map_link()" target="_BLANK">
<img class="thumbnail img-responsive" t-att-src="res_company.partner_id.google_map_img()" />
</a>
<t t-call="website.company_description"/>
</div>
</div>
</div>
+25 -4
View File
@@ -6,17 +6,38 @@ from openerp.addons.website.models import website
from urllib import quote_plus
class contactus(http.Controller):
def generate_google_map_url(self, street, city, city_zip, country_name):
url = "http://maps.googleapis.com/maps/api/staticmap?center=%s&sensor=false&zoom=8&size=298x298" % quote_plus(
'%s, %s %s, %s' % (street, city, city_zip, country_name)
)
return url
@website.route(['/crm/contactus'], type='http', auth="admin", multilang=True)
def contactus(self, *arg, **post):
required_fields = ['contact_name', 'email_from', 'description']
post['user_id'] = False
error = set()
values = dict((key, post.get(key)) for key in post)
values['error'] = error
# fields validation
for field in required_fields:
if not post.get(field):
error.add(field)
if error:
return request.website.render("website.contactus", values)
# if not given: subject is contact name
if not post.get('name'):
post['name'] = post.get('contact_name')
request.registry['crm.lead'].create(request.cr, request.uid,
post, request.context)
company = request.website.company_id
values = {
'google_map_url': "http://maps.googleapis.com/maps/api/staticmap?center=%s&sensor=false&zoom=8&size=298x298" % quote_plus('%s, %s %s, %s' % (company.street, company.city, company.zip, company.country_id and company.country_id.name_get()[0][1] or ''))
'google_map_url': self.generate_google_map_url(company.street, company.city, company.zip, company.country_id and company.country_id.name_get()[0][1] or '')
}
return request.website.render("website_crm.thanks", values)
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
return request.website.render("website_crm.contactus_thanks", values)
+52 -30
View File
@@ -5,34 +5,34 @@
<template id="contactus_form" name="Contact Form" inherit_id="website.contactus" inherit_option_id="website.contactus">
<xpath expr="//div[@name='mail_button']" position="replace">
<form t-action="/crm/contactus" method="post" class="form-horizontal mt32" >
<div class="form-group">
<div t-attf-class="form-group #{error and 'contact_name' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="contact_name">Your Name</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control" name="contact_name" required="True" />
<input type="text" class="form-control" name="contact_name" required="True" t-attf-value="#{contact_name or ''}"/>
</div>
</div>
<div class="form-group">
<div t-attf-class="form-group #{error and 'phone' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="phone">Phone Number</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control" name="phone" required="True" placeholder="e.g. (+32).81.81.37.00"/>
<input type="text" class="form-control" name="phone" placeholder="e.g. (+32).81.81.37.00" t-attf-value="#{phone or ''}"/>
</div>
</div>
<div class="form-group">
<div name="email_from_container" t-attf-class="form-group #{error and 'email_from' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="email_from">Email</label>
<div class="col-md-7 col-sm-8">
<input type="email" class="form-control" name="email_from" required="True" />
<input type="email" class="form-control" name="email_from" required="True" t-attf-value="#{email_from or ''}"/>
</div>
</div>
<div class="form-group">
<div t-attf-class="form-group #{error and 'name' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="name">Subject</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control" name="name" required="True"/>
<input type="text" class="form-control" name="name" t-attf-value="#{name or ''}"/>
</div>
</div>
<div class="form-group">
<div t-attf-class="form-group #{error and 'description' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="description">Your Question</label>
<div class="col-md-7 col-sm-8">
<textarea class="form-control" name="description" style="min-height: 120px"/>
<textarea class="form-control" name="description" style="min-height: 120px" required="True" t-attf-value="#{description or ''}"/>
</div>
</div>
<div class="form-group">
@@ -44,27 +44,49 @@
</xpath>
</template>
<template id="thanks">
<t t-call="website.layout">
<t t-set="title">Message Sent</t>
<div id="wrap" class="oe_structure">
<div class="container">
<div class="alert alert-success">
Your message has been sent successfully.
<button type="button" class="close" data-dismiss="alert">&amp;times;</button>
</div>
<h2>Thanks!</h2>
<p>
We will get back to you shortly.
</p><p class="mt64">
If you have an emergency, do not hesitate to contact us by phone:
</p>
<ul class="list-unstyled">
<li><i class="icon-phone"></i> : <span t-field="res_company.phone"/></li>
<li><i class="icon-envelope"></i> : <span t-field="res_company.email"/></li>
</ul>
</div>
<template id="contactus_form_company_name" name="Company Name" inherit_id="website_crm.contactus_form" inherit_option_id="website_crm.contactus_form">
<xpath expr="//div[@name='email_from_container']" position="after">
<div t-attf-class="form-group #{error and 'partner_name' in error and 'has-error' or ''}">
<label class="col-md-3 col-sm-4 control-label" for="partner_name">Your Company</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control" name="partner_name" required="True" t-attf-value="#{partner_name or ''}"/>
</div>
</div>
</xpath>
</template>
<template id="contactus_thanks" name="Contact us" page="True">
<t t-call="website.layout">
<t t-set="title">Contact us -
<t t-raw="res_company.name"></t>
</t>
<div id="wrap">
<div class="oe_structure"/>
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="alert alert-success">
Your message has been sent successfully.
<button type="button" class="close" data-dismiss="alert">&amp;times;</button>
</div>
<h2>Thanks!</h2>
<p>
We will get back to you shortly.
</p><p class="mt64">
If you have an emergency, do not hesitate to contact us by phone:
</p>
<ul class="list-unstyled">
<li><i class="icon-phone"></i> : <span t-field="res_company.phone"/></li>
<li><i class="icon-envelope"></i> : <span t-field="res_company.email"/></li>
</ul>
</div>
<div class="col-md-4">
<t t-call="website.company_description"/>
</div>
</div>
</div>
<div class="oe_structure"/>
</div>
</t>
</template>