Esempio n. 1
0
 def create(cls, **params):
     if params:
         params['id'] = snowflake.generate()
     v = cls(**params)
     db.session.add(v)
     db.session.commit()
     return v
Esempio n. 2
0
 def create_user(cls, **params):
     if params:
         params['id'] = snowflake.generate()
     user = User(**params)
     db.session.add(user)
     db.session.commit()
     return user
Esempio n. 3
0
def create_image(params=None):
    user_id = get_param(params, 'user_id', 0)
    url = get_param(params, 'url', '')

    v = Image(
        id=snowflake.generate(),
        user_id=user_id,
        url=url,
        is_del=BaseConfig.DEFAULT_IS_DEL,
    )

    db.session.add(v)
    db.session.commit()
    return v
Esempio n. 4
0
def create_reply(**params):
    '''创建回复'''
    new_id = snowflake.generate()
    c = Comment(
        id=new_id,
        user_id=params['user_id'],
        to_user_id=params['to_user_id'],
        res_id=params['comment_id'],
        res_type=BaseConfig.TYPE_COMMENT,
        content=params['content'],
        is_del=BaseConfig.DEFAULT_IS_DEL
    )
    db.session.add(c)
    db.session.commit()
    return c
Esempio n. 5
0
def create_comment(**keywords):
    '''创建评论'''
    new_id = snowflake.generate()
    c = Comment(
        id=new_id,
        user_id=keywords['user_id'],
        to_user_id="",
        res_id=keywords['res_id'],
        res_type=BaseConfig.TYPE_RES,
        content=keywords['content'],
        is_del=BaseConfig.DEFAULT_IS_DEL
    )
    db.session.add(c)
    db.session.commit()
    return c
Esempio n. 6
0
def create_user(**params):
    '''创建用户'''
    mobile = get_param(params, 'mobile', '')
    name = get_param(params, 'name', '')
    status = get_param(params, 'status', BaseConfig.DEFAULT_USER_STATUS)
    new_id = snowflake.generate()

    ext = {"location": "", "sign": "", "lat": 0, "lng": 0}

    u = User(id=new_id,
             mobile=mobile,
             name=name,
             portrait=BaseConfig.DEFAULT_PORTRAIT,
             age=BaseConfig.DEFAULT_AGE,
             gender=BaseConfig.DEFAULT_GENDER,
             status=status,
             ext=ext,
             is_del=BaseConfig.DEFAULT_IS_DEL)
    db.session.add(u)
    db.session.commit()
    return u
Esempio n. 7
0
from src import snowflake

if __name__ == '__main__':

    for i in range(1, 100):
        print(snowflake.generate())

    # print(len('{:b}'.format(snowflake.generate())))