6.odoo入门——培训签到课程项目(三)
来源:互联网 发布:类似知否的好文笔小说 编辑:程序博客网 时间:2024/05/17 05:54
第6天:
验证用户名和密码登录:
数据库中的密码是利用了加密之后的字符串存储,我们的思路是利用将待测试密码的加密值和数据库中的加密后的值进行对比验证是否同一个密码,数据库中加密后的密码形如大致如下:
$pbkdf2-sha512$25000$53wvJQRACIHQ2lvrPSfk3A$w6Z0EMLyyHnXSOnqN9HH6mZLG9mxY2srDhyRmk5vurW1CbuitNtEaS9IuyJgObetxZf0xq1KzfdmzSjd87EjCQ
后来发现好像并不是简单的md5加密,本人密码学学的不好,对此并不了解,后来因为我们没有继续用这个数据库,而是自己创建了一个简单的明文存储的数据库来管理用户,这个问题也就不了了之了。所以在此暂时记录下这个问题。
编写后端逻辑的时候遇到一个比较麻烦的问题是不太懂前后端交互的一些细节,所以需要知道前端的JSON用法,其中json是JavaScript对象表示法(JavaScriptObject Notation),推荐一个比较好的参考教程如下:
http://www.runoob.com/json/json-tutorial.html
完成项目的后台部分之后,看看odoo框架中我们用过的一些方法,如果只会使用现成的框架和方法,但是丝毫不理解框架和方法是如何实现的,我觉得这是不会进步的。我们首先看到在所谓的ORM模型中的一条语句:
user_model = http.request.env['ws.training.users']
在后面的用法中,我们知道user_model其实就是一个数据表模型
那么看看
http.request.env['ws.training.users']
在http.py文件中有一行:
_request_stack = werkzeug.local.LocalStack()request = _request_stack()
这个request对象是werkzeug.local.LocalStack()是实例化而来,这个类竟然是个栈?
其实这个看了源代码之后有点蛋疼,涉及到python之中特别的“协程”的概念,(就是在线程等待IO操作做不能干耗CPU时间片,而是进行另外一个协程的任务,这个具体实现就是利用LocalStack类了)
相关资料可以查看:
https://segmentfault.com/a/1190000007663087
http://python.jobbole.com/87738/
user_model = http.request.env['ws.training.users']
这个返回的是一个Model,也就是odoo框架给我们带来的一个直接获取到整个数据表模型的一个模块(在这里模块也就是一个数据表),我们就可以通过以下的语句去搜索相对应的语句:
user = user_model.sudo().search([('user_name', '=', login)])
search中的函数实现是:
其实是调用了Model模块中的_search函数,其源代码如下:
@api.modeldef _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None): """ Private implementation of search() method, allowing specifying the uid to use for the access right check. This is useful for example when filling in the selection list for a drop-down and avoiding access rights errors, by specifying ``access_rights_uid=1`` to bypass access rights check, but not ir.rules! This is ok at the security level because this method is private and not callable through XML-RPC. :param access_rights_uid: optional user ID to use when checking access rights (not for ir.rules, this is only for ir.model.access) :return: a list of record ids or an integer (if count is True) """ self.sudo(access_rights_uid or self._uid).check_access_rights('read') # For transient models, restrict access to the current user, except for the super-user if self.is_transient() and self._log_access and self._uid != SUPERUSER_ID: args = expression.AND(([('create_uid', '=', self._uid)], args or [])) query = self._where_calc(args) self._apply_ir_rules(query, 'read') order_by = self._generate_order_by(order, query) from_clause, where_clause, where_clause_params = query.get_sql() where_str = where_clause and (" WHERE %s" % where_clause) or '' if count: # Ignore order, limit and offset when just counting, they don't make sense and could # hurt performance query_str = 'SELECT count(1) FROM ' + from_clause + where_str self._cr.execute(query_str, where_clause_params) res = self._cr.fetchone() return res[0] limit_str = limit and ' limit %d' % limit or '' offset_str = offset and ' offset %d' % offset or '' query_str = 'SELECT "%s".id FROM ' % self._table + from_clause + where_str + order_by + limit_str + offset_str self._cr.execute(query_str, where_clause_params) res = self._cr.fetchall() # TDE note: with auto_join, we could have several lines about the same result # i.e. a lead with several unread messages; we uniquify the result using # a fast way to do it while preserving order (http://www.peterbe.com/plog/uniqifiers-benchmark) def _uniquify_list(seq): seen = set() return [x for x in seq if x not in seen and not seen.add(x)] return _uniquify_list([x[0] for x in res])
可以看到,其实,odoo给我们带来的便利之一就是将对数据库的操作都给我们封装好对应的api函数,使得我们可以脱离数据库的底层逻辑,直接使用这个ORM模型
为了更加熟悉Python,对Python中用到的东西最好都了解透彻,看到语句:
import sysreload(sys)sys.setdefaultencoding('utf8') #默认编码
不禁带来疑问:sys是个什么库呢,里面大概负责了什么内容,它的一些实现是怎么样的呢
这有一个比较好的讨论 :
http://bbs.bccn.net/thread-330592-1-1.html
据说并没有这样一个源文件,而是内嵌在解释器中,底层是C语言实现,接下来我希望可以仔细地读一下《Python源码剖析》,弄清楚底层是如何实现的。
- 6.odoo入门——培训签到课程项目(三)
- 4.odoo入门——培训签到课程项目(一)
- 4.odoo入门——培训签到课程项目(二),后端逻辑
- 16.odoo入门——初探后台启动过程(三)
- 19.odoo入门——odoo的session
- WordPress入门培训课程
- 10.11.12.odoo入门——杂记
- 20.odoo入门——杂记
- 21.odoo入门——杂记
- 22.odoo入门——工作杂记
- 23.odoo入门——工作杂记
- 24.odoo入门——工作杂记
- 8.odoo入门——jinja2入门(一)
- 7.odoo入门——初探odoo后台启动过程(一)
- 8.odoo入门——初探odoo后台启动过程(二)
- 18.odoo入门——odoo权限控制(一)模型(数据表)级别权限控制
- 13.odoo入门——杂记之git
- 17.odoo入门——初探后台启动过程(四)
- 素因子数GCD
- 新手PID算法的改进(Arduino-PID-Library)
- rpm命令详解
- oracle数据文件大小
- NSOperation
- 6.odoo入门——培训签到课程项目(三)
- Mac查看连接设备命令
- c++ 二进制兼容本质
- MySQL 安装教程
- Step 1:3分钟爱上Processing
- java 集合详解
- JSON数据格式
- vue 学习
- A