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


Python User.insert方法代码示例

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


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

示例1: load

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
def load():
    file_path = os.path.join(os.path.dirname(__file__), 'test_data.json')
    f = open(file_path, 'r')
    content = f.read().decode('utf8')
    f.close()
    data = json.loads(content)
    users = data['users']
    friends = data['friends']
    for user in users:
        pw_md5 = hashlib.md5()
        pw_md5.update(user['password'])
        u = User(name=user['name'], password=pw_md5.hexdigest(), head_img_url=user['head_img_url'], last_login_time=datetime.now())
        u.insert()
        for detail in user['user_details']:
            ud = UserDetail(user_id=u.id, field_name=detail['field_name'], field_value='%s,v' % detail['field_value'], updated_at=datetime.now())
            ud.insert()
            ui = UserIndex(field_name=detail['field_name'], field_value=detail['field_value'], user_id=u.id)
            ui.insert()
    for friend in friends:
        user_id = UserIndex.get_user_id('phone', friend['user_phone'])
        friend_id = UserIndex.get_user_id('phone', friend['friend_phone'])
        f = Friend(user_id=user_id, friend_id=friend_id)
        f.insert()
        print "u_id: %d, f_id: %d" % (user_id, friend_id)
        f = Friend(user_id=friend_id, friend_id=user_id)
        f.insert()
        print "u_id: %d, f_id: %d" % (friend_id, user_id)

        
开发者ID:chinatian,项目名称:python-orm,代码行数:29,代码来源:init_data.py

示例2: test_user_no_password

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
def test_user_no_password(db_conn, users_table):
    """
    Ensure an password isn't provided ever.
    """
    user, errors = User.insert({"name": "test", "email": "[email protected]", "password": "abcd1234"})
    json = user.deliver(access="private")
    assert "password" not in json
开发者ID:Folashade,项目名称:sagefy,代码行数:9,代码来源:test_models_user.py

示例3: test_user_password_validate

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
def test_user_password_validate(db_conn, users_table):
    """
    Ensure a password can be validated.
    """
    user, errors = User.insert({"id": "abcd1234", "name": "test", "email": "[email protected]", "password": "abcd1234"})
    assert not user.is_password_valid("1234abcd")
    assert user.is_password_valid("abcd1234")
开发者ID:Folashade,项目名称:sagefy,代码行数:9,代码来源:test_models_user.py

示例4: test_user_password_encrypt

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
def test_user_password_encrypt(db_conn, users_table):
    """
    Ensure a password is encrypted before going into db.
    """
    user, errors = User.insert({"id": "abcd1234", "name": "test", "email": "[email protected]", "password": "abcd1234"})
    assert len(errors) == 0
    assert user["password"] != "abcd1234"
    assert user["password"].startswith("$2a$")
开发者ID:Folashade,项目名称:sagefy,代码行数:10,代码来源:test_models_user.py

示例5: test_user_email_current

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
def test_user_email_current(db_conn, users_table):
    """
    Ensure an email is only provided when current user.
    """
    user, errors = User.insert({"name": "test", "email": "[email protected]", "password": "abcd1234"})
    json = user.deliver()
    assert "email" not in json
    json = user.deliver(access="private")
    assert "email" in json
开发者ID:Folashade,项目名称:sagefy,代码行数:11,代码来源:test_models_user.py

示例6: test_user_email_unique

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
def test_user_email_unique(db_conn, users_table):
    """
    Ensure an email is unique.
    """
    users_table.insert({"id": "abcd1234", "email": "[email protected]"}).run(db_conn)
    user, errors = User.insert({"name": "test", "email": "[email protected]", "password": "abcd1234"})
    assert len(errors) > 0
    assert "email" in [e["name"] for e in errors]
    assert "Must be unique." in [e["message"] for e in errors]
开发者ID:Folashade,项目名称:sagefy,代码行数:11,代码来源:test_models_user.py

示例7: test_update_password

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
def test_update_password(db_conn, users_table):
    """
    Expect to update a user's password.
    """

    user, errors = User.insert({"name": "Dalton", "email": "[email protected]", "password": "abcd1234"})
    pw1 = user["password"]
    user["password"] = "1234abcd"
    user.save()
    assert pw1 != user["password"]
开发者ID:Folashade,项目名称:sagefy,代码行数:12,代码来源:test_models_user.py

示例8: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
 def post(self):
     name = self.get_argument("name")
     phone = self.get_argument("phone", None)
     # 保存数据
     pw = '123456'
     pw_md5 = hashlib.md5()
     pw_md5.update(pw)
     u = User(name=name, password=pw_md5.hexdigest(), last_login_time=datetime.now())
     u.insert()
     if phone:
         ud = UserDetail(user_id=u.id, field_name='phone', field_value='%s,v' % phone, updated_at=datetime.now())
         ud.insert()
         ui = UserIndex(field_name='phone', field_value=phone, user_id=u.id)
         ui.insert()
         result = {'success':True, 'user':{'id':u.id, 'password':pw}}
     else:
         result = {'success':True}
     self.set_secure_cookie("user", str(u.id))
     self.write(json.dumps(result))
开发者ID:chinatian,项目名称:python-orm,代码行数:21,代码来源:user.py

示例9: create_user_route

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
def create_user_route(request):
    """
    Create user.
    """

    user, errors = User.insert(request['params'])
    if len(errors):
        return 400, {
            'errors': errors,
            'ref': 'YEcBnqf4vyA2pckIy70R789B',
        }
    return _log_in(user)
开发者ID:Folashade,项目名称:sagefy,代码行数:14,代码来源:user.py

示例10: range

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import insert [as 别名]
from models.user import User

for n in range(2000):
	name = 'chinatian_%d' % n
        phone = '12344%d' % n
        pw = '123456'
        pw_md5 = '123455'
        pw_md5.update(pw)
        u = User(name=name, password=pw_md5.hexdigest(), last_login_time=datetime.now())
        u.insert()
开发者ID:chinatian,项目名称:python-orm,代码行数:12,代码来源:insert_user.py


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