本文整理汇总了Python中models.Album.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Album.to_dict方法的具体用法?Python Album.to_dict怎么用?Python Album.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Album
的用法示例。
在下文中一共展示了Album.to_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import to_dict [as 别名]
def post(self):
"""POST handler for gallery albums.
URL pattern: /albums
POST data must contain album metadata: 'name'.
Returns 201 CREATED with JSON data structure describing new album.
Returns Content-type: application/json.
Also returns Location header pointing to API URL for album details.
Include 'wrapjson' parameter in POST to wrap returned JSON in
a <textarea>. This also changes the returned Content-type to text/html.
If request is poorly formatted returns 400 BAD REQUEST.
Returns 401 UNAUTHORIZED to all calls if authorization fails.
"""
try:
data = dict(((str(k), v) for k, v in self.request.POST.items()))
album = Album(album_id=config.ALBUM_ID_GENERATOR(),
**data)
except:
data = {}
self.error(400)
else:
if not config.DEMO_MODE:
album.put()
data = album.to_dict()
self.response.headers['Location'] = data['url']
self.response.set_status(201)
write_json(self, data, wrapjson='wrapjson' in self.request.POST)
示例2: post
# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import to_dict [as 别名]
def post(self):
if not self.has_permission:
return
user = self.current_user
name = self.get_argument('name', None)
name = strip_tags(name)
if not name:
return self.send_error_result(msg=u'没有填写专辑名')
if len(name) >= 10:
return self.send_error_result(msg=u'专辑名不能超过 10 个字符')
album = Album(name=name, user_id=user.id).save()
return self.send_success_result(data=album.to_dict())