from openerp import models, fields, api from openerp.http import request import logging _logger = logging.getLogger(__name__) import cgi class EhtmlFormgen(models.Model): _name = "ehtml.formgen" def _default_return_url(self): return request.httprequest.host_url + "form/thankyou" name = fields.Char(string="Form Name", required=True) model_id = fields.Many2one('ir.model', string="Model", required=True) fields_ids = fields.One2many('ehtml.fieldentry', 'html_id', string="HTML Fields") output_html = fields.Text(string='Embed Code', readonly=True) required_fields = fields.Text(readonly=True, string="Required Fields") defaults_values = fields.One2many('ehtml.fielddefault', 'html_id', string="Default Values", help="Sets the value of an field before it gets inserted into the database") return_url = fields.Char(string="Return URL", default=_default_return_url, help="The URL that the user will be redirected to after submitting the form", required=True) form_type = fields.Selection([('reg','Plain'),('odoo','Odoo Website')], default="odoo", string="Form Type") @api.onchange('model_id') @api.one def change_model(self): #delete all existing fields for field_entry in self.fields_ids: field_entry.unlink() required_string = "" for model_field in self.env['ir.model.fields'].search([('model_id','=', self.model_id.id),('required','=',True) ]): required_string += model_field.field_description.encode("utf-8") + " (" + model_field.name.encode("utf-8") + ")\n" self.required_fields = required_string @api.one def generate_form(self): if self.form_type == 'reg': self.generate_form_reg() elif self.form_type == 'odoo': self.generate_form_odoo() else: self.generate_form_optimize() @api.one def generate_form_reg(self): html_output = "" html_output += "\n"; html_output += "\n"; html_output += "\n"; html_output += '