当前位置: 首页>>代码示例>>Python>>正文


Python User.to_public_json方法代码示例

本文整理汇总了Python中pybossa.model.user.User.to_public_json方法的典型用法代码示例。如果您正苦于以下问题:Python User.to_public_json方法的具体用法?Python User.to_public_json怎么用?Python User.to_public_json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pybossa.model.user.User的用法示例。


在下文中一共展示了User.to_public_json方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: public_get_user_summary

# 需要导入模块: from pybossa.model.user import User [as 别名]
# 或者: from pybossa.model.user.User import to_public_json [as 别名]
def public_get_user_summary(name):
    """Sanitize user summary for public usage"""
    private_user = get_user_summary(name)
    public_user = None
    if private_user is not None:
        u = User()
        public_user = u.to_public_json(data=private_user)
    return public_user
开发者ID:influencerplus123,项目名称:tinybee.ai,代码行数:10,代码来源:users.py

示例2: test_user_public_info_keys

# 需要导入模块: from pybossa.model.user import User [as 别名]
# 或者: from pybossa.model.user.User import to_public_json [as 别名]
    def test_user_public_info_keys(self):
        """Test public info keys works."""
        user = User(
            email_addr="[email protected]",
            name="johndoe",
            fullname="John Doe",
            info=dict(avatar='image.png', container='foldr3', token='security'),
            locale="en")
        public_info_keys = ['avatar', 'container']
        user.set_password("juandiso")
        assert public_info_keys.sort() == user.public_info_keys().sort()

        data = user.to_public_json()
        err_msg = "There are some keys that should not be public"
        assert data.get('info').keys().sort() == public_info_keys.sort(), err_msg
开发者ID:PyBossa,项目名称:pybossa,代码行数:17,代码来源:test_model_user.py

示例3: test_user_public_attributes

# 需要导入模块: from pybossa.model.user import User [as 别名]
# 或者: from pybossa.model.user.User import to_public_json [as 别名]
    def test_user_public_attributes(self):
        """Test public attributes works."""
        user = User(
            email_addr="[email protected]",
            name="johndoe",
            pro=1,
            fullname="John Doe",
            locale="en")
        public_attributes = ['created', 'name', 'fullname', 'locale', 'info',
                             'task_runs', 'registered_ago', 'rank', 'score']

        user.set_password("juandiso")
        assert public_attributes.sort() == user.public_attributes().sort()
        data = user.to_public_json()
        err_msg = "There are some keys that should not be public"
        assert data.keys().sort() == public_attributes.sort(), err_msg
        all_attributes = user.dictize().keys()
        s = set(public_attributes)
        private_attributes = [x for x in all_attributes if x not in s]
        for attr in private_attributes:
            err_msg = "This attribute should be private %s" % attr
            assert data.get(attr) is None, err_msg
开发者ID:PyBossa,项目名称:pybossa,代码行数:24,代码来源:test_model_user.py

示例4: get_users_page

# 需要导入模块: from pybossa.model.user import User [as 别名]
# 或者: from pybossa.model.user.User import to_public_json [as 别名]
def get_users_page(page, per_page=24):
    """Return users with a paginator."""
    offset = (page - 1) * per_page
    sql = text('''SELECT "user".id, "user".name,
               "user".fullname, "user".email_addr,
               "user".created, "user".info, COUNT(task_run.id) AS task_runs
               FROM task_run, "user"
               WHERE "user".id=task_run.user_id GROUP BY "user".id
               ORDER BY "user".created DESC LIMIT :limit OFFSET :offset''')
    results = session.execute(sql, dict(limit=per_page, offset=offset))
    accounts = []

    u = User()

    for row in results:
        user = dict(id=row.id, name=row.name, fullname=row.fullname,
                    email_addr=row.email_addr, created=row.created,
                    task_runs=row.task_runs, info=row.info,
                    registered_ago=pretty_date(row.created))
        tmp = u.to_public_json(data=user)
        accounts.append(tmp)
    return accounts
开发者ID:influencerplus123,项目名称:tinybee.ai,代码行数:24,代码来源:users.py


注:本文中的pybossa.model.user.User.to_public_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。