diff --git a/bin/addons/base/base_data.xml b/bin/addons/base/base_data.xml
index 9a17e4bc7c7..db74b9b1b1e 100644
--- a/bin/addons/base/base_data.xml
+++ b/bin/addons/base/base_data.xml
@@ -28,6 +28,8 @@
True
+
+
Andorra, Principality of
ad
diff --git a/bin/addons/base/base_update.xml b/bin/addons/base/base_update.xml
index 969b8d49bdd..7432018fd94 100644
--- a/bin/addons/base/base_update.xml
+++ b/bin/addons/base/base_update.xml
@@ -70,34 +70,6 @@
======================
-->
-
- change.user.password
- change.user.password
- form
-
-
-
-
-
-
- Change Password
- ir.actions.act_window
- change.user.password
- form
- form
- new
-
-
res.users.form.modif
res.users
@@ -119,8 +91,6 @@
-
-
@@ -139,7 +109,7 @@
-
+
diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py
index 4dfe39a7762..5cd65a65d25 100644
--- a/bin/addons/base/ir/ir_model.py
+++ b/bin/addons/base/ir/ir_model.py
@@ -19,14 +19,16 @@
#
##############################################################################
import logging
+import re
+import time
from operator import itemgetter
+
from osv import fields,osv
-import ir, re
+import ir
import netsvc
from osv.orm import except_orm, browse_record
-
-import time
import tools
+from tools.safe_eval import safe_eval as eval
from tools import config
from tools.translate import _
import pooler
@@ -152,21 +154,29 @@ class ir_model_fields(osv.osv):
_description = "Fields"
_columns = {
'name': fields.char('Name', required=True, size=64, select=1),
- 'model': fields.char('Object Name', size=64, required=True, select=1),
- 'relation': fields.char('Object Relation', size=64),
- 'relation_field': fields.char('Relation Field', size=64),
- 'model_id': fields.many2one('ir.model', 'Object ID', required=True, select=True, ondelete='cascade'),
+ 'model': fields.char('Object Name', size=64, required=True, select=1,
+ help="The technical name of the model this field belongs to"),
+ 'relation': fields.char('Object Relation', size=64,
+ help="For relationship fields, the technical name of the target model"),
+ 'relation_field': fields.char('Relation Field', size=64,
+ help="For one2many fields, the field on the target model that implement the opposite many2one relationship"),
+ 'model_id': fields.many2one('ir.model', 'Model', required=True, select=True, ondelete='cascade',
+ help="The model this field belongs to"),
'field_description': fields.char('Field Label', required=True, size=256),
'ttype': fields.selection(_get_fields_type, 'Field Type',size=64, required=True),
- 'selection': fields.char('Field Selection',size=128),
+ 'selection': fields.char('Selection Options',size=128, help="List of options for a selection field, "
+ "specified as a Python expression defining a list of (key, label) pairs. "
+ "For example: [('blue','Blue'),('yellow','Yellow')]"),
'required': fields.boolean('Required'),
'readonly': fields.boolean('Readonly'),
- 'select_level': fields.selection([('0','Not Searchable'),('1','Always Searchable'),('2','Advanced Search')],'Searchable', required=True),
- 'translate': fields.boolean('Translate'),
+ 'select_level': fields.selection([('0','Not Searchable'),('1','Always Searchable'),('2','Advanced Search (deprecated)')],'Searchable', required=True),
+ 'translate': fields.boolean('Translate', help="Whether values for this field can be translated (enables the translation mechanism for that field)"),
'size': fields.integer('Size'),
'state': fields.selection([('manual','Custom Field'),('base','Base Field')],'Type', required=True, readonly=True, select=1),
'on_delete': fields.selection([('cascade','Cascade'),('set null','Set NULL')], 'On delete', help='On delete property for many2one fields'),
- 'domain': fields.char('Domain', size=256),
+ 'domain': fields.char('Domain', size=256, help="The optional domain to restrict possible values for relationship fields, "
+ "specified as a Python expression defining a list of triplets. "
+ "For example: [('color','=','red')]"),
'groups': fields.many2many('res.groups', 'ir_model_fields_group_rel', 'field_id', 'group_id', 'Groups'),
'view_load': fields.boolean('View Auto-Load'),
'selectable': fields.boolean('Selectable'),
@@ -174,7 +184,7 @@ class ir_model_fields(osv.osv):
_rec_name='field_description'
_defaults = {
'view_load': lambda *a: 0,
- 'selection': lambda *a: "[]",
+ 'selection': lambda *a: "[('key','label')]",
'domain': lambda *a: "[]",
'name': lambda *a: 'x_',
'state': lambda self,cr,uid,ctx={}: (ctx and ctx.get('manual',False)) and 'manual' or 'base',
@@ -185,6 +195,25 @@ class ir_model_fields(osv.osv):
'selectable': lambda *a: 1,
}
_order = "name"
+
+ def _check_selection(self, cr, uid, ids, context=None):
+ selection_field = self.browse(cr, uid, ids[0], context=context)
+ try:
+ selection_list = eval(selection_field.selection)
+ except Exception:
+ logging.getLogger('ir.model').error('Invalid selection list definition for fields.selection %s', selection_field.name , exc_info=True)
+ return False
+ if not (isinstance(selection_list, list) and selection_list):
+ return False
+ for selection_item in selection_list:
+ if not (isinstance(selection_item, (tuple,list)) and len(selection_item) == 2):
+ return False
+ return True
+
+ _constraints = [
+ (_check_selection, "Wrong list of values specified for a field of type selection, it should be written as [('key','value')]", ['selection'])
+ ]
+
def _size_gt_zero_msg(self, cr, user, ids, context=None):
return _('Size of the field can never be less than 1 !')
diff --git a/bin/addons/base/ir/ir_ui_menu.py b/bin/addons/base/ir/ir_ui_menu.py
index 08725fbb9cb..ef9f7f28308 100644
--- a/bin/addons/base/ir/ir_ui_menu.py
+++ b/bin/addons/base/ir/ir_ui_menu.py
@@ -257,12 +257,14 @@ class ir_ui_menu(osv.osv):
def read_image(self, path):
path_info = path.split(',')
icon_path = addons.get_module_resource(path_info[0],path_info[1])
- icon_file = tools.file_open(icon_path,'rb')
- try:
- icon = icon_file.read()
- return base64.encodestring(icon)
- finally:
- icon_file.close()
+ icon_image = False
+ if icon_path:
+ try:
+ icon_file = tools.file_open(icon_path,'rb')
+ icon_image = base64.encodestring(icon_file.read())
+ finally:
+ icon_file.close()
+ return icon_image
def _get_image_icon(self, cr, uid, ids, name, args, context=None):
res = {}
@@ -304,7 +306,7 @@ class ir_ui_menu(osv.osv):
('ir.actions.server', 'ir.actions.server'),
]),
}
-
+
def _rec_message(self, cr, uid, ids, context=None):
return _('Error ! You can not create recursive Menu.')
diff --git a/bin/addons/base/res/partner/partner.py b/bin/addons/base/res/partner/partner.py
index 3aed1c50aef..8a6a6197ab3 100644
--- a/bin/addons/base/res/partner/partner.py
+++ b/bin/addons/base/res/partner/partner.py
@@ -138,7 +138,7 @@ class res_partner(osv.osv):
'email': fields.related('address', 'email', type='char', size=240, string='E-mail'),
'company_id': fields.many2one('res.company', 'Company', select=1),
}
-
+
def _default_category(self, cr, uid, context={}):
if 'category_id' in context and context['category_id']:
return [context['category_id']]
diff --git a/bin/addons/base/res/res_lang.py b/bin/addons/base/res/res_lang.py
index 64bdb948d14..f05c174a62a 100644
--- a/bin/addons/base/res/res_lang.py
+++ b/bin/addons/base/res/res_lang.py
@@ -24,10 +24,66 @@ from locale import localeconv
import tools
from tools.safe_eval import safe_eval as eval
from tools.translate import _
+import locale
+import logging
+
class lang(osv.osv):
_name = "res.lang"
_description = "Languages"
+ def install_lang(self, cr, uid, **args):
+ lang_ids = self.search(cr, uid, [('code','=', tools.config.get('lang'))])
+ values_obj = self.pool.get('ir.values')
+ if not lang_ids:
+ lang_id = self.load_lang(cr, uid, tools.config.get('lang'))
+ default_value = values_obj.get(cr, uid, 'default', False, 'res.partner')
+ if not default_value:
+ values_obj.set(cr, uid, 'default', False, 'lang', ['res.partner'], tools.config.get('lang'))
+ return True
+
+ def load_lang(self, cr, uid, lang, lang_name=None):
+ # create the language with locale information
+ fail = True
+ logger = logging.getLogger('i18n')
+ iso_lang = tools.get_iso_codes(lang)
+ for ln in tools.get_locales(lang):
+ try:
+ locale.setlocale(locale.LC_ALL, str(ln))
+ fail = False
+ break
+ except locale.Error:
+ continue
+ if fail:
+ lc = locale.getdefaultlocale()[0]
+ msg = 'Unable to get information for locale %s. Information from the default locale (%s) have been used.'
+ logger.warning(msg, lang, lc)
+
+ if not lang_name:
+ lang_name = tools.get_languages().get(lang, lang)
+
+
+ def fix_xa0(s):
+ if s == '\xa0':
+ return '\xc2\xa0'
+ return s
+
+ lang_info = {
+ 'code': lang,
+ 'iso_code': iso_lang,
+ 'name': lang_name,
+ 'translatable': 1,
+ 'date_format' : str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')),
+ 'time_format' : str(locale.nl_langinfo(locale.T_FMT)),
+ 'decimal_point' : fix_xa0(str(locale.localeconv()['decimal_point'])),
+ 'thousands_sep' : fix_xa0(str(locale.localeconv()['thousands_sep'])),
+ }
+ lang_id = False
+ try:
+ lang_id = self.create(cr, uid, lang_info)
+ finally:
+ tools.resetlocale()
+ return lang_id
+
def _get_default_date_format(self,cursor,user,context={}):
return '%m/%d/%Y'
@@ -69,7 +125,7 @@ class lang(osv.osv):
thousands_sep = lang_obj.thousands_sep or conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
decimal_point = lang_obj.decimal_point
grouping = lang_obj.grouping
- return (grouping, thousands_sep, decimal_point)
+ return (grouping, thousands_sep, decimal_point)
def write(self, cr, uid, ids, vals, context=None):
for lang_id in ids :
@@ -95,19 +151,19 @@ class lang(osv.osv):
def _group(self, cr, uid, ids, s, monetary=False, grouping=False, thousands_sep=''):
grouping = eval(grouping)
-
+
if not grouping:
return (s, 0)
result = ""
seps = 0
spaces = ""
-
+
if s[-1] == ' ':
sp = s.find(' ')
spaces = s[sp:]
s = s[:sp]
-
+
while s and grouping:
# if grouping is -1, we are done
if grouping[0] == -1:
@@ -139,7 +195,7 @@ class lang(osv.osv):
if percent[0] != '%':
raise ValueError("format() must be given exactly one %char format specifier")
- lang_grouping, thousands_sep, decimal_point = self._lang_data_get(cr, uid, ids[0], monetary)
+ lang_grouping, thousands_sep, decimal_point = self._lang_data_get(cr, uid, ids[0], monetary)
formatted = percent % value
# floats and decimal ints need special action!
diff --git a/bin/addons/base/res/res_user.py b/bin/addons/base/res/res_user.py
index c8aa83f3253..0356aeac4d2 100644
--- a/bin/addons/base/res/res_user.py
+++ b/bin/addons/base/res/res_user.py
@@ -194,6 +194,16 @@ class users(osv.osv):
self.write(cr, uid, ids, {'address_id': address_id}, context)
return True
+ def _set_new_password(self, cr, uid, id, name, value, args, context=None):
+ if not value:
+ raise osv.except_osv(_('Empty new password'), _('Please provide a new password value'))
+ if uid == id:
+ # To change their own password users must use the client-specific change password wizard,
+ # so that the new password is immediately used for further RPC requests, otherwise the user
+ # will face unexpected 'Access Denied' exceptions.
+ raise osv.except_osv(_('Operation Canceled'), _('Please use the change password wizard (in User Preferences or User menu) to change your own password.'))
+ self.write(cr, uid, id, {'password': value})
+
_columns = {
'name': fields.char('User Name', size=64, required=True, select=True,
help="The new user's real name, used for searching"
@@ -201,6 +211,10 @@ class users(osv.osv):
'login': fields.char('Login', size=64, required=True,
help="Used to log into the system"),
'password': fields.char('Password', size=64, invisible=True, help="Keep empty if you don't want the user to be able to connect on the system."),
+ 'new_password': fields.function(lambda *a:'', method=True, type='char', size=64,
+ fnct_inv=_set_new_password,
+ string='Change password', help="Only specify a value if you want to change the user password. "
+ "This user will have to logout and login again!"),
'email': fields.char('E-mail', size=64,
help='If an email is provided, the user will be sent a message '
'welcoming him.\n\nWarning: if "email_from" and "smtp_server"'
@@ -452,7 +466,7 @@ class users(osv.osv):
(int(uid), passwd, True))
res = cr.fetchone()[0]
if not bool(res):
- raise security.ExceptionNoTb('AccessDenied')
+ raise security.ExceptionNoTb('Accessenied')
if res:
if self._uid_cache.has_key(db):
ulist = self._uid_cache[db]
@@ -476,6 +490,18 @@ class users(osv.osv):
finally:
cr.close()
+ def change_password(self, cr, uid, old_passwd, new_passwd):
+ """Change current user password. Old password must be provided explicitly
+ to prevent hijacking an existing user session, or for cases where the cleartext
+ password is not used to authenticate requests.
+
+ :return: True
+ :raise: security.ExceptionNoTb when old password is wrong
+ """
+ if self.check(cr.dbname, uid, old_passwd):
+ self.write(cr, uid, uid, {'password': new_passwd})
+ return True
+
users()
class config_users(osv.osv_memory):
@@ -574,39 +600,4 @@ class res_config_view(osv.osv_memory):
res_config_view()
-class change_user_password(osv.osv_memory):
- _name = 'change.user.password'
- _columns = {
- 'current_password':fields.char('Current Password', size=64, required=True, help="Enter your current password."),
- 'new_password': fields.char('New Password', size=64, required=True, help="Enter the new password."),
- 'confirm_password': fields.char('Confirm Password', size=64, required=True, help="Enter the new password again for confirmation."),
- }
- _defaults={
- 'current_password' : '',
- 'new_password' : '',
- 'confirm_password' : '',
- }
-
- def change_password(self, cr, uid, ids, context=None):
- for form_id in ids:
- password_rec = self.browse(cr, uid, form_id, context)
- if password_rec.new_password != password_rec.confirm_password:
- raise osv.except_osv(_('Error !'), _('The new and confirmation passwords do not match, please double-check them.'))
-
- # Validate current password without reading it from database,
- # as it could be stored differently (LDAP, encrypted/hashed, etc.)
- is_correct_password = False
- try:
- user_obj = self.pool.get('res.users')
- is_correct_password = user_obj.check(cr.dbname, uid, password_rec.current_password)
- except Exception:
- pass
- if not is_correct_password:
- raise osv.except_osv(_('Error !'), _('The current password does not match, please double-check it.'))
- user_obj.write(cr, uid, [uid], {'password': password_rec.new_password}, context=context)
- return {}
-
-change_user_password()
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/bin/osv/fields.py b/bin/osv/fields.py
index befe09ba75e..6f720ea4669 100644
--- a/bin/osv/fields.py
+++ b/bin/osv/fields.py
@@ -553,7 +553,7 @@ class many2many(_column):
DeprecationWarning, stacklevel=2)
obj = obj.pool.get(self._obj)
- # static domains are lists, and are evaluated both here and on client-side, while string
+ # static domains are lists, and are evaluated both here and on client-side, while string
# domains supposed by dynamic and evaluated on client-side only (thus ignored here)
# FIXME: make this distinction explicit in API!
domain = isinstance(self._domain, list) and self._domain or []
@@ -1049,7 +1049,8 @@ class property(function):
brs = properties.browse(cr, uid, nids, context=context)
for prop in brs:
value = properties.get_by_record(cr, uid, prop, context=context)
- res[prop.res_id.id][prop.fields_id.name] = value or False
+ record_exists = obj.pool.get(value._name).exists(cr, uid, value.id)
+ res[prop.res_id.id][prop.fields_id.name] = (record_exists and value) and value or False
if value and (prop.type == 'many2one'):
replaces.setdefault(value._name, {})
replaces[value._name][value.id] = True
diff --git a/bin/service/web_services.py b/bin/service/web_services.py
index 3c21202780a..b6bef3c7859 100644
--- a/bin/service/web_services.py
+++ b/bin/service/web_services.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
-#
+#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL ().
#
@@ -15,7 +15,7 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
+# along with this program. If not, see .
#
##############################################################################
@@ -50,8 +50,8 @@ class db(netsvc.ExportService):
self._pg_psw_env_var_is_set = False # on win32, pg_dump need the PGPASSWORD env var
def dispatch(self, method, auth, params):
- if method in [ 'create', 'get_progress', 'drop', 'dump',
- 'restore', 'rename',
+ if method in [ 'create', 'get_progress', 'drop', 'dump',
+ 'restore', 'rename',
'change_admin_password', 'migrate_databases' ]:
passwd = params[0]
params = params[1:]
@@ -64,7 +64,7 @@ class db(netsvc.ExportService):
raise KeyError("Method not found: %s" % method)
fn = getattr(self, 'exp_'+method)
return fn(*params)
-
+
def new_dispatch(self,method,auth,params):
pass
def _create_empty_database(self, name):
@@ -93,6 +93,7 @@ class db(netsvc.ExportService):
serv.actions[id]['progress'] = 0
cr = sql_db.db_connect(db_name).cursor()
tools.init_db(cr)
+ tools.config['lang'] = lang
cr.commit()
cr.close()
cr = None
@@ -392,7 +393,7 @@ class common(_ObjectService):
security.check_super(passwd)
else:
raise Exception("Method not found: %s" % method)
-
+
fn = getattr(self, 'exp_'+method)
return fn(*params)
@@ -568,7 +569,7 @@ GNU Public Licence.
def exp_check_connectivity(self):
return bool(sql_db.db_connect('template1'))
-
+
def exp_get_os_time(self):
return os.times()
@@ -598,7 +599,7 @@ class objects_proxy(netsvc.ExportService):
res = fn(db, uid, *params)
return res
-
+
def new_dispatch(self,method,auth,params):
pass
@@ -634,7 +635,7 @@ class wizard(netsvc.ExportService):
fn = getattr(self, 'exp_'+method)
res = fn(db, uid, *params)
return res
-
+
def new_dispatch(self,method,auth,params):
pass
@@ -697,7 +698,7 @@ class report_spool(netsvc.ExportService):
res = fn(db, uid, *params)
return res
-
+
def new_dispatch(self,method,auth,params):
pass
@@ -728,7 +729,7 @@ class report_spool(netsvc.ExportService):
self._reports[id]['format'] = format
self._reports[id]['state'] = True
except Exception, exception:
-
+
tb = sys.exc_info()
tb_s = "".join(traceback.format_exception(*tb))
logger = netsvc.Logger()
diff --git a/bin/tools/translate.py b/bin/tools/translate.py
index c1c09140d0a..3b0b0f1173c 100644
--- a/bin/tools/translate.py
+++ b/bin/tools/translate.py
@@ -347,7 +347,7 @@ class TinyPoFile(object):
if name is None:
if not fuzzy:
- self.warn('Missing "#:" formated comment at line %d for the following source:\n\t%s',
+ self.warn('Missing "#:" formated comment at line %d for the following source:\n\t%s',
self.cur_line(), source[:30])
return self.next()
return type, name, res_id, source, trad
@@ -541,9 +541,9 @@ def trans_generate(lang, modules, dbname=None):
query = 'SELECT name, model, res_id, module' \
' FROM ir_model_data'
-
- query_models = """SELECT m.id, m.model, imd.module
- FROM ir_model AS m, ir_model_data AS imd
+
+ query_models = """SELECT m.id, m.model, imd.module
+ FROM ir_model AS m, ir_model_data AS imd
WHERE m.id = imd.res_id AND imd.model = 'ir.model' """
if 'all_installed' in modules:
@@ -869,42 +869,7 @@ def trans_load_data(db_name, fileobj, fileformat, lang, lang_name=None, verbose=
if not ids:
# lets create the language with locale information
- fail = True
- for ln in get_locales(lang):
- try:
- locale.setlocale(locale.LC_ALL, str(ln))
- fail = False
- break
- except locale.Error:
- continue
- if fail:
- lc = locale.getdefaultlocale()[0]
- msg = 'Unable to get information for locale %s. Information from the default locale (%s) have been used.'
- logger.warning(msg, lang, lc)
-
- if not lang_name:
- lang_name = tools.get_languages().get(lang, lang)
-
- def fix_xa0(s):
- if s == '\xa0':
- return '\xc2\xa0'
- return s
-
- lang_info = {
- 'code': lang,
- 'iso_code': iso_lang,
- 'name': lang_name,
- 'translatable': 1,
- 'date_format' : str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')),
- 'time_format' : str(locale.nl_langinfo(locale.T_FMT)),
- 'decimal_point' : fix_xa0(str(locale.localeconv()['decimal_point'])),
- 'thousands_sep' : fix_xa0(str(locale.localeconv()['thousands_sep'])),
- }
-
- try:
- lang_obj.create(cr, uid, lang_info)
- finally:
- resetlocale()
+ lang_obj.load_lang(cr, 1, lang=lang, lang_name=lang_name)
# now, the serious things: we read the language file