本文整理汇总了Python中models.Movie.decode方法的典型用法代码示例。如果您正苦于以下问题:Python Movie.decode方法的具体用法?Python Movie.decode怎么用?Python Movie.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Movie
的用法示例。
在下文中一共展示了Movie.decode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: callback_post
# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import decode [as 别名]
def callback_post():
LOGGER.info('Logging Request: METHOD: ' + request.method + ' => ROUTE: /api/movies')
response.set_header('Date', DATETIMESTAMP)
try:
accept = request.headers.get('Accept')
response.set_header('Content-Type', determine_response_content_type(accept))
if 'application/json' not in request.headers.get(
'Content-Type') and 'application/vnd.collection+json' not in request.headers.get('Content-Type'):
LOGGER.error('Unsupported media type sent')
response.status = 415
response_body = ErrorCJ(ROOT, 'Invalid Content-Type', 415,
'application/json and application/vnd.collection+json supported')
return response_body.to_json()
request_json = json_loads(request._get_body_string())
if not request_json:
raise Exception
# debug
# print request_json
# connect to mongodb
mongoengine.connect('api')
movie_dict = dict()
for item in request_json["template"]["data"]:
movie_dict[item["name"]] = item["value"]
# new movie
movie = Movie()
movie.sysid = str(uuid.uuid4()).replace("-", "")
movie.created_on = datetime.datetime.now
movie.updated_on = datetime.datetime.now
movie.decode(movie_dict)
movie.save()
# send the response
response.set_header('Location', ROOT + 'movies/' + movie.sysid)
response.status = 201
movie = None
return
except Exception as e:
LOGGER.error('Unexpected exception ' + str(e))
response.status = 500
response_body = ErrorCJ(ROOT, 'Error Title', 500, str(e))
return response_body.to_json()