本文整理汇总了Python中models.Place.to_json方法的典型用法代码示例。如果您正苦于以下问题:Python Place.to_json方法的具体用法?Python Place.to_json怎么用?Python Place.to_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Place
的用法示例。
在下文中一共展示了Place.to_json方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import to_json [as 别名]
def get(self):
user_id = logic.get_current_userid(self.request.cookies.get('user'))
if user_id is None:
self.redirect('/')
return
user, status, errcode = logic.user_get(user_id, None)
if status != "OK":
self.render("error.html", {'error_code': errcode, 'error_string': status, 'lang': LANG})
return
get_values = self.request.GET
if not get_values:
if user.role != 'admin':
self.redirect('/error')
else:
self.render('restaurant_list_edit.html',{'user': user, 'lang' : LANG});
else:
place_key = get_values.get('id')
place, status, errcode = logic.place_get(None, place_key)
if status == 'OK':
try:
place = Place.to_json(place, None, None)
self.render('restaurant_edit.html', {'place': place, 'hours_string': json.dumps(place['hours']), 'closed': json.dumps(place['days_closed']), 'user': user, 'lang' : LANG });
except TypeError, e:
# TODO: handle error
self.render("error.html", {'error_code': 500, 'error_string': str(e), 'lang': LANG})
return
else:
示例2: get
# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import to_json [as 别名]
def get(self, pid):
if 'owner' in self.request.url:
self.response.set_status(405)
return
logging.info("Received get place : " + str(pid))
place, status, errcode = logic.place_get(None, pid)
if status == "OK":
try:
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps(Place.to_json(place, None,None)))
except TypeError, e:
self.response.set_status(500)
self.response.write(str(e))
示例3: PlaceHandler
# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import to_json [as 别名]
try:
place = Place.from_json(body)
except TypeError, e:
self.response.set_status(400)
self.response.write(str(e))
return
except Exception, e:
self.response.set_status(400)
self.response.write(str(e))
return
place, status, errcode = logic.place_create(place)
if status == "OK":
try:
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps(Place.to_json(place, None, None)))
except TypeError, e:
self.response.set_status(500)
self.response.write(str(e))
else:
self.response.set_status(errcode)
self.response.write(status)
class PlaceHandler(webapp2.RequestHandler):
def get(self, pid):
if 'owner' in self.request.url:
self.response.set_status(405)
return
logging.info("Received get place : " + str(pid))