summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchm@openerp.com <>2014-04-08 16:41:10 +0200
committerchm@openerp.com <>2014-04-08 16:41:10 +0200
commit0e062e61b26d2cdbe9016400c968ba6502e6c081 (patch)
tree41085d2494a543307bff14ff7d2112abb3a43370
parentdcdf729b9fb2404ac076aa0cd178df2c27dae0fb (diff)
[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
-rw-r--r--addons/website_crm/controllers/main.py21
-rw-r--r--addons/website_crm/views/website_crm.xml2
2 files changed, 19 insertions, 4 deletions
diff --git a/addons/website_crm/controllers/main.py b/addons/website_crm/controllers/main.py
index c1680ce22ff..163e3ee9793 100644
--- a/addons/website_crm/controllers/main.py
+++ b/addons/website_crm/controllers/main.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+import base64
from openerp.addons.web import http
from openerp.addons.web.http import request
@@ -66,10 +67,24 @@ class contactus(http.Controller):
environ.get("HTTP_USER_AGENT"),
environ.get("HTTP_ACCEPT_LANGUAGE"),
environ.get("HTTP_REFERER"))
- for field in kwargs.items():
- post['description'] = "%s\n%s: %s" % (post['description'], field[0], field[1])
+ for field_name, field_value in kwargs.items():
+ 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
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 ''),
diff --git a/addons/website_crm/views/website_crm.xml b/addons/website_crm/views/website_crm.xml
index a60a2c6843e..a521e155b02 100644
--- a/addons/website_crm/views/website_crm.xml
+++ b/addons/website_crm/views/website_crm.xml
@@ -4,7 +4,7 @@
<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 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">
<input type="hidden" t-att-name="kwarg[0]" t-att-value="kwarg[1]"/>
</t>