本文整理汇总了Python中google.appengine.datastore.datastore_query.Cursor类的典型用法代码示例。如果您正苦于以下问题:Python Cursor类的具体用法?Python Cursor怎么用?Python Cursor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cursor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_stats
def get_stats(
cls,
cursor_key=None,
limit=None,
year=None,
topic=None,
sort_by=None,
**kw
):
if topic:
return RoshReviewUserTopicStats.get_stats(
topic,
cursor_key=cursor_key,
limit=limit,
year=year,
**kw
)
limit = limit if limit else 20
sort_by = sort_by if sort_by else 'performance'
cursor = Cursor(urlsafe=cursor_key) if cursor_key else None
q = cls.query()
if year:
q = q.filter(cls.year == year)
q = q.order(-ndb.GenericProperty(sort_by))
stats, cursor, _ = q.fetch_page(limit, start_cursor=cursor, **kw)
return stats, (cursor.urlsafe() if cursor else None),
示例2: get_template_params
def get_template_params(self, vessel_key):
self.vessel_key = vessel_key
vessel = vessel_key.get()
wpt_qry = Waypoint.query(ancestor=vessel.key).order(-Waypoint.report_date, -Waypoint.received_date)
curs = Cursor(urlsafe=self.request.get('cursor'))
params = {'loginurl': users.create_login_url('/'),
'vessel': vessel,
'map' : GoogleMapTrack(vessel)
}
if self.request.get('cursor'):
params['start_url'] = self.get_base_url()
else:
params['start_url'] = ''
params['waypoints'], next_curs, params['older'] = wpt_qry.fetch_page(self.NUM_WAYPOINTS, start_cursor=curs)
params['this_page_url'] = self.get_base_url() + "?cursor=" + curs.urlsafe()
if params['older'] and next_curs:
params['next_page_url'] = self.get_base_url() + "?cursor=" + next_curs.urlsafe()
else:
params['older'] = False
# #Formulate reverse pointer if there is more recent waypoints
# rev_wpt_qry = Waypoint.query(ancestor=vessel.key).order(Waypoint.report_date, Waypoint.received_date)
# rev_curs = curs.reversed()
# _, prev_curs, params['newer'] = wpt_qry.fetch_page(self.NUM_WAYPOINTS, start_cursor=rev_curs)
# if params['newer'] and prev_curs:
# params['prev_page_url'] = self.get_base_url() + "?cursor=" + prev_curs.reversed().urlsafe()
# else:
# params['newer'] = False
return params
示例3: get
def get(self):
f_cursor_param = self.request.get('f_cursor')
b_cursor_param = self.request.get('b_cursor')
template_values = {}
if b_cursor_param:
words_query = Word.query(ancestor=create_dictionary_key()).order(Word.date)
b_cursor = Cursor(urlsafe=self.request.get('b_cursor'))
template_values['f_cursor'] = b_cursor.urlsafe()
rev_curs = b_cursor.reversed()
words, next_cursor, more = words_query.fetch_page(WORDS_PER_PAGE, start_cursor=rev_curs)
words.reverse()
if more and next_cursor:
template_values['b_cursor'] = next_cursor.reversed().urlsafe()
else:
words_query = Word.query(ancestor=create_dictionary_key()).order(-Word.date)
f_cursor = Cursor(urlsafe=self.request.get('f_cursor'))
template_values['b_cursor'] = f_cursor.urlsafe()
words, next_cursor, more = words_query.fetch_page(WORDS_PER_PAGE, start_cursor=f_cursor)
if more and next_cursor:
template_values['f_cursor'] = next_cursor.urlsafe()
wordDTOs = []
for word in words:
wordDTOs.append(WordDTO(word.word, word.description, word.example))
template_values['words'] = wordDTOs
self.response.out.write(template.render(get_template_path('view_words.html'), template_values))
示例4: get_staff
def get_staff(cls, cursor_key, limit=20, **kw):
cursor = Cursor(urlsafe=cursor_key) if cursor_key else None
is_staff = True
q = cls.query().filter(cls.is_staff == is_staff)
q = q.order(cls.display_name)
staff, cursor, _ = q.fetch_page(limit, start_cursor=cursor, **kw)
return staff, (cursor.urlsafe() if cursor else None)
示例5: process
def process (self, cursor=None):
if cursor:
cursor = Cursor(urlsafe=cursor)
total_clicks = 0
total_opens = 0
self.temp_clicks = {}
self.temp_opens = {}
if cursor == None: #skip all cursor continuations, these values are already init'd
self.tags = {}
self.urls = {}
self.clients = {}
self.clicks = []
self.opens = []
self.total_sends = 0
self.total_clicks = 0
self.total_opens = 0
from bulkmail.api.models import Campaign
c = Campaign.query(Campaign.campaign_id == self.campaign_id, Campaign.list_id == self.list_id).get()
for key in c.send_data:
sd = key.get()
self.total_sends += len(sd.data)
tracks, cursor, more = Track.query(
Track.list_id == self.list_id,
Track.campaign_id == self.campaign_id,
ndb.OR(Track.ttype == 'click', Track.ttype == 'open')
).order(Track._key).fetch_page(100, start_cursor=cursor)
for t in tracks:
self.process_track(t)
if t.ttype == 'click':
total_clicks += 1
elif t.ttype == 'open':
total_opens += 1
#set total_clicks/total_opens
self.total_clicks = self.total_clicks + total_clicks
self.total_opens = self.total_opens + total_opens
#set clicks/opens
self.sort_data('clicks')
self.sort_data('opens')
self.put()
if more and cursor:
taskqueue.add(
url='/api/compile-stats',
params={
'list_id': self.list_id,
'campaign_id': self.campaign_id,
'key': self.key.urlsafe(),
'cursor': cursor.urlsafe()
},
queue_name='stats'
)
示例6: livros
def livros(_write_tmpl, **params):
index = params["pag"] if params.has_key("pag") else ""
_type = params["type"] if params.has_key("type") else "next"
cursor = Cursor(urlsafe=index)
query = Livro.query()
has_previous = False
if _type == "previous":
q_backward = query.order(-Livro.titulo)
livros, previous, has_previous = q_backward.fetch_page(5, start_cursor = cursor.reversed())
has_next = True
next = cursor.reversed()
for l in livros:
l.id = l.key.id()
livros = reversed(livros)
else:
q_forward = query.order(Livro.titulo)
livros, next, has_next = q_forward.fetch_page(5, start_cursor = cursor)
if params.has_key("pag") and params["pag"] != '':
has_previous = True
previous = cursor
for l in livros:
l.id = l.key.id()
var = {"livros":livros,
"has_next":has_next,
"has_previous":has_previous,
"previous_cursor":previous,
"next_cursor":next}
_write_tmpl('templates/panel/livros.html', var)
示例7: get_students
def get_students(cls, cursor_key=None, limit=None, name=None, years=[], **kw):
limit = 20 if limit is None else limit
cursor = Cursor(urlsafe=cursor_key) if cursor_key else None
q = cls.query()
if name:
q = q.filter(cls.names >= name)
q = q.filter(cls.names < "%s{" % name)
if years:
q = q.filter(cls.year.IN(years))
else:
q = q.filter(cls.is_active == True)
if name:
q = q.order(cls.names, cls.year)
elif years:
q = q.order(cls.year, cls.display_name, cls.key)
else:
q = q.order(cls.year, cls.display_name)
if name or limit == 0:
limit = limit if limit else None
students, cursor = q.fetch(limit, **kw), None
else:
students, cursor, _ = q.fetch_page(limit, start_cursor=cursor, **kw)
return ([s.details() for s in students], (cursor.urlsafe() if cursor else None))
示例8: list
def list(limit=10, cursor=None):
if cursor:
cursor = Cursor(urlsafe=cursor)
query = Book.query().order(Book.title)
entities, cursor, more = query.fetch_page(limit, start_cursor=cursor)
entities = builtin_list(map(from_datastore, entities))
return entities, cursor.urlsafe() if len(entities) == limit else None
示例9: tag
def tag(tag):
cursor_str = util.param('cursor', str)
cursor = None
try:
cursor = Cursor(urlsafe=cursor_str)
except TypeError:
key = None
story_dbs, next_cursor, more = model.Story.query(
model.Story.tags == tag).filter(model.Story.story_item_count > 0).fetch_page(24,
start_cursor=cursor)
if len(story_dbs) == 0:
not_found = exceptions.NotFound()
raise not_found
params = {
'next_cursor': next_cursor.urlsafe(),
'tag': tag,
'current_cursor': cursor.urlsafe()
}
resp_model = {}
resp_model['html_class'] = 'tag'
resp_model['canonical_path'] = flask.url_for('tag', tag=tag)
decorate_page_response_model(resp_model)
decorate_stories_page_model(resp_model, story_dbs, params)
return flask.render_template('public/story/story_list.html', model=resp_model)
示例10: get
def get(self, post_key):
from google.appengine.datastore.datastore_query import Cursor
args = {}
next_cursor = self.request.get('next_cursor');
ckey = 'PostHandler.%s.%s' % (post_key,next_cursor)
cdata = memcache.get(ckey)
if cdata is not None:
args = cdata
else:
args['tags'] = self.tags()
post = Feed.query(Feed.key == ndb.Key(urlsafe = post_key)).get()
next_cursor = Cursor(urlsafe=next_cursor)
entryRef, next_cursor, more = Comment.query(Comment.parent == post.key).order(Comment.created_time).fetch_page(100, start_cursor = next_cursor)
entries = []
for _entry in entryRef:
entry = _entry.to_dict()
entry['member'] = _entry.member.get().to_dict()
entries.append(entry)
post_key = post.key.urlsafe()
args['post'] = post.to_dict();
args['post']['message'] = message(args['post']['message'])
args['post']['member'] = post.member.get().to_dict()
args['comments'] = {}
args['comments']['entries'] = entries;
args['comments']['next_cursor'] = next_cursor.urlsafe() if next_cursor else None
args['comments']['more'] = more
if not memcache.add(ckey, args, CACEH_POST_IN_PERMLINK):
logging.error('Memcache set failed.')
template = JINJA_ENVIRONMENT.get_template('/view/post.html')
self.response.write(template.render(args))
示例11: __init__
def __init__(self, model_cls, limit, order, cursor_str="", query=None):
cursor = Cursor(urlsafe=cursor_str) if cursor_str else Cursor()
rcursor = cursor.reversed()
cls_order = getattr(model_cls, order)
if query == None: query = model_cls.query()
q_forward = query.order(cls_order)
q_reverse = query.order(-cls_order)
self._items, self._next_cursor, self._more = q_forward.fetch_page(limit, start_cursor=cursor)
unused_itemss, self._prev_cursor, unused_prev_more = q_reverse.fetch_page(limit, start_cursor=rcursor)
self._cursor = cursor
示例12: get
def get(self, *args, **kwargs):
self.model_class = kwargs["_class"]
self.form_class = kwargs["_form_class"]
p = self.request.get("p")
q = self.request.get("q")
c = self.request.get("c")
forward = True if p not in ["prev"] else False
cursor = Cursor(urlsafe=c)
from google.appengine.ext.ndb.query import Node
if q:
nodes = []
for search in self.form_class.search_list:
nodes.append(FilterNode(search, "=", q))
qry = self.model_class.query(ndb.OR(*nodes))
else:
qry = self.model_class.query()
PAGE_SIZE = 5
if forward:
users, next_cursor, more = qry.order(self.model_class.key).fetch_page(PAGE_SIZE, start_cursor=cursor)
if next_cursor and more:
self.view.next_cursor = next_cursor
if c:
self.view.prev_cursor = cursor.reversed()
else:
users, next_cursor, more = qry.order(-self.model_class.key).fetch_page(PAGE_SIZE, start_cursor=cursor)
users = list(reversed(users))
if next_cursor and more:
self.view.prev_cursor = next_cursor
self.view.next_cursor = cursor.reversed()
def pager_url(p, cursor):
params = OrderedDict()
if q:
params["q"] = q
if p in ["prev"]:
params["p"] = p
if cursor:
params["c"] = cursor.urlsafe()
return self.uri_for("%s-list" % self.model_class.__name__.lower(), **params)
self.view.pager_url = pager_url
self.view.q = q
params = {
"class_name": self.model_class.__name__,
"list_columns": self.form_class.list_columns,
"users": users,
"count": qry.count(),
"add_uri": self.uri_for("%s-add" % self.model_class.__name__.lower()),
}
logger.warn(params)
return self.render_template("admin/list.html", **params)
示例13: get
def get(self):
p = self.request.get('p')
q = self.request.get('q')
c = self.request.get('c')
forward = True if p not in ['prev'] else False
cursor = Cursor(urlsafe=c)
if q:
qry = models.BlogPost.query(ndb.OR(models.BlogPost.title == q.lower(),
models.BlogPost.author == q.lower(),
models.BlogPost.category.IN(q.lower().split(','))))
count = qry.count()
blogs = qry
else:
qry = models.BlogPost.query()
count = qry.count()
PAGE_SIZE = 50
if forward:
blogs, next_cursor, more = qry.order(-models.BlogPost.updated).fetch_page(PAGE_SIZE, start_cursor=cursor)
if next_cursor and more:
self.view.next_cursor = next_cursor
if c:
self.view.prev_cursor = cursor.reversed()
else:
blogs, next_cursor, more = qry.order(models.BlogPost.updated).fetch_page(PAGE_SIZE, start_cursor=cursor)
blogs = list(reversed(blogs))
if next_cursor and more:
self.view.prev_cursor = next_cursor
self.view.next_cursor = cursor.reversed()
def pager_url(p, cursor):
params = OrderedDict()
if q:
params['q'] = q
if p in ['prev']:
params['p'] = p
if cursor:
params['c'] = cursor.urlsafe()
return self.uri_for('admin-blog', **params)
self.view.pager_url = pager_url
self.view.q = q
if self.app.config.get('app_lang') == 'es':
list_columns = [('title', u'Título'), ('author', 'Autor'), ('created', u'Fecha de creación'), ('updated', u'Fecha de actualización'), ('category', u'Categorías')]
else:
list_columns = [('title', u'Title'), ('author', 'Author'), ('created', u'Created'), ('updated', u'Updated'), ('category', u'Categories')]
params = {
"list_columns": list_columns,
"blogs": blogs,
"count": count
}
params['nickname'] = g_users.get_current_user().email().lower()
return self.render_template('%s/blog/admin_blog.html' % self.app.config.get('app_lang'), **params)
示例14: set_cursor
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
示例15: get
def get(self):
p = self.request.get('p')
q = self.request.get('q')
c = self.request.get('c')
forward = True if p not in ['prev'] else False
cursor = Cursor(urlsafe=c)
if q:
qry = models.User.query(ndb.OR(models.User.last_name == q,
models.User.email == q,
models.User.username == q))
else:
qry = models.User.query()
PAGE_SIZE = 5
if forward:
users, next_cursor, more = qry.order(models.User.key).fetch_page(PAGE_SIZE, start_cursor=cursor)
if next_cursor and more:
self.view.next_cursor = next_cursor
if c:
self.view.prev_cursor = cursor.reversed()
else:
users, next_cursor, more = qry.order(-models.User.key).fetch_page(PAGE_SIZE, start_cursor=cursor)
users = list(reversed(users))
if next_cursor and more:
self.view.prev_cursor = next_cursor
self.view.next_cursor = cursor.reversed()
def pager_url(p, cursor):
params = OrderedDict()
if q:
params['q'] = q
if p in ['prev']:
params['p'] = p
if cursor:
params['c'] = cursor.urlsafe()
return self.uri_for('user-list', **params)
self.view.pager_url = pager_url
self.view.q = q
params = {
"list_columns": [('username', 'Username'),
('last_name', 'Last Name'),
('email', 'E-Mail'),
('country', 'Country')],
"users" : users,
"count" : qry.count()
}
# FIXME: admin_user should probably go into BaseHandler
params['admin_user'] = googleusers.is_current_user_admin()
return self.render_template('admin/users.html', **params)