main.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import openerp.http as http
  2. from openerp.http import request
  3. import logging
  4. _logger = logging.getLogger(__name__)
  5. import werkzeug
  6. import base64
  7. class MyController(http.Controller):
  8. @http.route('/form/thankyou', type="http", auth="public", website=True)
  9. def ehtml_thanks(self, **kw):
  10. return http.request.render('entity_html_form.ehtml_thank_you', {})
  11. @http.route('/form/myinsert',type="http", auth="public")
  12. def my_insert(self, **kwargs):
  13. values = {}
  14. for field_name, field_value in kwargs.items():
  15. values[field_name] = field_value
  16. #the referral string is what the campaign looks for
  17. secure_values = {}
  18. history_values = {}
  19. ref_url = http.request.httprequest.headers['Referer']
  20. entity_form = http.request.env['ehtml.formgen'].sudo().browse(int(values['form_id']))
  21. new_history = http.request.env['ehtml.history'].sudo().create({'ref_url':ref_url, 'html_id': entity_form.id})
  22. #populate an array which has ONLY the fields that are in the form (prevent injection)
  23. for fi in entity_form.fields_ids:
  24. if fi.field_id.ttype == "binary":
  25. secure_values[fi.field_id.name] = base64.encodestring(values[fi.html_name].read() )
  26. else:
  27. secure_values[fi.field_id.name] = values[fi.html_name]
  28. new_history.insert_data.sudo().create({'html_id': new_history.id, 'field_id':fi.field_id.id, 'insert_value':values[fi.html_name]})
  29. #default values
  30. for df in entity_form.defaults_values:
  31. secure_values[df.field_id.name] = df.default_value
  32. new_history.insert_data.sudo().create({'html_id': new_history.id, 'field_id':df.field_id.id, 'insert_value':df.default_value})
  33. new_record = http.request.env[entity_form.model_id.model].sudo().create(secure_values)
  34. new_history.record_id = entity_form.id
  35. return werkzeug.utils.redirect(entity_form.return_url)