本文整理匯總了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)
#.........這裏部分代碼省略.........