earthson / afewords_base Goto Github PK
View Code? Open in Web Editor NEWbase development of afewords
base development of afewords
刚才看到了这段代码。实际上属性的生成我可以用db_propertys做。
def user_to_dict(user):
'''
user info to dict:
{
'_id': 'a241212dsf', # unicode, user id
'name': 'afewords', # unicode, user name
'draft': '', # int, user draft's num
'notice': '', # int, user notification's num
'thumb': '', # unicode, user thumb
}
'''
if user is None:
return None
ret = dict()
ret['_id'] = unicode(user._id)
ret['name'] = user.name
ret['thumb'] = user.avatar.tbumb_name
ret['draft'] = len(user.draft_lib.load_all())
ret['notice'] = len([i for i in user.notification_list.load_all() if i is not None and i[1] == False])
return ret
可以用以下的方式代替
to_load = ['id', 'name', 'draft_count', 'notice_count', 'thumb_name']
return dict(zip(to_load, usr.get_propertys(*to_load)))
属性的命名对于user对象来说是全局的,所以不能过于随意。需要的属性列表最好以list的形式给出,传入一个如下的生成器(或者类似的)
def attr_gen(obj, *keys):
return dict(zip(keys, obj.get_propertys(*keys)))
思考之后,我打算撤销对Page对象的attr_template支持。字典由db_property返回。
此外,属性命名不必和db_property一致。
但是,尽量抽象出固定的属性集合。比如user的属性集合,尽量共用统一的结构,最好不要超过3个。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.