本文整理汇总了Python中pyramid.renderers.render_to_response函数的典型用法代码示例。如果您正苦于以下问题:Python render_to_response函数的具体用法?Python render_to_response怎么用?Python render_to_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_to_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sample16
def sample16(request):
clientId = request.POST.get('clientId')
privateKey = request.POST.get('privateKey')
inputFile = request.POST.get('file')
url = request.POST.get('url')
basePath = request.POST.get('basePath')
fileId = request.POST.get('fileId')
guid = None
iframe = None
# Checking required parameters
if not clientId or not privateKey:
return render_to_response('__main__:templates/sample16.pt',
dict(error='You do not enter all parameters'))
### Create Signer, ApiClient and Annotation Api objects
# Create signer object
signer = GroupDocsRequestSigner(privateKey)
# Create apiClient object
apiClient = ApiClient(signer)
# Create Storage object
api = StorageApi(apiClient)
if not basePath:
basePath = 'https://api.groupdocs.com/v2.0'
#Set base path
api.basePath = basePath
if url:
try:
# Upload file to current user storage using entered URl to the file
upload = api.UploadWeb(clientId, url)
guid = upload.result.guid
fileId = None
except Exception, e:
return render_to_response('__main__:templates/sample16.pt',
dict(error=str(e)))
示例2: sample15
def sample15(request):
clientId = request.POST.get("client_id")
privateKey = request.POST.get("private_key")
# Checking required parameters
if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
return render_to_response("__main__:templates/sample15.pt", {"error": "You do not enter all parameters"})
### Create Signer, ApiClient, StorageApi and Document Api objects
# Create signer object
signer = GroupDocsRequestSigner(privateKey)
# Create apiClient object
apiClient = ApiClient(signer)
# Create DocApi object
doc = DocApi(apiClient)
# set total views
views = 0
try:
# Make a request to Document API
response = doc.GetDocumentViews(clientId)
if response.status == "Ok":
views = len(response.result.views)
except Exception, e:
return render_to_response("__main__:templates/sample15.pt", {"error": str(e)})
示例3: read_one_public
def read_one_public(request):
"""
Read one Stakeholder based on ID and return all versions of this
Stakeholder. Do not return any pending versions.
Default output format: JSON
"""
try:
output_format = request.matchdict['output']
except KeyError:
output_format = 'json'
uid = request.matchdict.get('uid', None)
if check_valid_uuid(uid) is not True:
raise HTTPNotFound()
if output_format == 'json':
stakeholders = stakeholder_protocol3.read_one(request, uid=uid,
public=True)
return render_to_response('json', stakeholders, request)
elif output_format == 'html':
#@TODO
return render_to_response('json', {'HTML': 'Coming soon'}, request)
else:
# If the output format was not found, raise 404 error
raise HTTPNotFound()
示例4: sample13
def sample13(request):
clientId = request.POST.get('client_id')
privateKey = request.POST.get('private_key')
fileGuId = request.POST.get('fileId')
email = request.POST.get('email')
# Checking required parameters
if IsNotNull(clientId) == False or IsNotNull(privateKey) == False or IsNotNull(fileGuId) == False or IsNotNull(email) == False:
return render_to_response('__main__:templates/sample13.pt',
{ 'error' : 'You do not enter all parameters' })
### Create Signer, ApiClient and Annotation Api objects
# Create signer object
signer = GroupDocsRequestSigner(privateKey)
# Create apiClient object
apiClient = ApiClient(signer)
# Create Annotation object
ant = AntApi(apiClient)
try:
# Make a request to Annotation API
ant.SetAnnotationCollaborators(clientId, fileGuId, "v2.0", body=[email])
except Exception, e:
return render_to_response('__main__:templates/sample13.pt',
{ 'error' : str(e) })
示例5: test_registerTemplateRenderer_explicitrenderer
def test_registerTemplateRenderer_explicitrenderer(self):
from pyramid import testing
def renderer(kw, system):
self.assertEqual(kw, {'foo':1, 'bar':2})
renderer = testing.registerTemplateRenderer('templates/foo', renderer)
from pyramid.renderers import render_to_response
render_to_response('templates/foo', dict(foo=1, bar=2))
示例6: sample12
def sample12(request):
clientId = request.POST.get('clientId')
privateKey = request.POST.get('privateKey')
fileGuId = request.POST.get('fileId')
# Checking required parameters
if not clientId or not privateKey or not fileGuId:
return render_to_response('__main__:templates/sample12.pt',
dict(error='You do not enter all parameters'))
### Create Signer, ApiClient and Annotation Api objects
# Create signer object
signer = GroupDocsRequestSigner(privateKey)
# Create apiClient object
apiClient = ApiClient(signer)
# Create Annotation object
ant = AntApi(apiClient)
try:
# Make a request to Annotation API using clientId and fileGuId
response = ant.ListAnnotations(clientId, fileGuId)
except Exception, e:
return render_to_response('__main__:templates/sample12.pt',
dict(error=str(e)))
示例7: render_page
def render_page(self, section, redirpath, values=None):
if self.endpath is None:
return HTTPFound(
location=route_url(
'subsections',
self.request,
action=section,
endpath='/'.join(redirpath)
))
self.c.active_footer_nav = '-'.join(
[self.request.matchdict.get('action')]
+list(self.endpath))
for ext in ('.mako', '.rst'):
tmpl_path = ('templates/pages/%s/%s%s' % (
section,
'/'.join(self.endpath),
ext))
values = values or {}
if pkg_resources.resource_exists('pylonshq', tmpl_path):
if ext == '.mako':
return render_to_response(
'pylonshq:%s' % tmpl_path, values, self.request)
else:
self.c.pagename = ' : '.join(
[item.replace('-', ' ').title() for item in self.endpath])
content = pkg_resources.resource_string(
'pylonshq',
tmpl_path)
body = publish_parts(
content,
writer_name='html')['html_body']
values={'body':body}
return render_to_response(
'pylonshq:templates/rst.mako', values, self.request)
raise NotFound()
示例8: login_form_process
def login_form_process(self):
"""Process login form.
Render form if attempt_authorize was failed
and redirect to root '/' of site.
Return form in 'form' key.
@todo redirect to request_from url
@todo process csrf value"""
schema = AuthSchema()
form = Form(schema, buttons=('submit',))
if 'submit' in self.request.POST:
controls = self.request.POST.items()
values = None
try:
appstruct = form.validate(controls)
except ValidationFailure, e:
return render_to_response(
'templates/auth_form.jinja2',
{'form': e.render()}
)
# make here call of attempt_login
if self.user_helper.attempt_authorize(
appstruct['login'],
appstruct['password']):
remember(self.request, appsctruct['login'])
return HTTPFound("/")
else:
return render_to_response(
'templates/auth_form.jinja2',
{'form':form.render(appstruct=appstruct)}
)
return HTTPFound('/')
示例9: sample32
def sample32(request):
clientId = request.POST.get('client_id')
privateKey = request.POST.get('private_key')
formGuid = request.POST.get('form_guid')
templateGuid = request.POST.get('template_guid')
callbackUrl = request.POST.get('callbackUrl')
basePath = request.POST.get('server_type')
email = request.POST.get('email')
message = ""
# Checking clientId, privateKey and file_Id
if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
return render_to_response('__main__:templates/sample32.pt',
{ 'error' : 'You do not enter all parameters' })
#Get curent work directory
currentDir = os.path.dirname(os.path.realpath(__file__))
#Create text file
fp = open(currentDir + '/../user_info.txt', 'w')
#Write user info to text file
fp.write(clientId + "\r\n" + privateKey + "\r\n" + email)
fp.close()
####Create Signer, ApiClient and Storage Api objects
#Create signer object
signer = GroupDocsRequestSigner(privateKey)
#Create apiClient object
apiClient = ApiClient(signer)
#Create Storage Api object
signatureApi = SignatureApi(apiClient)
#Set base Path
if basePath == "":
basePath = "https://api.groupdocs.com/v2.0"
signatureApi.basePath = basePath
#Create webHook and set callback URL
webHook = WebhookInfo()
webHook.callbackUrl = callbackUrl
####Make a request to Signature API using clientId
if formGuid != "":
try:
#Post form by entered form GUID
postForm = signatureApi.PublishSignatureForm(clientId, formGuid, body=webHook)
if postForm.status == "Ok":
message = '<font color="green">Form is published successfully</font>'
#Generate iframe url
if basePath == "https://api.groupdocs.com/v2.0":
iframe = 'https://apps.groupdocs.com/signature2/forms/signembed/' + formGuid
#iframe to dev server
elif basePath == "https://dev-api.groupdocs.com/v2.0":
iframe = 'https://dev-apps.groupdocs.com/signature2/forms/signembed/' + formGuid
#iframe to test server
elif basePath == "https://stage-apps-groupdocs.dynabic.com/v2.0":
iframe = 'https://stage-apps-groupdocs.dynabic.com/signature2/forms/signembed/' + formGuid
elif basePath == "http://realtime-api.groupdocs.com":
iframe = 'https://relatime-apps.groupdocs.com/signature2/forms/signembed/' + formGuid
iframe = signer.signUrl(iframe)
else:
raise Exception(postForm.error_message)
except Exception, e:
return render_to_response('__main__:templates/sample32.pt',
{ 'error' : str(e) })
示例10: view
def view(request):
project = get_selected_project(request)
error_id = request.matchdict['id']
try:
error = Error.objects(project=project.token, id=error_id).get()
except:
return HTTPNotFound()
error.mark_seen(request.user)
error.save()
instances = ErrorInstance.objects(hash=error.hash)[:10]
params = {
'error': error,
'selected_project': project,
'available_projects': Project.objects(),
'instances': instances,
'github': GithubLinker(project.github)
}
try:
template = 'error-view/' + str(error['language']).lower() + '.html'
return render_to_response(template, params)
except:
template = 'error-view/generic.html'
return render_to_response(template, params)
示例11: index
def index(request):
if request.method == "POST" and 'username' in request.cookies:
username = request.cookies['username']
# TODO process request
wishlist = []
for key,value in request.POST.items():
if key.startswith("wish-"):
wishlist.append(NAME2WISH[key[5:]])
print("wish={}, value={}".format(key[5:], value))
special = request.params["special"]
bequick = request.params["bequick"]
print(u"special={}, be quick={}".format(special,bequick))
order = Order(username,request.remote_addr,wishlist,special,bequick)
ORDERS[order.id] = order
return HTTPFound(location = "/confirm/{}".format(order.id))
else:
if 'username' in request.cookies:
username = request.cookies['username']
response = render_to_response("pt/index.pt", { "username" : username, "wishbar" : WISHBAR }, request)
response.set_cookie('username', value=username, max_age=86400)
return response
else:
return render_to_response('pt/login.pt', {}, request)
示例12: sample03
def sample03(request):
clientId = request.POST.get('client_id')
privateKey = request.POST.get('private_key')
inputFile = request.POST.get('file')
# Checking clientId and privateKey
if IsNotNull(clientId) == False or IsNotNull(privateKey) == False:
return render_to_response('__main__:templates/sample03.pt',
{ 'error' : 'You do not enter your User Id or Private Key' })
####Create Signer, ApiClient and Storage Api objects
#Create signer object
signer = GroupDocsRequestSigner(privateKey)
#Create apiClient object
apiClient = ApiClient(signer)
#Create Storage Api object
api = StorageApi(apiClient)
try:
#A hack to get uploaded file size
inputFile.file.seek(0, 2)
fileSize = inputFile.file.tell()
inputFile.file.seek(0)
fs = FileStream.fromStream(inputFile.file, fileSize)
####Make a request to Storage API using clientId
#Upload file to current user storage
response = api.Upload(clientId, inputFile.filename, fs)
#Generation of Embeded Viewer URL with uploaded file GuId
iframe = '<iframe src="https://apps.groupdocs.com/document-viewer/embed/' + response.result.guid + '" frameborder="0" width="720" height="600""></iframe>'
message = '<p>File was uploaded to GroupDocs. Here you can see your <strong>' + inputFile.filename + '</strong> file in the GroupDocs Embedded Viewer.</p>'
except Exception, e:
return render_to_response('__main__:templates/sample03.pt',
{ 'error' : str(e) })
示例13: notallowed
def notallowed(request):
auth_userid = authenticated_userid(request)
if auth_userid is None:
login = LoginView(request)
if request.method == 'POST':
# Process the login form and redirect
view_method = login.post
else:
# User is not logged in, render the login form
view_method = login.get
response = view_method()
# We need to commit the transaction, so that details about
# the forbidden view can be written to the database
transaction.commit()
if isinstance(response, Response):
return response
else:
return render_to_response("speak_friend:templates/login.pt",
response,
request=request)
else:
# If the user is logged in, they don't have permission
return render_to_response("speak_friend:templates/403_template.pt",
{},
request=request)
示例14: model
def model(self, request):
"""
The method which is used by the api to deliver a machine readable and serializable description of the underlying
database table/model.
:param request: The request which comes all the way through the application from the client
:type request: pyramid.request.Request
:param session: The session which is uesed to emit the query.
:type session: sqlalchemy.orm.Session
:return: An pyramid response object
:rtype: pyramid.response.Response
:raises: HTTPNotFound
"""
response_format = request.matchdict['format']
if response_format == 'json':
return render_to_response(
'model_restful_json',
self.model_description,
request=request
)
elif response_format == 'xml':
return render_to_response(
'model_restful_xml',
self.model_description,
request=request
)
else:
text = 'The Format "{format}" is not defined for this service. Sorry...'.format(
format=response_format
)
log.error(text)
raise HTTPNotFound(
detail=text
)
示例15: picked
def picked(request):
g = request.registry.settings.get('graph')
action = request.matchdict.get('action')
format_ = request.matchdict.get('format_')
def pickedgraph():
graph = rdflib.Graph()
for x in request.session["picked"]:
graph += g.triples((x, None, None))
graph += g.triples((None, None, x))
return graph
if action == 'download':
return serialize(pickedgraph(), format_)
elif action == 'rdfgraph':
return graphrdf(pickedgraph(), format_)
elif action == 'rdfsgraph':
return graphrdfs(pickedgraph(), format_)
elif action == 'clear':
request.session["picked"] = set()
return render_to_response(
"picked.jinja2", dict(things=[]), request)
else:
things = [resolve(x) for x in request.session["picked"]]
return render_to_response(
"picked.jinja2", dict(things=things), request)