Merged
authorHDA (OpenERP) <hda@tinyerp.com>
Tue, 12 Jan 2010 10:48:30 +0000 (16:18 +0530)
committerHDA (OpenERP) <hda@tinyerp.com>
Tue, 12 Jan 2010 10:48:30 +0000 (16:18 +0530)
bzr revid: hda@tinyerp.com-20100112104830-x35l4g08og2gacwo

23 files changed:
1  2 
bin/addons/__init__.py
bin/addons/base/ir/ir.xml
bin/addons/base/ir/ir_model.py
bin/addons/base/ir/ir_rule.py
bin/addons/base/ir/ir_values.py
bin/addons/base/module/module.py
bin/addons/base/res/partner/partner.py
bin/addons/base/res/res_currency.py
bin/addons/base/rng/view.rng
bin/netsvc.py
bin/osv/expression.py
bin/osv/fields.py
bin/osv/orm.py
bin/release.py
bin/report/custom.py
bin/report/render/odt2odt/__init__.py
bin/report/report_sxw.py
bin/service/security.py
bin/service/web_services.py
bin/sql_db.py
bin/tools/config.py
bin/tools/misc.py
bin/tools/translate.py

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
                      <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>
diff --cc bin/netsvc.py
@@@ -1,4 -1,5 +1,5 @@@
+ #!/usr/bin/env python
 -# -*- encoding: utf-8 -*-
 +# -*- coding: utf-8 -*-
  ##############################################################################
  #
  #    OpenERP, Open Source Management Solution
@@@ -145,25 -145,27 +145,24 @@@ class expression(object)
                  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':
Simple merge
diff --cc bin/osv/orm.py
@@@ -380,11 -365,18 +380,19 @@@ class orm_template(object)
                  '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]
@@@ -1918,15 -1773,13 +1927,14 @@@ class orm(orm_template)
                  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
diff --cc bin/release.py
Simple merge
Simple merge
  #    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:
@@@ -358,11 -359,12 +358,14 @@@ class report_sxw(report_rml, preprocess
              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 {})
@@@ -24,19 -25,11 +24,18 @@@ import tool
  
  _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:
@@@ -48,9 -41,11 +47,11 @@@ def check_super(passwd)
      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
@@@ -267,54 -276,62 +277,62 @@@ class db(netsvc.ExportService)
          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
  
diff --cc bin/sql_db.py
Simple merge
@@@ -240,7 -232,10 +242,10 @@@ class configmanager(object)
                  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:
Simple merge
@@@ -195,30 -191,16 +199,29 @@@ class TinyPoFile(object)
                  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:])