本文整理汇总了Python中pyramid.response.Response.status_int方法的典型用法代码示例。如果您正苦于以下问题:Python Response.status_int方法的具体用法?Python Response.status_int怎么用?Python Response.status_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.status_int方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forbidden_view
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def forbidden_view(context, request):
user = authenticated_userid(request)
if user is not None:
try:
reason = context.explanation
except AttributeError:
reason = 'unknown'
logger.debug("User %s tripped Forbidden view, request %s, "
"reason %s"%(str(user), str(request), str(reason)))
if request.db.settings.find_one({'key':'maintenance_mode'}).get('value', False):
msg = request.db.settings.find_one({'key':'maintenance_message'})
if msg is not None:
msg = msg['value']
response = Response(render('templates/maintenance.jinja2', {'request': request,'maintenance_msg': msg}))
request.session.delete()
response.status_int = 200
else:
response = Response(render('templates/forbidden.jinja2', {}))
response.status_int = 403
return response
if user is None and (request.is_xhr or request.headers.get('content-type') == 'application/json'):
response = Response(render('templates/forbidden.jinja2', {}))
response.status_int = 403
return response
logger.debug("No user and forbidden access! --> redirect to login")
loginurl = request.route_url('login', _query=(('next', request.path),))
return HTTPFound(location=loginurl)
示例2: inline_edit
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def inline_edit(request):
print(request.POST)
pk = int(request.POST.get("pk"))
name = request.POST.get("name")
value = request.POST.get("value")
name_to_be_edited = names.get(pk)
form = NameForm(obj=name_to_be_edited)
field = getattr(form, name)
field.process_formdata([value]) # change the value of the field
if form.validate(): # the change was good!
setattr(name_to_be_edited, name, value)
# session.commit() # in ORM you'd commit the change!
response = Response()
return response # 200 OK tells X-Editable everything worked
else: # change was bad!
# Since validation failed, no change is made!
response = Response()
response.status_int = 422 # Unprocessable Entity is most-correct
errors = []
for error_key in form.errors.keys():
errors.extend(map(lambda x: error_key + x, form.errors[error_key]))
response.text = "\n".join(errors)
return response
示例3: upload_files
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def upload_files(request):
"""uploads a list of files to the server, creates Link instances in server
and returns the created link ids with a response to let the front end
request a linkage between the entity and the uploaded files
"""
# decide if it is single or multiple files
file_params = request.POST.getall('file')
logger.debug('file_params: %s ' % file_params)
try:
new_links = upload_files_to_server(request, file_params)
except IOError as e:
c = StdErrToHTMLConverter(e)
response = Response(c.html())
response.status_int = 500
transaction.abort()
return response
else:
# store the link object
DBSession.add_all(new_links)
logger.debug('created links for uploaded files: %s' % new_links)
return {
'link_ids': [link.id for link in new_links]
}
示例4: forbidden_view
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def forbidden_view(context, request):
"""
View to trap all Forbidden errors and redirect any not logged in users to the login page.
For logged in users, a template is rendered - this template probably won't be seen
by the user though since there is Javascript handling 401 errors from form posts
showing a small pop-up error message instead.
:param context: Some object like HTTPForbidden()
:param request: Request() object
:return:
"""
user = authenticated_userid(request)
if user:
# Return a plain forbbiden page
try:
reason = context.explanation
except AttributeError:
reason = 'unknown'
log.debug("User {!r} tripped Forbidden view, request {!r}, reason {!r}".format(
user, request, reason))
response = Response(render('templates/forbidden.jinja2', {}))
response.status_int = 401
return response
loginurl = request.route_url('saml2-login',
_query=(('next', request.path),))
if not request.is_xhr:
return HTTPFound(location=loginurl)
else:
return HTTPXRelocate(loginurl)
示例5: failed_conversion
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def failed_conversion(exc, request):
# If the view has two formal arguments, the first is the context.
# The context is always available as ``request.context`` too.
filetype = exc.args[0] if exc.args else ""
response = Response('Failed conversion: file of type %s could not be converted. A common cause is a table of contents or other automated index. Remove this from your file, save, and try again.' %filetype)
response.status_int = 500
return response
示例6: failed_validation
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def failed_validation(exc, request):
response = Response(json.dumps({'success': False, 'error': str(exc)}))
response.status_int = 500
log.error(traceback.format_exc())
return response
示例7: delete_reference
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def delete_reference(request):
"""deletes the reference with the given ID
"""
ref_id = request.matchdict.get('id')
ref = Link.query.get(ref_id)
files_to_remove = []
if ref:
original_filename = ref.original_filename
# check if it has a thumbnail
if ref.thumbnail:
# remove the file first
files_to_remove.append(ref.thumbnail.full_path)
# delete the thumbnail Link from the database
DBSession.delete(ref.thumbnail)
# remove the reference itself
files_to_remove.append(ref.full_path)
# delete the ref Link from the database
# IMPORTANT: Because there is no link from Link -> Task deleting a Link
# directly will raise an IntegrityError, so remove the Link
# from the associated Task before deleting it
from stalker import Task
for task in Task.query.filter(Task.references.contains(ref)).all():
logger.debug('%s is referencing %s, '
'breaking this relation' % (task, ref))
task.references.remove(ref)
DBSession.delete(ref)
# now delete files
for f in files_to_remove:
# convert the paths to system path
f_system = convert_file_link_to_full_path(f)
try:
os.remove(f_system)
except OSError:
pass
response = Response('%s removed successfully' % original_filename)
response.status_int = 200
return response
else:
response = Response('No ref with id : %i' % ref_id)
response.status_int = 500
transaction.abort()
return response
示例8: unknown_failure
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def unknown_failure(request, exc):
#import traceback
logger.exception('unknown failure')
#msg = exc.args[0] if exc.args else ""
#response = Response('Ooops, something went wrong: %s' % (traceback.format_exc()))
response = Response('Ooops, something went wrong. Check the log files.')
response.status_int = 500
return response
示例9: error_response
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def error_response (err) :
if err !=None :
msg = err.args[0] if err.args else ""
response=Response('Problem occurs : '+str(type(err))+' = '+msg)
else :
response=Response('No induvidual equiped')
response.status_int = 500
return response
示例10: json_exception_view
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def json_exception_view(exc, request):
s = json.dumps({
"status": exc.status,
"message": exc.message,
})
response = Response(s)
response.status_int = exc.code
return response
示例11: toolbar_handler
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def toolbar_handler(request):
root_path = request.route_path("debugtoolbar.root")
request.exc_history = exc_history
remote_addr = request.remote_addr
if request.path.startswith(root_path) or (not remote_addr in hosts):
return handler(request)
toolbar = DebugToolbar(request, panel_classes)
request.debug_toolbar = toolbar
_handler = handler
for panel in toolbar.panels:
_handler = panel.wrap_handler(_handler)
try:
response = _handler(request)
except Exception:
info = sys.exc_info()
if exc_history is not None:
tb = get_traceback(info=info, skip=1, show_hidden_frames=False, ignore_system_exceptions=True)
for frame in tb.frames:
exc_history.frames[frame.id] = frame
exc_history.tracebacks[tb.id] = tb
body = tb.render_full(request, evalex=True).encode("utf-8", "replace")
response = Response(body, status=500)
toolbar.process_response(response)
return response
raise
else:
if intercept_redirects:
# Intercept http redirect codes and display an html page with a
# link to the target.
if response.status_int in redirect_codes:
redirect_to = response.location
redirect_code = response.status_int
if redirect_to:
content = render(
"pyramid_debugtoolbar:templates/redirect.jinja2",
{"redirect_to": redirect_to, "redirect_code": redirect_code},
)
content = content.encode(response.charset)
response.content_length = len(content)
response.location = None
response.app_iter = [content]
response.status_int = 200
toolbar.process_response(response)
return response
finally:
# break circref
del request.debug_toolbar
示例12: generic_error
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def generic_error(exc, request):
response = Response('Unexpected API response error: %s' % exc.msg)
response.status_int = 500
return response
#@view_config(context=Exception)
#def catchall_error(exc, request):
# response = Response('Unexpected error')
# response.status_int = 500
# return response
示例13: error_view
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def error_view(exc, request):
_, _, tb = sys.exc_info()
traceback.print_tb(tb) # Fixed format
tb_info = traceback.extract_tb(tb)
filename, line, func, text = tb_info[-1]
log.error('An error occurred on line {} in statement {}'.format(line, text))
msg = exc.args[0] if exc.args else ""
response = Response('Server Error: %s' % msg)
response.status_int = 500
return response
示例14: forbidden_view
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def forbidden_view(context, request):
user = authenticated_userid(request)
if user is not None:
try:
reason = context.explanation
except AttributeError:
reason = 'unknown'
logger.debug("User %s tripped Forbidden view, request %s, "
"reason %s"%(str(user), str(request), str(reason)))
response = Response(render('templates/forbidden.jinja2', {}))
response.status_int = 403
return response
if user is None and (request.is_xhr or request.headers.get('content-type') == 'application/json'):
response = Response(render('templates/forbidden.jinja2', {}))
response.status_int = 403
return response
logger.debug("No user and forbidden access! --> redirect to login")
loginurl = request.route_url('login', _query=(('next', request.path),))
return HTTPFound(location=loginurl)
示例15: forbidden_view
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_int [as 别名]
def forbidden_view(context, request):
user = authenticated_userid(request)
if user is not None:
try:
reason = context.explanation
except AttributeError:
reason = 'unknown'
logger.debug("User {!r} tripped Forbidden view, request {!r}, "
"reason {!r}".format(user, request, reason))
response = Response(render('templates/forbidden.jinja2', {}))
response.status_int = 403
return response
if user is None and request.is_xhr:
response = Response(render('templates/forbidden.jinja2', {}))
response.status_int = 403
return response
loginurl = request.route_url('login', _query=(('next', request.path),))
return HTTPFound(location=loginurl)