本文整理汇总了Python中google.appengine.datastore.datastore_query.Cursor.from_websafe_string方法的典型用法代码示例。如果您正苦于以下问题:Python Cursor.from_websafe_string方法的具体用法?Python Cursor.from_websafe_string怎么用?Python Cursor.from_websafe_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.datastore.datastore_query.Cursor
的用法示例。
在下文中一共展示了Cursor.from_websafe_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_cursor
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def set_cursor(queryset, start=None, end=None):
queryset = _add_mixin(queryset)
if start is not None:
start = Cursor.from_websafe_string(start)
setattr(queryset.query, '_gae_start_cursor', start)
if end is not None:
end = Cursor.from_websafe_string(end)
setattr(queryset.query, '_gae_end_cursor', end)
return queryset
示例2: set_cursor
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def set_cursor(queryset, start=None, end=None):
queryset = queryset.all()
class CursorQuery(CursorQueryMixin, queryset.query.__class__):
pass
queryset.query = queryset.query.clone(klass=CursorQuery)
if start is not None:
start = Cursor.from_websafe_string(start)
queryset.query._gae_start_cursor = start
if end is not None:
end = Cursor.from_websafe_string(end)
queryset.query._gae_end_cursor = end
# Evaluate QuerySet
return queryset
示例3: retrieve_dbs
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def retrieve_dbs(model_class, query, order=None, limit=None, cursor=None,
**filters):
''' Retrieves entities from datastore, by applying cursor pagindation
and equality filters. Returns dbs and more cursor value
'''
limit = limit or config.DEFAULT_DB_LIMIT
if cursor:
cursor = Cursor.from_websafe_string(cursor)
#apply order if any
if order:
for o in order.split(','):
if o.startswith('-'):
query = query.order(-model_class._properties[o[1:]])
else:
query = query.order(model_class._properties[o])
for prop in filters:
if filters.get(prop, None) is None:
continue
if type(filters[prop]) == list:
for value in filters[prop]:
query = query.filter(model_class._properties[prop] == value)
else:
query = query.filter(model_class._properties[prop] == filters[prop])
model_dbs, more_cursor, more = query.fetch_page(limit, start_cursor=cursor)
if not more:
more_cursor = None
else:
more_cursor = more_cursor.to_websafe_string()
return list(model_dbs), more_cursor
示例4: retrieve_dbs
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def retrieve_dbs(
query, order=None, limit=None, cursor=None, keys_only=None, **filters
):
limit = limit or config.DEFAULT_DB_LIMIT
cursor = Cursor.from_websafe_string(cursor) if cursor else None
model_class = ndb.Model._kind_map[query.kind]
if order:
for o in order.split(','):
if o.startswith('-'):
query = query.order(-model_class._properties[o[1:]])
else:
query = query.order(model_class._properties[o])
for prop in filters:
if filters.get(prop, None) is None:
continue
if isinstance(filters[prop], list):
for value in filters[prop]:
query = query.filter(model_class._properties[prop] == value)
else:
query = query.filter(model_class._properties[prop] == filters[prop])
model_dbs, more_cursor, more = query.fetch_page(
limit, start_cursor=cursor, keys_only=keys_only,
)
more_cursor = more_cursor.to_websafe_string() if more else None
return list(model_dbs), more_cursor
示例5: retrieve_dbs
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def retrieve_dbs(query, order=None, limit=None, cursor=None, **filters):
""" Retrieves entities from datastore, by applying cursor pagination
and equality filters. Returns dbs and more cursor value
"""
limit = limit or config.DEFAULT_DB_LIMIT
cursor = Cursor.from_websafe_string(cursor) if cursor else None
model_class = ndb.Model._kind_map[query.kind]
if order:
for o in order.split(","):
if o.startswith("-"):
query = query.order(-model_class._properties[o[1:]])
else:
query = query.order(model_class._properties[o])
for prop in filters:
if filters.get(prop, None) is None:
continue
if isinstance(filters[prop], list):
for value in filters[prop]:
query = query.filter(model_class._properties[prop] == value)
else:
query = query.filter(model_class._properties[prop] == filters[prop])
model_dbs, more_cursor, more = query.fetch_page(limit, start_cursor=cursor)
more_cursor = more_cursor.to_websafe_string() if more else None
return list(model_dbs), more_cursor
示例6: all
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def all(cls, cursor):
page_size = int(os.environ['PAGE_SIZE'])
query = cls.query().order(-cls.creation_time)
if cursor:
cursor_obj = Cursor.from_websafe_string(cursor)
return query.fetch_page(page_size, start_cursor=cursor_obj)
return query.fetch_page(page_size)
示例7: by_creator
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def by_creator(cls, user_key, cursor):
page_size = int(os.environ['PAGE_SIZE'])
query = cls.query(
cls.status == StatusType.ACTIVE,
cls.creator_key == user_key).order(cls.status, cls.key)
if cursor:
cursor_obj = Cursor.from_websafe_string(cursor)
return query.fetch_page(page_size, start_cursor=cursor_obj)
return query.fetch_page(page_size)
示例8: get_comments_more
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def get_comments_more(self,key):
cursor=self.param('next')
entry=Entry.get(key)
from google.appengine.datastore.datastore_query import Cursor
cur=Cursor.from_websafe_string(cursor)
comments,cursor,more=Comment.query().filter(Comment.entry ==entry.key).order(-Comment.date).fetch_page(10,start_cursor=cur)
vals= dict(entry=entry, comments=comments,cursor=more and cursor.to_websafe_string() or '',more=more)
html=self.get_render('comments_more',vals)
self.write(html)
示例9: by_research
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def by_research(cls, research_key, cursor):
page_size = int(os.environ['PAGE_SIZE'])
query = cls.query(
cls.status == StatusType.ACTIVE,
cls.research_key == research_key)\
.order(-cls.creation_time, cls.status, cls.key)
if cursor:
cursor_obj = Cursor.from_websafe_string(cursor)
return query.fetch_page(page_size, start_cursor=cursor_obj)
return query.fetch_page(page_size)
示例10: by_user
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def by_user(cls, user_key, cursor):
page_size = int(os.environ['PAGE_SIZE'])
q = cls.query(ndb.OR(
cls.supervisor_key == user_key,
cls.researchers_keys == user_key),
cls.status.IN([StatusType.ACTIVE, StatusType.BANNED]))\
.order(cls.key)
if cursor:
cursor_obj = Cursor.from_websafe_string(cursor)
return q.fetch_page(page_size, start_cursor=cursor_obj)
return q.fetch_page(page_size)
示例11: get_dbs
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def get_dbs(
query, order=None, limit=None, cursor=None, keys_only=None, **filters
):
limit = limit or config.DEFAULT_DB_LIMIT
cursor = Cursor.from_websafe_string(cursor) if cursor else None
model_class = ndb.Model._kind_map[query.kind]
for prop in filters:
if filters.get(prop, None) is None:
continue
if isinstance(filters[prop], list):
for value in filters[prop]:
query = query.filter(model_class._properties[prop] == value)
# new custom wodor app -------------
elif isinstance(filters[prop], dict):
if filters[prop]['test'] == '>':
query = query.filter(model_class._properties[prop] > filters[prop]['value'])
elif filters[prop]['test'] == '>=':
query = query.filter(model_class._properties[prop] >= filters[prop]['value'])
elif filters[prop]['test'] == '<':
query = query.filter(model_class._properties[prop] < filters[prop]['value'])
elif filters[prop]['test'] == '<=':
query = query.filter(model_class._properties[prop] < filters[prop]['value'])
elif filters[prop]['test'] == '==':
query = query.filter(model_class._properties[prop] == filters[prop]['value'])
elif filters[prop]['test'] == '!=':
query = query.filter(model_class._properties[prop] != filters[prop]['value'])
elif filters[prop]['test'] == 'IN':
values = filters[prop]['value']
if isinstance(values, list):
values = filters[prop]['value']
else:
values = values.split(',')
query = query.filter(model_class._properties[prop].IN(values))
query = query.order(model_class._key)
query = query.order(model_class._properties[prop]) # TODO does it work?
else:
query = query.filter(model_class._properties[prop] == filters[prop])
# ----------------------------------
if order:
for o in order.split(','):
if o.startswith('-'):
query = query.order(-model_class._properties[o[1:]])
else:
query = query.order(model_class._properties[o])
model_dbs, next_cursor, more = query.fetch_page(
limit, start_cursor=cursor, keys_only=keys_only,
)
next_cursor = next_cursor.to_websafe_string() if more else None
return list(model_dbs), next_cursor
示例12: fetch_cursor
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def fetch_cursor(self,next_cursor='',prev_cursor='',order=None):
from google.appengine.datastore.datastore_query import Cursor
## cur=Cursor.from_websafe_string(p)
## results,cur2,more= self.query.fetch_page(self.items_per_page,start_cursor=cur)
## # setup query
if prev_cursor:
query = self.query.order(order.reversed())
cur=Cursor.from_websafe_string(prev_cursor)
elif next_cursor:
query = self.query.order(order)
cur=Cursor.from_websafe_string(next_cursor)
else:
query = self.query.order(order)
cur=None
# fetch results
results,cur2,more = query.fetch_page(self.items_per_page,start_cursor=cur)
if prev_cursor:
results.reverse()
sPrev=''
sNext=''
# pagination
if prev_cursor:
sNext=cur.reversed().to_websafe_string()
sPrev=more and cur2.to_websafe_string() or ''
else:
if next_cursor:
sPrev=cur.reversed().to_websafe_string()
sNext=more and cur2.to_websafe_string() or ''
links = { 'prev': sPrev, 'next': sNext, 'more': more }
##
## links = {'prev': cur2.reversed().to_websafe_string(), 'next':more and cur2.to_websafe_string() or '','more':more }
##
return (results, links)
示例13: find_all
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def find_all(cls, cursor, keyword):
page_size = int(os.environ['PAGE_SIZE'])
q = cls.query(cls.status.IN([StatusType.ACTIVE, StatusType.BANNED])) \
if keyword:
q = q.filter(cls.email >= keyword)
q = q.filter(cls.email < keyword + u'\ufffd')
q = q.order(cls.email, cls.key)
if cursor:
cursor_obj = Cursor.from_websafe_string(cursor)
return q.fetch_page(page_size, start_cursor=cursor_obj)
return q.fetch_page(page_size)
示例14: artists
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def artists(self, request):
'''API endpoint to query for artists'''
next_page = request.next_page or 'first_artists_page'
cache = memcache.get(next_page)
if cache:
return ArtistsResponse(artists=cache[0], next_page=cache[1])
query = Artist.query()
if next_page is 'first_artists_page':
artists, cursor, more = query.fetch_page(300)
else:
artists, cursor, more = query.fetch_page(300,
start_cursor=Cursor.from_websafe_string(next_page))
artists = [artist.to_message() for artist in artists]
memcache.add(next_page, (artists, cursor.to_websafe_string()))
return ArtistsResponse(artists=artists, next_page=cursor.to_websafe_string())
示例15: validate_request
# 需要导入模块: from google.appengine.datastore.datastore_query import Cursor [as 别名]
# 或者: from google.appengine.datastore.datastore_query.Cursor import from_websafe_string [as 别名]
def validate_request(cls, request):
args = cls.get_dwc_args(request)
if len(args) == 0 and request.get('q', None) is None:
return None
keywords = [x.lower() for x in request.get('q', '').split(',') if x]
limit = request.get_range('limit', min_value=1, max_value=100, default=10)
offset = request.get('offset', None)
cursor = None
if offset:
cursor = Cursor.from_websafe_string(offset)
return dict(
args=args,
keywords=keywords,
limit=limit,
offset=offset,
cursor=cursor)