本文整理汇总了Python中models.Location.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Location.get_by_key_name方法的具体用法?Python Location.get_by_key_name怎么用?Python Location.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Location
的用法示例。
在下文中一共展示了Location.get_by_key_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import get_by_key_name [as 别名]
def get(self, loc_key, level):
l = Location.get_by_key_name(loc_key)
if not l:
self.redirect('/')
elif self.has_submitted_recently():
self.redirect('/whoops')
else:
if not level:
self.render('comfort/index', location=str(l))
else:
try:
level_int = int(level)
c = Comfort.create(level_int, str(l))
if c:
self.record_comfort(c)
except ValueError:
self.redirect('/')
示例2: post
# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import get_by_key_name [as 别名]
def post(self):
rooms_to_delete = json.loads(self.request.body)
if not rooms_to_delete:
self.redirect('/rooms')
return
locations = [Location.get_by_key_name(room) for room in rooms_to_delete]
comforts = [c for c in Comfort.all()]
for location in locations:
comforts_to_remove = filter(lambda c: c.loc_building == location.building and \
c.loc_floor == location.floor and \
c.loc_room == location.room,
comforts)
db.delete(comforts_to_remove)
db.delete(location)
memcache.delete(MC_LOCATIONS_KEY)