<rng:ref name="button"/>
<rng:ref name="group"/>
<rng:ref name="graph"/>
+ <rng:ref name="filter"/>
+ <rng:ref name="notebook"/>
<rng:element name="newline"><rng:empty/></rng:element>
</rng:choice>
</rng:zeroOrMore>
+ #!/usr/bin/env python
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
if field._type in ['many2many','one2many']:
right = field_obj.search(cr, uid, [(fargs[1], operator, right)], context=context)
right1 = table.search(cr, uid, [(fargs[0],'in', right)], context=context)
- self.__exp[i] = ('id', 'in', right1)
-
+ self.__exp[i] = ('id', 'in', right1)
continue
- if field._properties:
+ if field._properties and not field.store:
# this is a function field
- if not field.store:
- if not field._fnct_search:
- # the function field doesn't provide a search function and doesn't store
- # values in the database, so we must ignore it : we generate a dummy leaf
- self.__exp[i] = self.__DUMMY_LEAF
- else:
- subexp = field.search(cr, uid, table, left, [self.__exp[i]], context=context)
- # we assume that the expression is valid
- # we create a dummy leaf for forcing the parsing of the resulting expression
- self.__exp[i] = '&'
- self.__exp.insert(i + 1, self.__DUMMY_LEAF)
- for j, se in enumerate(subexp):
- self.__exp.insert(i + 2 + j, se)
-
- # else, the value of the field is store in the database, so we search on it
+ if not field._fnct_search:
+ # the function field doesn't provide a search function and doesn't store
+ # values in the database, so we must ignore it : we generate a dummy leaf
+ self.__exp[i] = self.__DUMMY_LEAF
+ else:
- subexp = field.search(cr, uid, table, left, [self.__exp[i]])
++ subexp = field.search(cr, uid, table, left, [self.__exp[i]], context=context)
+ # we assume that the expression is valid
+ # we create a dummy leaf for forcing the parsing of the resulting expression
+ self.__exp[i] = '&'
+ self.__exp.insert(i + 1, self.__DUMMY_LEAF)
+ for j, se in enumerate(subexp):
+ self.__exp.insert(i + 2 + j, se)
-
- # else, the value of the field is store in the database, so we search on it
++ # else, the value of the field is store in the database, so we search on it
elif field._type == 'one2many':
'ttype': f._type,
'relation': f._obj or 'NULL',
'view_load': (f.view_load and 1) or 0,
- 'select_level': str(f.select or 0),
+ 'select_level': tools.ustr(f.select or 0),
'readonly':(f.readonly and 1) or 0,
'required':(f.required and 1) or 0,
+ 'selectable' : (f.selectable and 1) or 0,
}
+ # When its a custom field,it does not contain f.select
+ if context.get('field_state','base') == 'manual':
+ if context.get('field_name','') == k:
+ vals['select_level'] = context.get('select','0')
+ #setting value to let the problem NOT occur next time
+ else:
+ vals['select_level'] = cols[k]['select_level']
+
if k not in cols:
cr.execute('select nextval(%s)', ('ir_model_fields_id_seq',))
id = cr.fetchone()[0]
elif isinstance(f, fields.many2many):
cr.execute("SELECT relname FROM pg_class WHERE relkind in ('r','v') AND relname=%s", (f._rel,))
if not cr.dictfetchall():
- #FIXME: Remove this try/except
- try:
- ref = self.pool.get(f._obj)._table
- except AttributeError:
- ref = f._obj.replace('.', '_')
- cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE, "%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE) WITHOUT OIDS' % (f._rel, f._id1, self._table, f._id2, ref))
+ if not self.pool.get(f._obj):
+ raise except_orm('Programming Error', ('There is no reference available for %s') % (f._obj,))
+ ref = self.pool.get(f._obj)._table
+ # ref = f._obj.replace('.', '_')
+ cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE, "%s" INTEGER NOT NULL REFERENCES "%s" ON DELETE CASCADE) WITH OIDS' % (f._rel, f._id1, self._table, f._id2, ref))
cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (f._rel, f._id1, f._rel, f._id1))
cr.execute('CREATE INDEX "%s_%s_index" ON "%s" ("%s")' % (f._rel, f._id2, f._rel, f._id2))
+ cr.execute("COMMENT ON TABLE \"%s\" IS 'RELATION BETWEEN %s AND %s'" % (f._rel, self._table, ref))
cr.commit()
else:
cr.execute("SELECT c.relname,a.attname,a.attlen,a.atttypmod,a.attnotnull,a.atthasdef,t.typname,CASE WHEN a.attlen=-1 THEN a.atttypmod-4 ELSE a.attlen END as size " \
for i in range(0, len(ids), cr.IN_MAX):
sub_ids = ids[i:i+cr.IN_MAX]
if d1:
- cr.execute('SELECT %s FROM \"%s\" WHERE id IN (%s) AND %s ORDER BY %s' % \
- (','.join(fields_pre2 + ['id']), self._table,
- ','.join(['%s' for x in sub_ids]), d1,
- order_by),sub_ids + d2)
+ cr.execute('SELECT %s FROM %s WHERE %s.id = ANY (%%s) AND %s ORDER BY %s' % \
+ (','.join(fields_pre2 + [self._table + '.id']), ','.join(tables), self._table, ' and '.join(d1),
- self._order),[sub_ids,]+d2)
++ order_by),[sub_ids,]+d2)
if not cr.rowcount == len({}.fromkeys(sub_ids)):
raise except_orm(_('AccessError'),
- _('You try to bypass an access rule (Document type: %s).') % self._description)
+ _('You try to bypass an access rule while reading (Document type: %s).') % self._description)
else:
- cr.execute('SELECT %s FROM \"%s\" WHERE id IN (%s) ORDER BY %s' % \
+ cr.execute('SELECT %s FROM \"%s\" WHERE id = ANY (%%s) ORDER BY %s' % \
(','.join(fields_pre2 + ['id']), self._table,
- self._order), (sub_ids,))
+ ','.join(['%s' for x in sub_ids]),
+ order_by), sub_ids)
res.extend(cr.dictfetchall())
else:
res = map(lambda x: {'id': x}, ids)
raise except_orm(_('AccessError'),
_('You try to write on an record that doesn\'t exist ' \
'(Document type: %s).') % self._description)
- if d1:
- cr.execute('update "'+self._table+'" set '+string.join(upd0, ',')+' ' \
- 'where id in ('+ids_str+')'+d1, upd1+ d2)
- else:
- cr.execute('update "'+self._table+'" set '+string.join(upd0, ',')+' ' \
- 'where id in ('+ids_str+')', upd1)
-
+ cr.execute('update '+self._table+' set '+string.join(upd0, ',')+' ' \
+ 'where id in ('+ids_str+')', upd1)
+
if totranslate:
+ # TODO: optimize
for f in direct:
if self._columns[f].translate:
- src_trans = self.pool.get(self._name).read(cr,user,ids,[f])
- self.pool.get('ir.translation')._set_ids(cr, user, self._name+','+f, 'model', context['lang'], ids, vals[f], src_trans[0][f])
+ src_trans = self.pool.get(self._name).read(cr,user,ids,[f])[0][f]
+ if not src_trans:
+ src_trans = vals[f]
+ # Inserting value to DB
+ self.write(cr, user, ids, {f:vals[f]})
+ self.pool.get('ir.translation')._set_ids(cr, user, self._name+','+f, 'model', context['lang'], ids, vals[f], src_trans)
# call the 'set' method of fields which are not classic_write
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# GNU Affero General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
+
- from odt2odt import parseNode
+ from odt2odt import parseNode
++
++# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
fnct = self.create_source_pdf
elif report_type=='html2html':
fnct = self.create_source_html2html
+ elif report_type=='mako2html':
+ fnct = self.create_source_mako2html
else:
- raise Exception('Unknown Report Type: '+report_type)
- return fnct(cr, uid, ids, data, report_xml, context)
+ raise 'Unknown Report Type'
+ fnct_ret = fnct(cr, uid, ids, data, report_xml, context)
+ if not fnct_ret:
+ return (False,False)
+ return fnct_ret
def create_source_odt(self, cr, uid, ids, data, report_xml, context=None):
return self.create_single_odt(cr, uid, ids, data, report_xml, context or {})
_uid_cache = {}
+# When rejecting a password, we need to give as little info as possible
+class ExceptionNoTb(Exception):
+ def __init__(self, msg ):
+ # self.message = msg # No need in Python 2.6
+ self.traceback = ('','','')
+ self.args = (msg, '')
+
def login(db, login, password):
- cr = pooler.get_db(db).cursor()
- if password:
- cr.execute('select id from res_users where login=%s and password=%s and active', (tools.ustr(login), tools.ustr(password)))
- else:
- cr.execute('select id from res_users where login=%s and password is null and active', (tools.ustr(login),))
+ if not password:
+ return False
+ cr = pooler.get_db(db).cursor()
+ cr.execute('select id from res_users where login=%s and password=%s and active', (tools.ustr(login), tools.ustr(password)))
res = cr.fetchone()
cr.close()
if res:
if passwd == tools.config['admin_passwd']:
return True
else:
- raise Exception('AccessDenied')
+ raise ExceptionNoTb('AccessDenied')
def check(db, uid, passwd):
+ if not passwd:
+ return False
cached_pass = _uid_cache.get(db, {}).get(uid)
if (cached_pass is not None) and cached_pass == passwd:
return True
logger = netsvc.Logger()
db = sql_db.db_connect('template1')
- cr = db.cursor()
+ db.lock()
try:
+ cr = db.cursor()
try:
- cr.execute('ALTER DATABASE "%s" RENAME TO "%s"' % (old_name, new_name))
- except Exception, e:
- logger.notifyChannel("web-services", netsvc.LOG_ERROR,
- 'RENAME DB: %s -> %s failed:\n%s' % (old_name, new_name, e))
- raise Exception("Couldn't rename database %s to %s: %s" % (old_name, new_name, e))
- else:
- fs = os.path.join(tools.config['root_path'], 'filestore')
- if os.path.exists(os.path.join(fs, old_name)):
- os.rename(os.path.join(fs, old_name), os.path.join(fs, new_name))
-
- logger.notifyChannel("web-services", netsvc.LOG_INFO,
- 'RENAME DB: %s -> %s' % (old_name, new_name))
+ try:
+ cr.execute('ALTER DATABASE "%s" RENAME TO "%s"' % (old_name, new_name))
+ except Exception, e:
+ logger.notifyChannel("web-services", netsvc.LOG_ERROR,
+ 'RENAME DB: %s -> %s failed:\n%s' % (old_name, new_name, e))
+ raise Exception("Couldn't rename database %s to %s: %s" % (old_name, new_name, e))
+ else:
+ fs = os.path.join(tools.config['root_path'], 'filestore')
+ if os.path.exists(os.path.join(fs, old_name)):
+ os.rename(os.path.join(fs, old_name), os.path.join(fs, new_name))
+
+ logger.notifyChannel("web-services", netsvc.LOG_INFO,
+ 'RENAME DB: %s -> %s' % (old_name, new_name))
+ finally:
+ cr.close()
finally:
- cr.close()
+ db.release()
return True
- def db_exist(self, db_name):
+ def exp_db_exist(self, db_name):
## Not True: in fact, check if connection to database is possible. The database may exists
return bool(sql_db.db_connect(db_name))
- def list(self):
+ def exp_list(self):
+ if not tools.config['list_db']:
+ raise Exception('AccessDenied')
+
db = sql_db.db_connect('template1')
- cr = db.cursor()
+ db.lock()
try:
- list_db = tools.config["list_db"]
- if list_db == 'False':
- return []
+ cr = db.cursor()
try:
- db_user = tools.config["db_user"]
- if not db_user and os.name == 'posix':
- import pwd
- db_user = pwd.getpwuid(os.getuid())[0]
- if not db_user:
- cr.execute("select decode(usename, 'escape') from pg_user where usesysid=(select datdba from pg_database where datname=%s)", (tools.config["db_name"],))
- res = cr.fetchone()
- db_user = res and str(res[0])
- if db_user:
- cr.execute("select decode(datname, 'escape') from pg_database where datdba=(select usesysid from pg_user where usename=%s) and datname not in ('template0', 'template1', 'postgres') order by datname", (db_user,))
- else:
- cr.execute("select decode(datname, 'escape') from pg_database where datname not in('template0', 'template1','postgres') order by datname")
- res = [str(name) for (name,) in cr.fetchall()]
- except:
- res = []
+ try:
+ db_user = tools.config["db_user"]
+ if not db_user and os.name == 'posix':
+ import pwd
+ db_user = pwd.getpwuid(os.getuid())[0]
+ if not db_user:
+ cr.execute("select decode(usename, 'escape') from pg_user where usesysid=(select datdba from pg_database where datname=%s)", (tools.config["db_name"],))
+ res = cr.fetchone()
+ db_user = res and str(res[0])
+ if db_user:
+ cr.execute("select decode(datname, 'escape') from pg_database where datdba=(select usesysid from pg_user where usename=%s) and datname not in ('template0', 'template1', 'postgres') order by datname", (db_user,))
+ else:
+ cr.execute("select decode(datname, 'escape') from pg_database where datname not in('template0', 'template1','postgres') order by datname")
+ res = [str(name) for (name,) in cr.fetchall()]
+ except:
+ res = []
+ finally:
+ cr.close()
finally:
- cr.close()
+ db.release()
res.sort()
return res
self.options[arg] = getattr(opt, arg)
keys = ['language', 'translate_out', 'translate_in', 'debug_mode',
- 'stop_after_init', 'logrotate']
- 'stop_after_init', 'without_demo', 'netrpc', 'xmlrpc', 'syslog', 'list_db']
++ 'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog', 'list_db']
+
+ if hasSSL and not self.options['secure']:
+ keys.append('secure')
for arg in keys:
if getattr(opt, arg) is not None:
if 0 == len(self.lines):
raise StopIteration()
line = self.lines.pop(0).strip()
- if line.startswith('#:'):
- for item in line[2:].strip().split(' '):
- value = item.split(':')
- if len(value) == 3:
- if value[2].endswith(','):
- value[2] = value[2][:-1]
- tmp_tnrs.append( value )
- if line.startswith('#'):
- line = None
+ while line.startswith('#'):
+ if line.startswith('#~ '):
+ break
+ if line.startswith('#:'):
+ if ' ' in line[2:].strip():
+ for lpart in line[2:].strip().split(' '):
+ tmp_tnrs.append(lpart.strip().split(':',2))
+ else:
+ tmp_tnrs.append( line[2:].strip().split(':',2) )
+ elif line.startswith('#,') and (line[2:].strip() == 'fuzzy'):
+ fuzzy = True
+ line = self.lines.pop(0).strip()
+ while not line:
+ # allow empty lines between comments and msgid
+ line = self.lines.pop(0).strip()
+ if line.startswith('#~ '):
+ while line.startswith('#~ ') or not line.strip():
+ if 0 == len(self.lines):
+ raise StopIteration()
+ line = self.lines.pop(0)
+ # This has been a deprecated entry, don't return anything
+ return self.next()
-
if not line.startswith('msgid'):
raise Exception("malformed file: bad line: %s" % line)
source = unquote(line[6:])