本文整理汇总了Python中google.appengine.ext.db.Key.from_path方法的典型用法代码示例。如果您正苦于以下问题:Python Key.from_path方法的具体用法?Python Key.from_path怎么用?Python Key.from_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.ext.db.Key
的用法示例。
在下文中一共展示了Key.from_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get(self):
user = users.get_current_user()
r = FlowerbedAdd()
if self.request.get('lat') and self.request.get('lon'):
#TODO: check if flowerbed is far enough from others
#TODO: check if flowerbed is close enough to user
lat = int(self.request.get('lat')) / 1000000.0
lon = int(self.request.get('lon')) / 1000000.0
gamer_key = Key.from_path(kloombaDb.Gamer.kind(), user.user_id())
gamer_hash = hashlib.md5(user.user_id() + SALT).hexdigest()
r.timestamp = int(time.time())
#get backpack
bp_beds = GqlQuery('SELECT * FROM Backpack WHERE ANCESTOR IS :1 AND name=:2', gamer_key, 'flowerbed').get()
if bp_beds.amount:
#lower backpack
bp_beds.amount -= 1
bp_beds.put()
#add flowerbed
point = GeoPt(lat, lon)
cell = geocell.compute(point, RULES['GEO_RESOLUTION'])
flowerbed = kloombaDb.Flowerbed(parent=Key.from_path(kloombaDb.Flowerbed.kind(), cell))
flowerbed.point = point
flowerbed.tile = cell
flowerbed.owner = user.user_id()
flowerbed.owner_public_id = gamer_hash
flowerbed.put()
#save to memcache
memcache.set(str(flowerbed.key()), flowerbed)
#add possession
possession = kloombaDb.Possession(parent=gamer_key)
possession.flowerbed = flowerbed
possession.put()
backpack = GqlQuery('SELECT * FROM Backpack WHERE ANCESTOR IS :1', gamer_key).run()
#set timestamps
r.flowerbed.timestamp = int(time.time())
r.backpack.timestamp = int(time.time())
#set flowerbed
r.flowerbed.id = str(flowerbed.key())
r.flowerbed.latitude = int(self.request.get('lat'))
r.flowerbed.longitude = int(self.request.get('lon'))
r.flowerbed.owner = gamer_hash
r.flowerbed.flowers = 0
#set backpack
for i in backpack:
bp = r.backpack.item.add()
bp.name = i.name
bp.amount = i.amount
if self.request.get('debug', False):
self.response.out.write(r)
else:
self.response.out.write(r.SerializeToString())
示例2: post
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def post(self):
model_kind = self.request.get('model_kind')
frequency = self.request.get('frequency')
date = str_to_date(self.request.get('date_string'))
store_key_name = self.request.get('store_key_name')
logging.info('Cleanupworker model kind: %s frequency: \
%s store: %s' %(model_kind,frequency,store_key_name))
recursion_flag = False
if model_kind == 'ProductRenderer':
store_key = Key.from_path('Store',store_key_name)
query = get_renderer_query_for_frequency(frequency, date, store_key)
keys = query.fetch(200, TEMPLATE_PRODUCT_COUNT)
elif model_kind == 'ProductCounter':
store_key = Key.from_path('Store',store_key_name)
query = get_counter_query_for_frequency(frequency, date, store_key)
keys = query.fetch(200)
elif model_kind == 'UserCounter':
query = USER_COUNTER_CLEANUP_TARGETS
keys = query.fetch(200)
else:
logging.error('No type found for CleanupWorker :%s' %model_kind)
if len(keys):
recursion_flag = True
pdb.delete(keys)
if recursion_flag:
logging.info('Enqueing cleanup for model %s' %model_kind)
enqueue_cleanup(model_kind,frequency,str(date),store_key_name)
示例3: get
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get(self):
next = None
PAGESIZE = 30
util.insertUsersideCookies(self)
self.session = True
user = UserInfo()
user.whoIs(self)
bookmark = self.request.get("bookmark")
if bookmark:
bookmark = Key(self.request.get("bookmark"))
else:
if user.user:
bookmark = Key.from_path('MySketchesSketch','-%023d' % (int(user.user_id)) + SKETCH_ZEROS)
else:
bookmark = Key.from_path('MySketchesSketch','-%023d' % (0) + SKETCH_ZEROS)
if user.user:
endKey = Key.from_path('MySketchesSketch','-%023d' % (int(user.user_id) + 1) + SKETCH_ZEROS)
else:
endKey = Key.from_path('MySketchesSketch','-%023d' % (1) + SKETCH_ZEROS)
logging.info('starting key ' + str(bookmark))
logging.info('starting key name' + bookmark.name())
q = db.GqlQuery("SELECT * FROM MySketchesSketch WHERE __key__ >= :1 AND __key__ < :2",bookmark,endKey)
sketches = q.fetch(PAGESIZE+1)
if len(sketches) == PAGESIZE + 1:
next = str(sketches[-1].key())
sketches = sketches[:PAGESIZE]
logging.info('next key ' + next)
logging.info('next key name ' + sketches[-1].key().name())
if next is None:
next = ""
for sketch in sketches:
sketch.stringtags = util.shorten(" ".join(sketch.tags),18)
template_values = {
'sketches':sketches,
'bookmark':bookmark,
'next':next,
'action':"mySketches",
'headerTitle':"My sketches",
}
self.generate('galleryTemplate.html',template_values)
示例4: get
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get(self):
checklist = Checklist.get(Key.from_path('Checklist', long(self.request.get('cl_id'))))
if not helpers.checkPermissionAndRespond(self, cl=checklist): return
if not self.addable(checklist):
helpers.createResponse(self, 'message_can_not_create_item.html')
return
helpers.createResponse(self, 'create_item.html', {'checklist': checklist})
示例5: get_news_item
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get_news_item(id):
if 'uncached' not in request.args:
return get_news_item_cached(id)
key = Key.from_path('NewsItem', str(id))
news_item = NewsItem.get(key)
return Response(json.dumps(news_item.jsonData, default=dthandler), mimetype='application/json')
示例6: post_news_item
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def post_news_item(news_item_id=None):
if not users.is_current_user_admin():
abort(401)
if news_item_id:
key = Key.from_path('NewsItem', str(news_item_id))
news_item = NewsItem.get(key)
news_item.clearTags();
else:
news_item = NewsItem.create()
# TODO: Most of this code can go in the model with a fromJSONData function
news_item.title = request.json['title']
news_item.body = request.json['body']
news_item.draft = request.json['draft']
news_item.posted_date = parser.parse(request.json['posted_date'])
news_item.last_modified_date = parser.parse(request.json['last_modified_date'])
news_item.put();
# Loop through the tags to add them
for tag_name in request.json['tags']:
tag_name = tag_name.strip()
if tag_name == '':
continue
tag = Tag(key_name=tag_name, tag=tag_name)
tag.put()
news_item_tag = NewsItemTag()
news_item_tag.tag = tag.key()
news_item_tag.news_item = news_item.key()
news_item_tag.put()
return Response(json.dumps(news_item.jsonData, default=dthandler), mimetype='application/json')
示例7: post
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def post(self):
cl = Checklist.get(Key.from_path('Checklist', long(self.request.get('cl_id'))))
if not helpers.checkPermissionAndRespond(self, cl=cl, edit=False):
return
user = users.get_current_user()
for sub in Subscription.all().filter("user ==", user).filter("deleted ==", False):
if sub.source.key() == cl.key():
helpers.createResponse(self, 'message_already_subscribed.html',
{'old_checklist': cl})
sub = Subscription(
user=user,
source=cl,
deleted=False,
)
sub.put()
for item in cl.item_set:
subItem = SubscribedItem(
subscription=sub,
original=item,
finished=False,
deleted=False,
)
subItem.put()
helpers.createResponse(self, 'message_subscribed.html')
示例8: post
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def post(self):
user = self.processPostData()
syllabusUnitIds = self.request.get_all('keys')
syllabusUnitKeys = [Key.from_path('SyllabusUnit', int(iid)) for iid in syllabusUnitIds]
user.syllabusUnitKeys = syllabusUnitKeys
user.put()
self.render(user)
示例9: FileKey
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def FileKey(filename, user):
if not user:
u_id = -1
else:
u_id = user.user_id()
return Key.from_path('File', '%s_%s' % (filename, u_id))
示例10: get
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get(self):
str_id = self.request.get('id')
message = self.request.get('message')
if not str_id or not message:
self.response.status_int = 400
self.response.body = "Invalid or missing id and or message."
return
devices = GqlQuery('SELECT * FROM Device WHERE __key__ = :1',
Key.from_path('Device', str_id))
if devices.count() < 1:
self.response.status_int = 404
self.response.body = "Target device not registered."
return
payload = {'registration_ids': [devices.get().token], 'data': {'message': message}}
headers = {'Content-Type': 'application/json',
'Authorization': 'key=' + API_KEY}
result = urlfetch.fetch(url = ANDROID_GCM_URL,
payload = json.dumps(payload),
method = urlfetch.POST,
headers = headers)
self.response.status_int = result.status_code
self.response.body = result.content
示例11: get
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get(self, **args):
cl = Checklist.get(Key.from_path("Checklist", long(args['id'])))
if not cl or cl.deleted:
helpers.createResponse(self, 'message_not_exist.html')
return
if not helpers.checkPermissionAndRespond(self, cl=cl, edit=False): return
item_q = cl.item_set.filter("deleted ==", False).order("creation_time")
cursor = self.request.get('cursor')
if cursor:
item_q = item_q.with_cursor(cursor)
items = item_q.fetch(20)
user = users.get_current_user()
subscribed = False
for sub in Subscription.all().filter("user ==", user).filter("deleted ==", False):
if sub.source.key() == cl.key():
subscribed = True
break
helpers.createResponse(self, 'dashboard_subscribe.html',
{'items': items,
'cl': cl,
'cursor_item': item_q.cursor(),
'subscribed': subscribed,
},
)
示例12: get
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get(self):
mcode = self.request.get('mcode')
lcode = self.request.get('lcode')
q=Lecturer.all()
q.filter('__key__ =', Key.from_path('Lecturer', lcode))
lecturers = q.get()
self.response.write('Lecturer with code "'+lcode+'" is called "'+lecturers.full_name+'"')
q = Module.all()
q.filter('__key__ = ', Key.from_path('Module',mcode))
modules = q.get()
self.response.write('<br/>Module with code "'+modules.code+'" has title "'+modules.title+'"')
Rating(module=modules, lecturer =lecturers).put()
self.response.write('<br/> Rating probably put successfully')
示例13: get
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get(self, **args):
cl = Checklist.get(Key.from_path("Checklist", long(args['id'])))
if not cl or cl.deleted:
helpers.createResponse(self, 'message_not_exist.html')
return
if not helpers.checkPermissionAndRespond(self, cl=cl, edit=False): return
item_q = cl.item_set.filter("deleted ==", False).order("creation_time")
cursor = self.request.get('cursor_item')
if cursor:
item_q = item_q.with_cursor(cursor)
items = item_q.fetch(20)
subs = []
for sub in cl.subscription_set:
subs.append(sub)
cursor_item = item_q.cursor()
item_q = item_q.with_cursor(cursor_item)
helpers.createResponse(self, 'dashboard_items.html',
{'items': items,
'cl': cl,
'cursor_item': cursor_item,
'more_items': item_q.count(1) == 1,
'subs': subs,
})
示例14: make_db_key
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def make_db_key(key):
path = reduce(
operator.add,
(('Slot', '/'.join(key[:i + 1])) for i in range(len(key))),
()
)
return Key.from_path(*path)
示例15: get
# 需要导入模块: from google.appengine.ext.db import Key [as 别名]
# 或者: from google.appengine.ext.db.Key import from_path [as 别名]
def get(self):
r = BookmarkRemove()
if not self.request.get('id'):
return
fb_key = self.request.get('id')
user = users.get_current_user()
gamer_key = Key.from_path(kloombaDb.Gamer.kind(), user.user_id())
#get bookmark
bookmark = GqlQuery('SELECT * FROM Bookmark WHERE ANCESTOR IS :1 AND flowerbed=:2', gamer_key, Key(fb_key)).get()
if not bookmark:
return
bookmark.delete()
r.timestamp = int(time.time())
r.id = fb_key
if self.request.get('debug', False):
self.response.out.write(r)
else:
self.response.out.write(r.SerializeToString())