Python odoo.http.request.env() Examples
The following are 30
code examples of odoo.http.request.env().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
odoo.http.request
, or try the search function
.
Example #1
Source File: timetable.py From -Odoo--- with GNU General Public License v3.0 | 6 votes |
def get_timetable(self,sub_domain,uid=False,student_ids=False,**kwargs): user_id = uid try: if not user_id: return self.res_err(300) ret, entry = self._check_domain(sub_domain) if ret: return ret user = request.env['wxxcx.user'].sudo().browse(int(user_id)) if not user or not user.partner_id : return self.res_err(404) except Exception as e: _logger.exception(e) return self.res_err(-1,e.message)
Example #2
Source File: wechat_user.py From wechat_mall with MIT License | 6 votes |
def get(self, sub_domain, token=None, **kwargs): try: user = request.env['res.users'].sudo().search([('sub_domain', '=', sub_domain)]) if not user: return request.make_response(json.dumps({'code': 404, 'msg': error_code[404]})) if not token: return request.make_response(json.dumps({'code': 300, 'msg': error_code[300].format('token')})) access_token = request.env(user=user.id)['wechat_mall.access_token'].search([ ('token', '=', token), ('create_uid', '=', user.id) ]) if not access_token: return request.make_response(json.dumps({'code': 901, 'msg': error_code[901]})) return request.make_response(json.dumps({'code': 0, 'msg': 'success'})) except Exception as e: _logger.exception(e) return request.make_response(json.dumps({'code': -1, 'msg': error_code[-1], 'data': e.message}))
Example #3
Source File: user.py From -Odoo--- with GNU General Public License v3.0 | 6 votes |
def check_token(self, sub_domain, token=None, **kwargs): try: ret, entry = self._check_domain(sub_domain) if ret:return ret if not token: return self.res_err(300) access_token = request.env(user=1)['wxapp.access_token'].search([ ('token', '=', token), ]) if not access_token: return self.res_err(901) return self.res_ok() except Exception as e: _logger.exception(e) return self.res_err(-1, e.message)
Example #4
Source File: main.py From Odoo-11-Development-Coobook-Second-Edition with MIT License | 6 votes |
def books(self): records = request.env['library.book'].sudo().search([]) result = '<html><body><table><tr><td>' result += '</td></tr><tr><td>'.join(records.mapped('name')) result += '</td></tr></table></body></html>' # return request.make_response( # result, [ # ('Last-modified', email.utils.formatdate( # ( # fields.Datetime.from_string( # request.env['library.book'].sudo() # .search([], order='write_date desc', limit=1) # .write_date) - # datetime.datetime(1970, 1, 1) # ).total_seconds(), # usegmt=True)), # ]) return result # test this with # curl -i -X POST -H "Content-Type: application/json" -d {} $URL
Example #5
Source File: base.py From -Odoo--- with GNU General Public License v3.0 | 6 votes |
def _check_user(self, sub_domain, token): user = request.env['wxxcx.config'].sudo().search([('sub_domain', '=', sub_domain)]) if not user: return self.res_err(404), None, user if not token: return self.res_err(300), None, user access_token = request.env(user=1)['wxxcx.access_token'].search([ ('token', '=', token), #('create_uid', '=', user.id) ]) if not access_token: return self.res_err(901), None, user wechat_user = request.env(user=1)['wxxcx.user'].search([ ('open_id', '=', access_token.open_id), #('create_uid', '=', user.id) ]) if not wechat_user: return self.res_err(10000), None, user return None, wechat_user, user
Example #6
Source File: main.py From Odoo-11-Development-Coobook-Second-Edition with MIT License | 6 votes |
def all_books_mark_mine(self): records = request.env['library.book'].sudo().search([]) result = '<html><body><table>' for record in records: result += '<tr>' if record.author_ids & request.env.user.partner_id: result += '<th>' else: result += '<td>' result += record.name if record.author_ids & request.env.user.partner_id: result += '</th>' else: result += '</td>' result += '</tr>' result += '</table></body></html>' return result
Example #7
Source File: course_sale.py From -Odoo--- with GNU General Public License v3.0 | 6 votes |
def list(self, sub_domain, categoryId=False, nameLike=False, **kwargs): category_id = categoryId try: ret, entry = self._check_domain(sub_domain) if ret: return ret domain = [('wxxcx_published', '=', True)] if category_id: cate_ids = [int(category_id)] + request.env['wxxcx.course.category'].sudo().browse( int(category_id)).child_ids.ids domain.append(('wxxcx_category_id', 'in', cate_ids)) if nameLike: domain.append(('name', 'ilike', nameLike)) course_list = request.env['course.template'].sudo().search(domain) if not course_list: return self.res_err(404) return self.res_ok([self._course_basic_dict(each_goods) for each_goods in course_list]) except Exception as e: _logger.exception(e) return self.res_err(-1, e.message)
Example #8
Source File: order.py From wechat_mall with MIT License | 5 votes |
def get(self, sub_domain, token=None, order_id=None, reputation=2, **kwargs): try: user = request.env['res.users'].sudo().search([('sub_domain', '=', sub_domain)]) if not user: return request.make_response(json.dumps({'code': 404, 'msg': error_code[404]})) if not token: return request.make_response(json.dumps({'code': 300, 'msg': error_code[300].format('token')})) if not order_id: return request.make_response(json.dumps({'code': 300, 'msg': error_code[300].format('order_id')})) access_token = request.env(user=user.id)['wechat_mall.access_token'].search([ ('token', '=', token), ('create_uid', '=', user.id) ]) if not access_token: return request.make_response(json.dumps({'code': 901, 'msg': error_code[901]})) wechat_user = request.env(user=user.id)['wechat_mall.user'].search([ ('open_id', '=', access_token.open_id), ('create_uid', '=', user.id) ]) if not wechat_user: return request.make_response(json.dumps({'code': 10000, 'msg': error_code[10000]})) order = wechat_user.order_ids.filtered(lambda r: r.id == int(order_id)) if not order: return request.make_response(json.dumps({'code': 404, 'msg': error_code[404]})) order.write({'status': 'completed'}) return request.make_response(json.dumps({'code': 0, 'msg': 'success'})) except Exception as e: _logger.exception(e) return request.make_response(json.dumps({'code': -1, 'msg': error_code[-1], 'data': e.message}))
Example #9
Source File: main.py From Odoo-10-Development-Essentials with MIT License | 5 votes |
def index(self, **kwargs): """ Todo list page """ TodoTask = request.env['todo.task'] tasks = TodoTask.search([]) return request.render( 'todo_website.index', {'tasks': tasks})
Example #10
Source File: main.py From Odoo-11-Development-Coobook-Second-Edition with MIT License | 5 votes |
def books_json(self): records = request.env['library.book'].sudo().search([]) return records.read(['name'])
Example #11
Source File: main.py From Odoo-11-Development-Coobook-Second-Edition with MIT License | 5 votes |
def all_books_mine(self): records = request.env['library.book'].search([ ('author_ids', 'in', request.env.user.partner_id.ids), ]) result = '<html><body><table><tr><td>' result += '</td></tr><tr><td>'.join(records.mapped('name')) result += '</td></tr></table></body></html>' return result
Example #12
Source File: main.py From Odoo-11-Development-Coobook-Second-Edition with MIT License | 5 votes |
def all_books(self): records = request.env['library.book'].sudo().search([]) result = '<html><body><table><tr><td>' result += '</td></tr><tr><td>'.join(records.mapped('name')) result += '</td></tr></table></body></html>' return result
Example #13
Source File: main.py From Odoo-11-Development-Essentials-Third-Edition with MIT License | 5 votes |
def add(self, **kwargs): """ Form to add a new Todo Task """ users = request.env['res.users'].search([]) return request.render( 'todo_website.add', {'users': users})
Example #14
Source File: main.py From odoo-dingtalk-connector with GNU General Public License v3.0 | 5 votes |
def qrcode(self, **kw): """ 钉钉扫码登陆页面 """ config = request.env['ir.config_parameter'].sudo() data = { 'app_id': config.get_param('dingtalk_sns_app_id'), 'redirect_url': request.httprequest.host_url + 'dingtalk/auth' } return request.render('dingtalk_connector.qrcode_login', data)
Example #15
Source File: main.py From odoo-dingtalk-connector with GNU General Public License v3.0 | 5 votes |
def sign_in(self, **kw): """ 钉钉免登入口 """ config = request.env['ir.config_parameter'].sudo() data = { 'corp_id': config.get_param('dingtalk_corp_id') } return request.render('dingtalk_connector.sign_in', data)
Example #16
Source File: main.py From Odoo-Python-ERP- with GNU General Public License v3.0 | 5 votes |
def add(self, **kwargs): users = request.env['res.users'].search([]) return request.render( 'bug-website.add', {'users': users})
Example #17
Source File: main.py From odoo-dingtalk-connector with GNU General Public License v3.0 | 5 votes |
def delete_user(self, **kw): """ 钉钉业务回调 接收接口 """ # TODO 接收业务回调数据 def result(): # 获取Odoo配置 config = request.env['ir.config_parameter'].sudo() dingtalkCrypto = DingTalkCrypto(config.get_param('dingtalk_call_back_api_aes_key'), config.get_param('dingtalk_corp_id')) # 加密数据 encrypt = dingtalkCrypto.encrypt('success') # 获取当前时间戳 timestamp = str(int(round(time.time() * 1000))) # 获取随机字符串 nonce = dingtalkCrypto.generateRandomKey(8) # 生成签名 signature = dingtalkCrypto.generateSignature(nonce, timestamp, config.get_param('dingtalk_call_back_api_token'), encrypt) data = { 'msg_signature': signature, 'timeStamp': timestamp, 'nonce': nonce, 'encrypt': encrypt } result = { 'json': True, 'data': data } return result return result()
Example #18
Source File: main.py From odoo-dingtalk-connector with GNU General Public License v3.0 | 5 votes |
def get_dingtalk(self): """ 获取钉钉API服务 """ # 获取配置信息 config = request.env['ir.config_parameter'].sudo() # 返回钉钉API服务 return DingTalk(config.get_param('dingtalk_app_key'), config.get_param('dingtalk_app_secret'), config.get_param('dingtalk_sns_app_id'), config.get_param('dingtalk_sns_app_secret'))
Example #19
Source File: main.py From odoo-dingtalk-connector with GNU General Public License v3.0 | 5 votes |
def auth(self, **kw): """ 钉钉免登认证 """ authCode = kw.get('authCode') code = kw.get('code') dingtalk = self.get_dingtalk() # 检测是通过扫码跳转还是免登跳转 if authCode: # 免登跳转处理 try: user_info = dingtalk.get_user_info_by_auth_code(authCode) user_id = user_info.get('userid') except: return http.local_redirect('/web/login') elif code: # 扫码跳转处理 try: persistent_code_data = dingtalk.get_sns_persistent_code(code) unionid = persistent_code_data.get('unionid') user_id = dingtalk.get_user_id_by_unionid(unionid).get('userid') except: return http.local_redirect('/web/login') # 检查钉钉用户是否存在 if user_id: # 根据钉钉Id判断Odoo用户是否存在,存在即登陆 user = request.env['res.users'].sudo().search([('dingtalk_id', '=', user_id)]) if user: # 添加登陆模式为钉钉免登模式 request.session.dingtalk_auth = True # 生成登陆凭证 request.session.authenticate(request.session.db, user.login, user_id) return http.local_redirect('/web') else: # 自动注册 password = 'dingtalk_id:' + user_id + '|key:' + str(random.randint(100000, 999999)) fail = request.env['res.users'].sudo().create_user_by_dingtalk_id(user_id, password) if not fail: return http.local_redirect('/dingtalk/sign/in') return http.local_redirect('/web/login')
Example #20
Source File: config.py From wechat_mall with MIT License | 5 votes |
def get(self, sub_domain, key=None): try: user = request.env['res.users'].sudo().search([('sub_domain', '=', sub_domain)]) if not user: return request.make_response(json.dumps({'code': 404, 'msg': error_code[404]})) if not key: return request.make_response(json.dumps({'code': 300, 'msg': error_code[300].format('key')})) config = request.env['wechat_mall.config.settings'] value_obj = config.get_config(key, uid=user.id, obj=True) if not value_obj: return request.make_response(json.dumps({'code': 404, 'msg': error_code[404]})) response = request.make_response( headers={ "Content-Type": "json" }, data=json.dumps({ 'code': 0, 'data': { 'creatAt': value_obj.create_date, 'dateType': 0, 'id': value_obj.id, 'key': key, 'remark': '', 'updateAt': value_obj.write_date, 'userId': user.id, 'value': config.get_config(key, uid=user.id) }, 'msg': 'success' }) ) return response except AttributeError: return request.make_response(json.dumps({'code': 404, 'msg': error_code[404]})) except Exception as e: _logger.exception(e) return request.make_response(json.dumps({'code': -1, 'msg': error_code[-1], 'data': e.message}))
Example #21
Source File: main.py From Odoo-11-Development-Essentials-Third-Edition with MIT License | 5 votes |
def index(self, **kwargs): """ Todo list page """ TodoTask = request.env['todo.task'] tasks = TodoTask.search([]) return request.render( 'todo_website.index', {'tasks': tasks})
Example #22
Source File: oauth_login_ext.py From weodoo with MIT License | 5 votes |
def web_login(self, *args, **kw): if request.httprequest.method == 'GET': if request.session.uid and request.params.get('redirect'): return http.redirect_with_hash(request.params.get('redirect')) fm = request.params.get('_fm', None) if not request.session.uid and fm!=None: fragment = base64.urlsafe_b64decode(fm.encode('utf-8')).decode('utf-8') if '_ftype=wo' in fragment: auth_link = self._get_auth_link_wo() return werkzeug.utils.redirect(auth_link, 303) response = super(AuthSignupHome, self).web_login(*args, **kw) from .controllers import QR_DICT qr_id = str(request.session.get('qr_id', ''))#kw.get('qr_id', False) if qr_id and (request.params['login_success'] or request.session.uid): from .controllers import QR_DICT if qr_id in QR_DICT: qr = QR_DICT[qr_id] if 1:#qr['state']=='fail' and qr['openid']: # 绑定当前登录的用户 if request.session.uid: user = request.env["res.users"].sudo().search(([('id','=',request.session.uid)])) else: user = request.env.user user.write({ 'oauth_provider_id': qr['data']['oauth_provider_id'], 'oauth_uid': qr['data']['user_id'], }) request.env.cr.commit() return response
Example #23
Source File: oauth_login_ext.py From weodoo with MIT License | 5 votes |
def list_providers(self): providers = super(AuthSignupHome, self).list_providers() weodoo_provider = request.env(user=1).ref('weodoo.provider_third') for provider in providers: if provider['id']==weodoo_provider.id: provider['auth_link'] = self._get_auth_link_wo(provider) break return providers
Example #24
Source File: oauth_login_ext.py From weodoo with MIT License | 5 votes |
def _get_auth_link_wo(self, provider=None): if not provider: provider = request.env(user=1).ref('weodoo.provider_third') return_url = request.httprequest.url_root + 'auth_oauth/signin3rd' state = self.get_state(provider) self._deal_state_r(state) params = dict( response_type='token', client_id=provider['client_id'], redirect_uri=return_url, scope=provider['scope'], state=json.dumps(state), ) return "%s?%s" % (provider['auth_endpoint'], werkzeug.url_encode(params))
Example #25
Source File: dingtalk.py From odoo-dingtalk with GNU Lesser General Public License v3.0 | 5 votes |
def admin(self, **kw): code = kw.get('code'); if code: corpid = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_corpid') sso_secret = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_sso_secret') if not corpid or not sso_secret: return redirect('/') dt = DingTalkClient(corpid,sso_secret) info = dt.get_sso_userinfo(code) _logger.info(info) return json.dumps(info) else: return redirect('/')
Example #26
Source File: dingtalk.py From odoo-dingtalk with GNU Lesser General Public License v3.0 | 5 votes |
def userinfo(self, **kw): code = kw.get('code'); if code: corpid = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_corpid') corpsecret = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_corpsecret') if not corpid or not corpsecret: return {'status':-1,'msg':'未配置企业corp id和secret'} dt = DingTalkClient(corpid,corpsecret) c = Cache.factory() if not c.get('access_token'): dt.get_access_token() if not request.uid: request.uid = odoo.SUPERUSER_ID try: user = dt.get_user_info(code) employee = request.env['hr.employee'].sudo().search([('dingtalk_userid', '=', user['userid'])]) if len(employee) > 0 and employee.resource_id.user_id: user = employee.resource_id.user_id request.session.authenticate(request.session.db, user.login, user.password_crypt) data = {'status':0,'msg':'登录成功'} else: data = {'status': -1, 'msg': '没有权限,请联系系统管理员设置'} except Exception ,e: _logger.exception("error : %s" % str(e)) data = {'status': -1, 'msg': str(e)} return json.dumps(data)
Example #27
Source File: dingtalk.py From odoo-dingtalk with GNU Lesser General Public License v3.0 | 5 votes |
def home(self): corpid = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_corpid') corpsecret = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_corpsecret') agentid = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_agentid') if not corpid or not corpsecret: return redirect('/') dt = DingTalkClient(corpid,corpsecret) now = int(time.time()); dt.get_access_token() ticket= dt.get_jsapi_ticket() noncestr = 'dingtalk' _logger.info(http.request.httprequest.url) sign = dt.sign(ticket,noncestr,now,http.request.httprequest.url) _logger.info(ticket) config = { 'nonceStr': noncestr, 'agentId' : agentid, 'timeStamp':now, 'corpId':corpid, 'signature' :sign } _logger.info(config) return http.request.render('dingtalk.home',config)
Example #28
Source File: course_sale_category.py From -Odoo--- with GNU General Public License v3.0 | 5 votes |
def all(self,sub_domain): ret,entry = self._check_domain(sub_domain) if ret:return ret try: all_category = request.env['wxxcx.course.category'].sudo().search([ ('is_use','=',True) ]) if not all_category: return self.res_err(404) data=[ { "dateAdd":each_category.create_date, "dateUpdate":each_category.write_date, "icon": each_category.get_main_image() if each_category.icon else '', "id": each_category.id, "isUse": each_category.is_use, "key": each_category.key, "level": each_category.level, "name": each_category.name, "paixu": each_category.sort or 0, "pid": each_category.pid.id if each_category.pid else 0, "type": each_category.category_type, "userId": each_category.create_uid.id } for each_category in all_category ] return self.res_ok(data) except Exception as e: _logger.exception(e) return self.res_err(-1,e.message)
Example #29
Source File: base.py From -Odoo--- with GNU General Public License v3.0 | 5 votes |
def convert_static_link(request, html): base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') return html.replace('src="', 'src="{base_url}'.format(base_url=base_url))
Example #30
Source File: base.py From -Odoo--- with GNU General Public License v3.0 | 5 votes |
def _check_domain(self, sub_domain): wxxcx_entry = request.env['wxxcx.config'].sudo().search([('sub_domain', '=', sub_domain)]) if not wxxcx_entry: return self.res_err(404), None return None, wxxcx_entry