本文整理汇总了Python中model.anno.Anno.query方法的典型用法代码示例。如果您正苦于以下问题:Python Anno.query方法的具体用法?Python Anno.query怎么用?Python Anno.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.anno.Anno
的用法示例。
在下文中一共展示了Anno.query方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_favorite_apps
# 需要导入模块: from model.anno import Anno [as 别名]
# 或者: from model.anno.Anno import query [as 别名]
def list_favorite_apps(cls, user_key):
# We are using "query" on key for getting anno data instead of "get" or "get_multi"
# Getting anno using "query" is more memory efficient than using "get" or "get_multi",
# we don't know why.
# Getting anno using "query" also create index for this.
from model.userannostate import UserAnnoState
from model.anno import Anno
userannostate_list = UserAnnoState.list_by_user(user_key, 50)
anno_key_list = [ userannostate.anno for userannostate in userannostate_list if userannostate.anno is not None ]
if len(anno_key_list):
anno_list = Anno.query(ndb.AND(Anno.key.IN(anno_key_list),
Anno.app != None)
)\
.fetch(projection=[Anno.app])
app_key_list = [ anno.app for anno in anno_list ]
app_key_list = sorted(app_key_list, key=app_key_list.count, reverse=True)
unique_app_key_list = []
[ unique_app_key_list.append(app_key) for app_key in app_key_list if app_key not in unique_app_key_list ]
app_list = ndb.get_multi(unique_app_key_list)
else:
app_list = []
favorite_apps_list = []
for app in app_list:
if app:
app_message = UserFavoriteApp(name=app.name, icon_url=(app.icon_url or ""), version=(app.version or ""))
favorite_apps_list.append(app_message)
return favorite_apps_list
示例2: init_index_document
# 需要导入模块: from model.anno import Anno [as 别名]
# 或者: from model.anno.Anno import query [as 别名]
def init_index_document(self, request):
"""
Exposes an API endpoint to insert search document for legacy documents.
"""
for anno in Anno.query():
logging.info("generating search document for anno(%s)." % anno.key.id())
put_search_document(anno.generate_search_document(), SearchIndexName.ANNO)
return message_types.VoidMessage()
示例3: migrate_photo_time_annos
# 需要导入模块: from model.anno import Anno [as 别名]
# 或者: from model.anno.Anno import query [as 别名]
def migrate_photo_time_annos(cursor=None):
team_key = 'us.orbe.Reko-Album'
phototime_app = AppInfo.query().filter(AppInfo.lc_name == 'phototime').get()
phototime_community = Community.getCommunityFromTeamKey(team_key=team_key)
anno_list = Anno.query().filter(Anno.app == phototime_app.key).fetch()
for anno in anno_list:
anno.community = phototime_community.key
user_email = anno.creator.get().user_email
anno.creator = User.find_user_by_email(email=user_email, team_key=team_key).key
anno.put()
示例4: anno_list
# 需要导入模块: from model.anno import Anno [as 别名]
# 或者: from model.anno.Anno import query [as 别名]
def anno_list(self, request):
"""
Exposes an API endpoint to retrieve a list of anno.
"""
limit = 10 # default limit is 10.
if request.limit is not None:
limit = request.limit
curs = None
if request.cursor is not None:
try:
curs = Cursor(urlsafe=request.cursor)
except BadValueError:
raise endpoints.BadRequestException('Invalid cursor %s.' % request.cursor)
select_projection = None
# todo: add projection validation, may need metadata.
if request.select is not None:
select_projection = request.select.split(',')
if (curs is not None) and (select_projection is not None):
annos, next_curs, more = Anno.query().fetch_page(limit, start_cursor=curs, projection=select_projection)
elif (curs is not None) and (select_projection is None):
annos, next_curs, more = Anno.query().fetch_page(limit, start_cursor=curs)
elif (curs is None) and (select_projection is not None):
annos, next_curs, more = Anno.query().fetch_page(limit, projection=select_projection)
else:
annos, next_curs, more = Anno.query().fetch_page(limit)
if select_projection is not None:
items = [entity.to_response_message_by_projection(select_projection) for entity in annos]
else:
items = [entity.to_response_message() for entity in annos]
if more:
return AnnoListMessage(anno_list=items, cursor=next_curs.urlsafe(), has_more=more)
else:
return AnnoListMessage(anno_list=items, has_more=more)
示例5: update_anno_schema
# 需要导入模块: from model.anno import Anno [as 别名]
# 或者: from model.anno.Anno import query [as 别名]
def update_anno_schema(cursor=None):
anno_list, cursor, more = Anno.query().fetch_page(BATCH_SIZE, start_cursor=cursor)
anno_update_list = []
for anno in anno_list:
# updating anno schema for plugin
if not anno.archived:
anno.archived = False
anno_update_list.append(anno)
# updating app for anno schema
# if not anno.app:
# appinfo = AppInfo.get(name=anno.app_name)
#
# if appinfo is None:
# appInfoMessage = AppInfoMessage(name=anno.app_name, version=anno.app_version)
# appinfo = AppInfo.insert(appInfoMessage)
#
# anno.app = appinfo.key
# anno_update_list.append(anno)
# updating anno schema for community
# if not anno.community:
# anno.community = None
# anno_update_list.append(anno)
# updating anno schema for anno_id
# if not anno.anno_id:
# anno.anno_id = anno.key.id()
# anno_update_list.append(anno)
# updating userannostate from anno
# update_userannostate_schema_from_anno(anno)
# updating anno index
# regenerate_index(anno, SearchIndexName.ANNO)
# extract tag
# create_tags(anno.anno_text)
if len(anno_update_list):
ndb.put_multi(anno_update_list)
if more:
update_anno_schema(cursor=cursor)