Source code for odoo_xmlrpc_twisted.functions.create_activatetoken
"""During the activation of a userset the "activate" fields in the "res.users" table."""importosimportconfigparserimportsecretsfromdatetimeimportdatetime,timedelta# call the function "get_settings_odoo" to get the parameters# for the logging of the model on the "odoo Webservice API"try:from.get_settings_odooimportget_settings_odooexceptImportError:fromget_settings_odooimportget_settings_odooresult=get_settings_odoo()db=result[0]uid=result[1]password=result[3]models=result[4]# ------- get parameter from the file "parameter_user.ini" -------# Name and full path of the "ini" filefilename="parameter_user.ini"path_name=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Go up to repo rootconfig_path=os.path.join(path_name,'config')fullpath=os.path.join(config_path,filename)config=configparser.ConfigParser()config.read(fullpath)# Value for max duration time in days of the activate_tokenactivate_token_duration=config.get('create_activatetoken','activate_token_duration')
[docs]defcreate_activatetoken(login):""" Function to set during user activation the fields "x_activate_token" and 'x_activate_date' in the database table 'res.users'. """result='False'iflogin!='':# find user in the table 'res.users' with the login = loginusers_id=models.execute_kw(db,uid,password,'res.users','search',[[['login','=',login],['x_activate_complete','=',False],]])# generate a random URL-safe text stringx_activate_token=secrets.token_urlsafe(None)# set the max duration of the token duration_date=datetime.now()+timedelta(days=int(activate_token_duration))x_activate_date=duration_date.strftime("%Y-%m-%d %H:%M:%S")# update the user record with the "activate" valuesforu_idinusers_id:models.execute_kw(db,uid,password,'res.users','write',[[u_id],{'x_activate_token':x_activate_token,'x_activate_date':x_activate_date}])result=x_activate_tokenelse:passreturn(result)