本文整理汇总了Python中app.needs.Need.api_response方法的典型用法代码示例。如果您正苦于以下问题:Python Need.api_response方法的具体用法?Python Need.api_response怎么用?Python Need.api_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.needs.Need
的用法示例。
在下文中一共展示了Need.api_response方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import api_response [as 别名]
def put(self, key):
"""
The PUT HTTP method
"""
obj = self.model.get_by_id(key)
if not obj:
return create_api_response(404, "{resource} {key} not found".format(
resource=self.name, key=key))
need = Need('get')
if not obj.can(session['user'], need, obj):
return need.api_response()
need = Need('put')
if not obj.can(session['user'], need, obj):
return need.api_response()
blank_val = object()
changed = False
for key, value in self.parse_args(False).iteritems():
old_val = getattr(obj, key, blank_val)
if old_val == blank_val:
return create_api_response(
400, "{} is not a valid field.".format(key))
setattr(obj, key, value)
changed = True
if changed:
obj.put()
return create_api_response(200, "", obj)
示例2: index
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import api_response [as 别名]
def index(self):
"""
Index HTTP method. Should be called from GET when no key is provided.
Processes cursor and num_page URL arguments for pagination support.
"""
query = self.model.query()
need = Need('index')
result = self.model.can(session['user'], need, query=query)
if not result:
return need.api_response()
args = self.parse_args(True)
query = filter_query(result, args, self.model)
created_prop = getattr(self.model, 'created', None)
if not query.orders and created_prop:
logging.info("Adding default ordering by creation time.")
query = query.order(-created_prop)
page = int(request.args.get('page', 1))
num_page = request.args.get('num_page', None)
query_results = paginate(query, page, num_page)
add_statistics = request.args.get('stats', False)
if add_statistics:
query_results['statistics'] = self.statistics()
return create_api_response(200, "success", query_results)
示例3: delete
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import api_response [as 别名]
def delete(self, user_id):
"""
The DELETE HTTP method
"""
ent = self.model.query.get(user_id)
need = Need('delete')
if not self.model.can_static(session['user'], need):
return need.api_response()
ent.key.delete()
return create_api_response(200, "success", {})
示例4: get
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import api_response [as 别名]
def get(self, key):
"""
The GET HTTP method
"""
obj = self.model.get_by_id(key)
if not obj:
return create_api_response(404, "{resource} {key} not found".format(
resource=self.name, key=key))
need = Need('get')
if not obj.can(session['user'], need, obj):
return need.api_response()
return create_api_response(200, "", obj)
示例5: post
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import api_response [as 别名]
def post(self):
"""
The POST HTTP method
"""
data = self.parse_args(False)
need = Need('create')
if not self.model.can(session['user'], need):
return need.api_response()
entity, error_response = self.new_entity(data)
if not error_response:
return create_api_response(200, "success", {
'key': entity.key.id()
})
else:
return error_response
示例6: download
# 需要导入模块: from app.needs import Need [as 别名]
# 或者: from app.needs.Need import api_response [as 别名]
def download(self, key):
"""
Allows you to download a submission.
"""
obj = self.model.get_by_id(key)
if not obj:
return create_api_response(404, "{resource} {key} not found".format(
resource=self.name, key=key))
need = Need('get')
if not obj.can(session['user'], need, obj):
return need.api_response()
if 'file_contents' not in obj.messages:
return create_api_response(400,
"Submissions has no contents to download.")
response = make_response(create_zip(obj.messages['file_contents']))
response.headers["Content-Disposition"] = (
"attachment; filename=submission-%s.zip" % str(obj.created))
response.headers["Content-Type"] = "application/zip"
return response