本文整理匯總了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())