本文整理汇总了Python中users.Users.get_user_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Users.get_user_by_id方法的具体用法?Python Users.get_user_by_id怎么用?Python Users.get_user_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.Users
的用法示例。
在下文中一共展示了Users.get_user_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_post_win_count_by_user
# 需要导入模块: from users import Users [as 别名]
# 或者: from users.Users import get_user_by_id [as 别名]
def get_post_win_count_by_user(user_id):
try:
user = Users.get_user_by_id(user_id)
user_extension = Users.get_user_extension(user.username)
count = 0
for fp in ForumPost.objects.all():
if user_extension in fp.win_users.all():
count += 1
return count
except Exception as ex:
Logs.print_current_function_name_and_line_number(ex)
return 0
示例2: get4rain
# 需要导入模块: from users import Users [as 别名]
# 或者: from users.Users import get_user_by_id [as 别名]
def get4rain(sequence, user_id):
"""
:param sequence: 设备UUID
:param user_id: 用户ID
:return: 红包雨 -- 是否成功, 说明信息,红包金额
查看红包雨是否已经发放了足够数量; 查看今天是否获取了请求红包或有效红包;
"""
result = {}
RedEnvelopeConfiguration.set_red_envelope_configuration()
bonus = 0
user = Users.get_user_by_id(user_id)
phone = user.username
if SpecialActivity.exist_in_99(phone):
today = Datetimes.get_now()
today_start = Datetimes.get_day_start(today)
today_end = Datetimes.get_day_end(today)
today_red_envelope = RedEnvelopes.get_valid_or_request_red_envelope(
today_start, today_end, RedEnvelopes.RED_ENVELOPE_TYPE_RAIN)
rest = 0.27 - today_red_envelope
min_money = 0.01
min_value = 1
max_value = 27
possibility = 1
factor = 100
bonus = RedEnvelopes.compute_red_envelope(
rest,
min_money,
min_value,
max_value,
possibility,
factor
)
elif SpecialActivity.exist_in_119(phone):
today = Datetimes.get_now()
today_start = Datetimes.get_day_start(today)
today_end = Datetimes.get_day_end(today)
today_red_envelope = RedEnvelopes.get_valid_or_request_red_envelope(
today_start, today_end, RedEnvelopes.RED_ENVELOPE_TYPE_RAIN)
rest = 0.32 - today_red_envelope
min_money = 0.01
min_value = 1
max_value = 32
possibility = 1
factor = 100
bonus = RedEnvelopes.compute_red_envelope(
rest,
min_money,
min_value,
max_value,
possibility,
factor
)
else:
count = RedEnvelopes.get_rain_count(user_id)
if count >= RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_COUNT:
result["success"] = False
result["info"] = "the rain stopped"
result["bonus"] = 0
return result
if RedEnvelopes.has_got_rain(user_id):
result["success"] = False
result["info"] = "you have got the rain today"
result["bonus"] = 0
return result
device = Devices.get(sequence)
if not device:
result["success"] = False
result["info"] = "There is no device"
result["bonus"] = 0
return result
rd_type = RedEnvelopes.RED_ENVELOPE_TYPE_RAIN
rd_state = RedEnvelopes.RED_ENVELOPE_STATE_REQUEST
start_and_end = RedEnvelopes.get_rain_start_and_end()
start = start_and_end["start"]
end = start_and_end["end"]
given_bonus = RedEnvelopes.get_valid_and_request_bonus(start, end, rd_type)
rest = RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_THRESHOLD - given_bonus
factor = RedEnvelopeConfiguration.RED_ENVELOPE_FACTOR
min_money = RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_MIN
min_value = RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_MIN * factor
max_value = RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_MAX * factor
bonus = RedEnvelopes.compute_red_envelope(
rest,
min_money,
min_value,
max_value,
RedEnvelopeConfiguration.RED_ENVELOPE_RAIN_POSSIBILITY,
factor
)
result["bonus"] = bonus
if bonus == 0:
result["success"] = False
result["info"] = "There is no enough money for red envelope or it is possible"
else:
RedEnvelopes.generate(bonus, user_id, device.id, rd_type, rd_state)
#.........这里部分代码省略.........