'Insert view into database via a query to passtrough validation'

def _insert_view(self, **kw):

    kw.pop('id', None)
    kw.setdefault('mode', ('extension' if kw.get('inherit_id') else 'primary'))
    kw.setdefault('active', True)
    keys = sorted(kw.keys())
    fields = ','.join((('"%s"' % (k.replace('"', '\\"'),)) for k in keys))
    params = ','.join((('%%(%s)s' % (k,)) for k in keys))
    query = ('INSERT    INTO    ir_ui_view(%s)    VALUES(%s)    RETURNING    id' % (fields, params))
    self.cr.execute(query, kw)
    return self.cr.fetchone()[0]
