Git Product home page Git Product logo

afewords_base's People

Contributors

deju avatar earthson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

afewords_base's Issues

关于属性获取

刚才看到了这段代码。实际上属性的生成我可以用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)))

撤销attr_template支持

思考之后,我打算撤销对Page对象的attr_template支持。字典由db_property返回。
此外,属性命名不必和db_property一致。

但是,尽量抽象出固定的属性集合。比如user的属性集合,尽量共用统一的结构,最好不要超过3个。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.