[IMP] website_crm: designer can add input type file in form view. All files create an ir.attachment linked with the created lead
bzr revid: chm@openerp.com-20140408144110-4j9aljn2kgjt0adk
This commit is contained in:
parent
dcdf729b9f
commit
0e062e61b2
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import base64
|
||||||
|
|
||||||
from openerp.addons.web import http
|
from openerp.addons.web import http
|
||||||
from openerp.addons.web.http import request
|
from openerp.addons.web.http import request
|
||||||
|
@ -66,10 +67,24 @@ class contactus(http.Controller):
|
||||||
environ.get("HTTP_USER_AGENT"),
|
environ.get("HTTP_USER_AGENT"),
|
||||||
environ.get("HTTP_ACCEPT_LANGUAGE"),
|
environ.get("HTTP_ACCEPT_LANGUAGE"),
|
||||||
environ.get("HTTP_REFERER"))
|
environ.get("HTTP_REFERER"))
|
||||||
for field in kwargs.items():
|
for field_name, field_value in kwargs.items():
|
||||||
post['description'] = "%s\n%s: %s" % (post['description'], field[0], field[1])
|
if not hasattr(field_value, 'filename'):
|
||||||
|
post['description'] = "%s\n%s: %s" % (post['description'], field_name, field_value)
|
||||||
|
|
||||||
|
lead_id = request.registry['crm.lead'].create(request.cr, SUPERUSER_ID, post, request.context)
|
||||||
|
|
||||||
|
for field_name, field_value in kwargs.items():
|
||||||
|
if hasattr(field_value, 'filename'):
|
||||||
|
attachment_value = {
|
||||||
|
'name': field_value.filename,
|
||||||
|
'res_name': field_value.filename,
|
||||||
|
'res_model': 'crm.lead',
|
||||||
|
'res_id': lead_id,
|
||||||
|
'datas': base64.encodestring(field_value.read()),
|
||||||
|
'datas_fname': field_value.filename,
|
||||||
|
}
|
||||||
|
request.registry['ir.attachment'].create(request.cr, SUPERUSER_ID, attachment_value, context=request.context)
|
||||||
|
|
||||||
request.registry['crm.lead'].create(request.cr, SUPERUSER_ID, post, request.context)
|
|
||||||
company = request.website.company_id
|
company = request.website.company_id
|
||||||
values = {
|
values = {
|
||||||
'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 ''),
|
'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 ''),
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<template id="contactus_form" name="Contact Form" inherit_id="website.contactus" inherit_option_id="website.contactus">
|
<template id="contactus_form" name="Contact Form" inherit_id="website.contactus" inherit_option_id="website.contactus">
|
||||||
<xpath expr="//div[@name='mail_button']" position="replace">
|
<xpath expr="//div[@name='mail_button']" position="replace">
|
||||||
<form action="/crm/contactus" method="post" class="form-horizontal mt32" >
|
<form action="/crm/contactus" method="post" class="form-horizontal mt32" enctype="multipart/form-data">
|
||||||
<t t-foreach="kwargs" t-as="kwarg">
|
<t t-foreach="kwargs" t-as="kwarg">
|
||||||
<input type="hidden" t-att-name="kwarg[0]" t-att-value="kwarg[1]"/>
|
<input type="hidden" t-att-name="kwarg[0]" t-att-value="kwarg[1]"/>
|
||||||
</t>
|
</t>
|
||||||
|
|
Loading…
Reference in New Issue