本文整理汇总了Python中db.User.query方法的典型用法代码示例。如果您正苦于以下问题:Python User.query方法的具体用法?Python User.query怎么用?Python User.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.User
的用法示例。
在下文中一共展示了User.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_random_url
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import query [as 别名]
def generate_random_url(mid):
for i in range(5):
history_url = uuid.uuid4().hex
query = User.query(User.history_url == history_url)
users = query.fetch()
if len(users) > 0:
# duplicated url...
continue
break
else:
# I believe it will not happen
return None
return history_url
示例2: get_drinking_history_content
# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import query [as 别名]
def get_drinking_history_content(history_url):
query = User.query(User.history_url==history_url)
users = query.fetch(1)
if len(users) == 0:
return None
# check it is still valid
if users[0].history_expire < utc_now():
# expired
return None
drinkings = get_drinking_history(users[0].key.id())
t_drinkings = []
for drinking in drinkings:
t_drinking = {}
t_drinking['started'] = format_jdate(drinking.start_date.
replace(tzinfo=tz_utc).astimezone(tz_jst))
t_drinking['finished'] = drinking.finished_date. \
replace(tzinfo=tz_utc).astimezone(tz_jst).strftime('%H:%M') \
if drinking.finished_date else u''
t_drinking['result'] = drinking.result if drinking.result else u''
t_drinking['watches'] = []
for watch in drinking.watches:
if watch.sent_count > 0:
t_watch = {}
t_watch['date'] = watch.date. \
replace(tzinfo=tz_utc).astimezone(tz_jst).strftime('%H:%M')
t_watch['sent_count'] = watch.sent_count
t_watch['reply'] = watch.reply if watch.reply else u'返信なし'
t_drinking['watches'].append(t_watch)
t_drinkings.append(t_drinking)
template_values = {
'drinkings': t_drinkings,
}
template = JINJA_ENVIRONMENT.get_template('templates/index.html')
return template.render(template_values)