本文整理汇总了Python中models.user.User.select方法的典型用法代码示例。如果您正苦于以下问题:Python User.select方法的具体用法?Python User.select怎么用?Python User.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_verify_code
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def send_verify_code(user, params):
phone = params.get('phone')
vtype = params.get("vtype")
if not vtype or vtype not in ("enter", "register", "forget"):
return {"error_code": 20631, "msg": "vtype invalid"}
if vtype == "enter":
# 为当前登录用户获取验证码
if not user:
return {"error_code": 20632, "msg": "user not exists"}
return send_code(phone=user.phone)
elif vtype in ("register", "forget", ):
# register: 注册获取验证码
# forget: 忘记密码获取验证码
if not phone:
return {"error_code": 20636, "msg": "username or phone not exists"}
user = User.select().where(User.username == phone).first()
if vtype == "register":
if user:
return {"error_code": 20633, "msg": "user phone already register"}
if vtype == "forget":
if not user:
return {"error_code": 20634, "msg": "user not exists"}
return send_code(phone=phone)
示例2: user_role_change
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def user_role_change(user, params, token, device):
uid = params.get("id", "")
if device == "web":
role, role_id = user.identify[0], int(user.identify[1:])
else:
role, role_id = user.app_identify[0], int(user.app_identify[1:])
tmp_user = User.select().where(User.uuid==uid).first()
identify = None
if not tmp_user:
tmp_team = Team.select().where(Team.uuid==uid).first()
if not tmp_team or tmp_team.user != user:
return {"error_code": 20332, "msg": "the role not change, not allowed"}
if role == "f":
identify = "c%s" % tmp_team.id
else:
if tmp_user.id != user.id:
return {"error_code": 20332, "msg": "the role not change, not allowed"}
if role == "c":
identify = "f%s" % tmp_user.id
if identify:
if device == "web":
user.identify = identify
user.save()
else:
user.app_identify = identify
user.save()
if device in ("ios", "android"):
qs = Session.delete().where(Session.user==user, Session.session_key!=token, Session.device << ("ios", "android"))
qs.execute()
return {"error_code": 0, "msg": "ok"}
示例3: client_login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def client_login(params):
code = params.get("code")
if not code or len(code) != 36:
return {"error_code":1, "msg":"params invalid"}
key = "jump-%s" % code
obj = misc.misc_get(key)
if not obj:
return {"error_code":1, "msg":"code not exists"}
dic = utils.loads(obj.value)
obj.delete_instance()
if dic['expire_at'] < utils.stamp():
return {"error_code":1, "msg":"code expire"}
user = User.select().where(User.id==dic['user_id']).first()
res = {"error_code":0, "msg":"ok"}
res['session_token'] = generate_token()
sess = Session()
sess.user = user
sess.session_key = res['session_token']
sess.expire_at = utils.timedelta(utils.now(), days=1)
res['expire_at'] = 0
sess.save()
res['identify'] = user.identify
return res
示例4: change_status
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def change_status(params):
status = params['status']
uname = params['uname']
user = User.select().where(User.username == uname).first()
user.status = status
user.save()
return {"error_code":0, "msg":"ok"}
示例5: get_user_by_uuid
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def get_user_by_uuid(uuid):
user = User.select().where(User.uuid==uuid).first()
if not user:
return None
profile = user.profile.first()
profile.avatar = widget.avatar(profile.avatar)
user.profile = profile
return user
示例6: calc_user_discover
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def calc_user_discover(body):
now = utils.now()
start = utils.timedelta(now, days=-90)
year_start = utils.timedelta(now, days=-365)
id_start = 0
while 1:
users = User.select(User.id).where(User.id>id_start).limit(200)
if not users:
break
for u in users:
user_id = u.id
id_start = u.id
us = UserStatistics.select().where(UserStatistics.user == u.id).first()
if not us:
us = UserStatistics()
us.user = u.id
count = UserDiscover.select(fn.SUM(UserDiscover.view_num)).where(UserDiscover.user==user_id, UserDiscover.update_at.between(start, now)).scalar()
us.season_view = count if count else 0
# 90天内投标
count = Proposal.select().where(Proposal.user==user_id,Proposal.ptype=='D',Proposal.create_at.between(start, now)).count()
us.season_proposal = count
# 90内沟通中
count = Proposal.select().where(Proposal.user==user_id,
Proposal.status=="interview",
Proposal.update_at.between(start, now)).count()
us.season_interview = count
# 90天内被邀请
count = Proposal.select().where(Proposal.user==user_id,Proposal.ptype=='I',Proposal.create_at.between(start, now)).count()
us.season_invite = count
# 90天内被邀请回复
count = Proposal.select().where(Proposal.user==user_id,
Proposal.ptype=='I',Proposal.status=="interview",
Proposal.update_at.between(start, now)).count()
us.season_reply = count
# 90天内被邀请当天回复
count1 = Proposal.select().where(Proposal.user==user_id,
Proposal.ptype=='I',Proposal.day_reply==True,
Proposal.update_at.between(start, now)).count()
us.season_day_reply = count1
# 90天内雇佣
count = Proposal.select().where(Proposal.user==user_id,
Proposal.status=="hire",
Proposal.update_at.between(start, now)).count()
us.season_hire = count
# 一年内收总金额
year_amount = MarginRecord.select(fn.SUM(MarginRecord.amount)).where(MarginRecord.user==user_id,
MarginRecord.record_type=="income", MarginRecord.create_at.between(year_start, now)).scalar()
us.year_amount = year_amount if year_amount else 0
us.update_at = now
us.save()
示例7: user_completeness
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def user_completeness(body):
if filter(lambda x: x not in body, ["user_id", "columns"]):
return
user_id = body["user_id"]
columns = body["columns"]
user = User.select().where(User.id == user_id).first()
if not user:
return
up = UserPoints.select().where(UserPoints.user == user).first()
if not up:
up = UserPoints()
up.user = user
up.save()
profile = user.profile.first()
points_change = 0
for column in columns:
points = user_points_config.get(column)
# 新设置加分,去掉后减分, 更改分不变
if column == "category":
value = UserCategory.select().where(UserCategory.user == user).count()
elif column == "avatar":
value = True if not profile.avatar.startswith("/static/") else False
elif column == "other_language":
value = UserLanguage.select().where(UserLanguage.user == user).count()
elif column == "employment":
value = Employment.select().where(Employment.user == user).count()
elif column == "education":
value = Education.select().where(Education.user == user).count()
elif column == "portfolio":
value = Portfolio.select().where(Portfolio.user == user).count()
elif column == "email":
value = getattr(user, column)
else:
value = getattr(profile, column)
if value:
if not getattr(up, column):
setattr(up, column, True)
points_change += points
else:
if getattr(up, column):
setattr(up, column, False)
points_change -= points
# 每次循环完更新字断加分标示
up.save()
# 循环完毕更新总分
profile.completeness += points_change
profile.save()
return
示例8: password_reset
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def password_reset(params):
uname = params.get('username')
password = params.get('password')
if not uname or not password:
return {"error_code":20091, "msg":"parameters required"}
user = User.select().where(User.username == uname).first()
if not user:
return {"error_code":20093, "msg":"user not exists"}
pw, salt = generate_password(password)
user.password = pw
user.salt = salt
user.update_at = utils.now()
user.save()
return {"error_code":0, "msg":"ok"}
示例9: user_discover_view
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def user_discover_view(body):
if "uuid" not in body or "user_id" not in body:
return
now = utils.now()
period = utils.datetime_to_day_number(now)
user = User.select().where(User.uuid==body["uuid"]).first()
if not user or user.id == int(body["user_id"]):
return
ud = UserDiscover.select().where(UserDiscover.user==user, UserDiscover.period==period).first()
if not ud:
ud = UserDiscover()
ud.user = user
ud.period = utils.datetime_to_day_number(now)
ud.view_num += 1
ud.update_at = now
ud.save()
return
示例10: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def login(uname, password):
if not uname or not password:
return {"error_code":20001, "msg":"parameters required"}
user = User.select().where(User.username == uname or User.email == uname or User.phone == uname).first()
if not user:
return {"error_code":20002, "msg":"user not exists"}
if not check_password(password, user.password, user.salt):
return {"error_code":20003, "msg":"username or password invalid"}
res = {"error_code":0, "msg":"ok"}
res['session_token'] = generate_token()
sess = Session()
sess.user = user
sess.session_key = res['session_token']
sess.expire_at = utils.timedelta(utils.now(), days=1)
res['expire_at'] = 0
sess.save()
return res
示例11: user_list
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def user_list(params):
page = params.get('page', 1)
count = params.get('count', 20)
userlist = User.select(User.username,User.phone,User.status,User.to_dev,User.to_req,
Profile.name,Profile.skills,Profile.address,Profile.alipay).\
join(Profile).paginate(page, count)
user_arr = []
for user in userlist:
temp = {}
temp['username'] = user.username
temp['phone'] = user.phone
temp['status'] = user.status
temp['to_dev'] = user.to_dev
temp['to_req'] = user.to_req
temp['name'] = user.profile.name
temp['skills'] = user.profile.skills
temp['address'] = user.profile.address
temp['alipay'] = user.profile.alipay
user_arr.append( temp)
return {"error_code":0, "msg":"ok", "userlist": user_arr}
示例12: user_profile_update
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def user_profile_update(user, params):
if len(params) == 0:
return {"error_code": 0, "msg": "ok"}
email = params.get("email")
name = params.get("name")
location = utils.safe_id(params.get('location'))
address = params.get("address")
postcode = params.get("postcode")
available = params.get("available")
workload = params.get("workload")
title = params.get("title")
overview = params.get("overview")
hourly = params.get("hourly")
skills = params.get("skills")
english = params.get("english")
other = params.get("other", "").strip()
level = params.get("level")
# 更新分值字断名称
columns = list()
profile = user.profile.first()
if email is not None:
if not validate.is_email(email):
return {"error_code": 202710, "msg": "email invalid"}
u = User.select().where(User.email == email).first()
if u and u.id != user.id:
return {"error_code": 202711, "msg": "email is exists"}
user.email = email
user.save()
columns.append("email")
if level is not None:
if level not in ("entry", "middle", "expert"):
return {"error_code": 202712, "msg": "level invalid"}
if profile.level != level:
profile.level = level
columns.append("level")
if name is not None:
if name.strip() != profile.name:
if profile.id_number:
return {"error_code": 20271, "msg": "already verify user, not allow modify name"}
profile.name = name
if location:
add = Address.select().where(Address.id == location).first()
if not add or add and add.level != 3:
return {"error_code": 20272, "msg": "location invalid"}
profile.location = location
columns.append("location")
if address is not None:
if len(address) > 100:
return {"error_code": 20273, "msg": "address too long"}
profile.address = address
columns.append("address")
if postcode is not None:
if len(postcode) > 20:
return {"error_code": 20274, "msg": "postcode too long"}
profile.postcode = postcode
columns.append("postcode")
if available is not None:
if available == "true":
profile.available = True
elif available == "false":
profile.available = False
if workload is not None:
if not (workload.isdigit() and 1 <= int(workload) <= 3):
return {"error_code": 202713, "msg": "workload invalid"}
profile.workload = workload
columns.append("workload")
if title is not None:
if len(title) > 29:
return {"error_code": 20275, "msg": "title too long"}
profile.title = title
columns.append("title")
if overview is not None:
if len(overview) > 1024 * 1024 * 4:
return {"error_code": 20276, "msg": "overview too long"}
profile.overview = overview
columns.append("overview")
if hourly is not None:
try:
hourly = float(hourly)
except:
return {"error_code": 20277, "msg": "hourly invalid"}
profile.hourly = hourly
columns.append("hourly")
if english is not None:
if english not in ("1", "2", "3", "4"):
#.........这里部分代码省略.........
示例13: user_profile
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def user_profile(user, params, lang):
origin_user = user
uuid = params.get("uuid", "")
if uuid:
user = User.select().where(User.uuid == uuid).first()
if not user:
return {"error_code": 20002, "msg": "user not exist"}
profile = user.profile.first()
languages = []
ul = UserLanguage.select().where(UserLanguage.user == user)
for u in ul:
languages.append(dict(
language_id=u.id,
name=u.name,
level=u.level,
))
out = dict()
# user self can get private information
if not uuid:
out["reg_step"] = user.reg_step
out["id_number"] = "%s********%s" % (profile.id_number[:6], profile.id_number[14:]) if profile.id_number else ""
out["alipay"] = profile.alipay
out["email"] = user.email
out["phone"] = user.phone
out["name"] = profile.name
out["username"] = user.username
out["avatar"] = widget.avatar(profile.avatar)
out["completeness"] = profile.completeness
out["visibility"] = profile.visibility
out["level"] = profile.level
out["title"] = profile.title
out["overview"] = profile.overview
out["hourly"] = profile.hourly
out["english"] = profile.english
out["skills"] = utils.loads(profile.skills) if profile.skills else []
out["available"] = profile.available
out["workload"] = profile.workload
location = {}
if profile.location_id:
city = widget.get_location(profile.location_id)
province = widget.get_location(city.parent_id)
location["location_id"] = profile.location_id
location["name"] = utils.lang_map_name(city.name, city.ename, lang)
location["parent_id"] = province.id
location["parent_name"] = utils.lang_map_name(province.name, province.ename, lang)
out["location"] = location
out["address"] = profile.address
out["postcode"] = profile.postcode
out['id'] = user.uuid
out["languages"] = languages
out["imid"] = user.id
if uuid:
favorites = Favorite.select().where(Favorite.user==origin_user, Favorite.target_id==profile.user_id, Favorite.ftype == 'REQ').first()
if favorites:
out["favorite"] = True
else:
out["favorite"] = False
# 开发者的评价数量和平均得分
score = UserStatistics.select(UserStatistics.eveluate_num, UserStatistics.aver_score).where(UserStatistics.user == user).first()
out["eveluate_num"] = score.eveluate_num if score else 0
out["aver_score"] = score.aver_score if score else 0
return {"error_code": 0, "msg": "ok", "profile": out}
示例14: register
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def register(params, device):
rtype = params.get('rtype', None)
name = params.get('name', None)
phone = params.get('phone', None)
password = params.get('password', None)
vcode = params.get('vcode', None)
uname = params.get('username', '')
cname = params.get('cname', '')
notice = params.get('notice', "true")
if not phone or not password or not vcode or not name or not rtype or not notice or not rtype.isdigit():
return {"error_code":20021, "msg":"parameters required"}
rtype = int(rtype)
if not validate.is_phone(phone):
return {"error_code":20022, "msg":"phone invalid"}
# freelancer: 1, client: 2, client_person: 3
if rtype not in [1, 2, 3]:
return {"error_code":20022, "msg":"user type invalid"}
if rtype == 2 and not cname or len(cname) > 100:
return {"error_code":20022, "msg":"user type invalid or cname too long"}
if not validate.is_verify_code(vcode):
return {"error_code":20024, "msg":"verify code invalid"}
if User.select().where(User.phone == phone).first():
return {"error_code":20025, "msg":"user is exists"}
if rtype != 1:
username = phone
else:
# freelancer do not use username, just use phone to register
# username = uname
username = phone
if not utils.is_username(username):
return {"error_code":20023, "msg":"username invalid"}
if User.select().where(User.username == username).first():
return {"error_code":20025, "msg":"user is exists"}
res = verify_code(phone=phone, code=vcode)
if res['error_code'] != 0:
return res
user_id = GUID.guid()
team_id = GUID.guid()
with database.atomic() as txn:
try:
pwd, salt = generate_password(password.encode('utf-8'))
user = User()
user.id = user_id
user.username = username
user.password = pwd
user.salt = salt
user.phone = phone
#user.verifycode = vcode
user.save(force_insert=True)
profile = Profile()
profile.user = user
profile.name = name
profile.avatar = widget.avatar()
if notice == "true":
profile.is_notice = True
profile.save()
party = Party()
party.user = user
party.vip = False
party.connects = 60
party.agency_connects = 60
party.save()
margin = Margin()
margin.user = user
margin.save()
if rtype == 1:
user.identify = 'f%s' % user.id
user.app_identify = 'f%s' % user.id
user.status = "unactive"
user.to_dev = True
user.to_req = False
user.save()
queue.to_queue({"type":"user_register", "user_id":user.id})
else:
team = Team()
team.id = team_id
team.user = user
if rtype == 2:
team.name = cname
else:
team.name = "个人需求方"
team.team_type = 'client'
team.status = "normal"
#.........这里部分代码省略.........
示例15: user_info
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import select [as 别名]
def user_info(params):
uname = params['uname']
user = User.select().where(User.username == uname).first()
return user_profile(user, params, "zh_CN")