本文整理汇总了Python中twisted.web.template.renderElement函数的典型用法代码示例。如果您正苦于以下问题:Python renderElement函数的具体用法?Python renderElement怎么用?Python renderElement使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了renderElement函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nonDefaultDoctype
def test_nonDefaultDoctype(self):
"""
L{renderElement} will write the doctype string specified by the
doctype keyword argument.
"""
element = TestElement()
d = self.request.notifyFinish()
def check(_):
self.assertEqual(
"".join(self.request.written),
('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
'<p>Hello, world.</p>'))
d.addCallback(check)
renderElement(
self.request,
element,
doctype=(
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'))
return d
示例2: _showDirectory
def _showDirectory(self, request, dirinfo):
children = dirinfo[1]['children']
body = tags.ul(*[
tags.li(tags.a(name + ('/' if info[0] == 'dirnode' else ''),
href='/' + info[1]['ro_uri']))
for name, info in children.iteritems()
])
renderElement(request, body)
示例3: process
def process(r):
"""
Recursively go through r and any child Resources until something
returns an IRenderable, then render it and let the result of that
bubble back up.
"""
if IResource.providedBy(r):
request.render(getChildForRequest(r, request))
return _StandInResource
if IRenderable.providedBy(r):
renderElement(request, r)
return _StandInResource
return r
示例4: render
def render(self, request):
print '%srequest.args: %s%s' % (config.color.RED, request.args, config.color.ENDC)
session_user = SessionManager(request).getSessionUser()
if session_user['id'] == 0:
return redirectTo('../', request)
sessionResponse = SessionManager(request).getSessionResponse()
try:
status = request.args.get('status')[0]
except:
status = 'pending'
filters = {'status': status}
Page = pages.SummaryTransactions('Summary Transactions', 'summaryTransactions', filters)
Page.session_user = session_user
Page.sessionResponse = sessionResponse
print "%ssession_user: %s%s" % (config.color.BLUE, session_user, config.color.ENDC)
print "%ssessionResponse: %s%s" % (config.color.BLUE, sessionResponse, config.color.ENDC)
SessionManager(request).clearSessionResponse()
request.write('<!DOCTYPE html>\n')
return renderElement(request, Page)
示例5: render_GET
def render_GET(self, request):
email = self.getRequestEmail(request)
request.setHeader('content-type', 'text/html; charset=utf-8')
element = tags.html(
htmlHead,
tags.body(tags.form(
tags.fieldset(
tags.div(
tags.label('Cert e-mail'),
tags.label('Username', for_='username'),
tags.label('Password', for_='password'),
tags.label('Site', for_='site', class_='last'),
id='names',
),
tags.div(
tags.input(disabled='true', value=email),
tags.input(name='username', type='text'),
tags.input(name='password', type='password'),
tags.input(name='site', type='url', class_='last'),
id='fields',
),
),
tags.button('Generate', type='submit'),
action='', method='POST',
)),
)
return renderElement(request, element)
示例6: render
def render(self, request):
print '%srequest.args: %s%s' % (config.color.RED, request.args, config.color.ENDC)
session_user = SessionManager(request).get_session_user()
session_user['action'] = 'summary_bids'
if session_user['level'] != 0:
return redirectTo('../', request)
session_response = SessionManager(request).get_session_response()
filters = {}
try:
filters['status'] = request.args.get('status')[0]
except:
filters['status'] = 'active'
Page = pages.SummaryBids('%s Summary Bids' % config.company_name, 'summary_bids', filters)
Page.session_user = session_user
print "%ssession_user: %s%s" % (config.color.BLUE, session_user, config.color.ENDC)
print "%ssession_response: %s%s" % (config.color.BLUE, session_response, config.color.ENDC)
SessionManager(request).clearSessionResponse()
request.write('<!DOCTYPE html>\n')
return renderElement(request, Page)
示例7: render_POST
def render_POST(self, request):
uri = request.args.get('uri', [])
if not uri or not tahoeRegex.match(uri[0]):
return self.render_GET(request)
ext = request.args.get('ext', [])
b64uri = base64.urlsafe_b64encode(uri[0])
extension = ''
if ext and ext[0]:
extension = '.' + ext[0].lstrip('.')
if uri[0] not in self.shortdb:
while True:
short = crockford.b32encode(os.urandom(9)).lower()
if short not in self.shortdb:
break
self.shortdb[short] = uri[0]
self.shortdb[uri[0]] = short
self.shortdb.sync()
else:
short = self.shortdb[uri[0]]
if request.args.get('api', []):
return '/' + short + extension
body = tags.p(
tags.a('long url', href=b64uri + extension), '; ',
tags.a('medium url', href='/' + uri[0] + extension), '; ',
tags.a('short url', href=short + extension))
return renderElement(request, body)
示例8: render
def render(self, request):
print '%srequest.args: %s%s' % (config.color.RED, request.args, config.color.ENDC)
session_user = SessionManager(request).get_session_user()
session_user['page'] = 'transactions'
if session_user['id'] == 0:
return redirectTo('../', request)
session_response = SessionManager(request).get_session_response()
filters = {}
try:
filters['status'] = request.args.get('status')[0]
except:
filters['status'] = 'open'
try:
filters['kind'] = request.args.get('kind')[0]
except:
filters['kind'] = 'promoter'
Page = pages.Transactions('%s Transactions' % config.company_name, 'transactions', filters)
Page.session_user = session_user
print "%ssession_user: %s%s" % (config.color.BLUE, session_user, config.color.ENDC)
print "%ssession_response: %s%s" % (config.color.BLUE, session_response, config.color.ENDC)
SessionManager(request).clearSessionResponse()
request.write('<!DOCTYPE html>\n')
return renderElement(request, Page)
示例9: render
def render(self, request):
session_transaction = SessionManager(request).getSessionTransaction()
#transactionId = session_transaction['id']
if session_transaction['id'] == 0:
return redirectTo('../', request)
#lenderId = session_transaction['lenderId']
#transaction = db.query(Transaction).filter(Transaction.id == transactionId).first()
session_user = SessionManager(request).getSessionUser()
session_user['page'] = 'receipt'
Page = pages.Receipt('Smart Property Group - Receipt', 'receipt')
Page.session_user = session_user
Page.session_transaction = session_transaction
print "%ssession_user: %s%s" % (config.color.YELLOW, session_user, config.color.ENDC)
print "%ssession_transaction: %s%s" % (config.color.YELLOW, session_transaction, config.color.ENDC)
SessionManager(request).clearSessionResponse()
request.write('<!DOCTYPE html>\n')
return renderElement(request, Page)
示例10: render
def render(self, request):
print '%srequest.args: %s%s' % (config.color.RED, request.args, config.color.ENDC)
session_user = SessionManager(request).getSessionUser()
if session_user['id'] == 0:
return redirectTo('../', request)
sessionResponse = SessionManager(request).getSessionResponse()
sessionProperty = SessionManager(request).getSessionProperty()
try:
status = request.args.get('status')[0]
except:
status = 'pending'
Page = pages.Orders('Orders', 'orders', status)
Page.session_user = session_user
print "%ssession_user: %s%s" % (config.color.BLUE, session_user, config.color.ENDC)
print "%ssessionProperty: %s%s" % (config.color.BLUE, sessionProperty, config.color.ENDC)
print "%ssessionResponse: %s%s" % (config.color.BLUE, sessionResponse, config.color.ENDC)
SessionManager(request).clearSessionResponse()
request.write('<!DOCTYPE html>\n')
return renderElement(request, Page)
示例11: render
def render(self, request):
print '%srequest.args: %s%s' % (config.color.RED, request.args, config.color.ENDC)
session_user = SessionManager(request).getSessionUser()
if session_user['id'] == 0:
return redirectTo('../', request)
sessionResponse = SessionManager(request).getSessionResponse()
session_user['page'] = 'lend'
session_transaction = SessionManager(request).getSessionTransaction()
if not session_transaction.get('amount'):
session_transaction['amount'] = 1
session_user['page'] = 'lend'
Page = pages.Lend('Smart Property Group - Lend', 'lend')
Page.session_user = session_user
Page.sessionResponse = sessionResponse
Page.session_transaction = session_transaction
print "%ssession_user: %s%s" % (config.color.BLUE, session_user, config.color.ENDC)
print "%ssessionResponse: %s%s" % (config.color.BLUE, sessionResponse, config.color.ENDC)
print "%ssession_transaction: %s%s" % (config.color.BLUE, session_transaction, config.color.ENDC)
SessionManager(request).clearSessionResponse()
request.write('<!DOCTYPE html>\n')
return renderElement(request, Page)
示例12: test_simpleFailure
def test_simpleFailure(self):
"""
L{renderElement} handles failures by writing a minimal
error message to the request and finishing it.
"""
element = FailingElement()
d = self.request.notifyFinish()
def check(_):
flushed = self.flushLoggedErrors(FlattenerError)
self.assertEqual(len(flushed), 1)
self.assertEqual(
"".join(self.request.written),
('<!DOCTYPE html>\n'
'<div style="font-size:800%;'
'background-color:#FFF;'
'color:#F00'
'">An error occurred while rendering the response.</div>'))
self.assertTrue(self.request.finished)
d.addCallback(check)
self.assertIdentical(NOT_DONE_YET, renderElement(self.request, element))
return d
示例13: render_GET
def render_GET(self, request):
accept = request.getHeader('Accept')
if accept is not None and b'application/json' in accept: # TODO: Implement or obtain correct Accept interpretation
request.setHeader(b'Content-Type', b'application/json')
return serialize(self.__describe_block()).encode('utf-8')
else:
request.setHeader(b'Content-Type', b'text/html;charset=utf-8')
return template.renderElement(request, self.__element)
示例14: wrapper
def wrapper(
self: Any, request: IRequest, *args: Any, **kwargs: Any
) -> KleinRenderable:
response = f(self, request, *args, **kwargs)
if IRenderable.providedBy(response):
return renderElement(request, response)
return response
示例15: render
def render(self, format, kind=None, buffer=None):
# Variable aliases
bucket = self.bucket
df = self.dataframe
# Compute group name for HDF5 and NetCDF formats
# TODO: Optionally prefix with "realm" from "bucket.tdata"
group_name = bucket.title.short
if format == 'xlsx':
# http://pandas.pydata.org/pandas-docs/stable/io.html#io-excel-writer
# https://stackoverflow.com/questions/28058563/write-to-stringio-object-using-pandas-excelwriter
with pandas.ExcelWriter('temp.xlsx', engine='xlsxwriter') as excel_writer:
excel_writer.book.filename = buffer
df.to_excel(excel_writer, sheet_name=bucket.title.compact[:31], index=False)
elif format in ['hdf', 'hdf5', 'h5']:
# Create index from "time" column
df = dataframe_index_and_sort(df, 'time')
# http://pandas.pydata.org/pandas-docs/stable/io.html#hdf5-pytables
t = tempfile.NamedTemporaryFile(suffix='.hdf5')
try:
df.to_hdf(t.name, group_name, format='table', data_columns=True, index=False)
buffer.write(t.read())
except Exception as ex:
return self.request.error_response(bucket, with_traceback=True)
elif format in ['nc', 'cdf']:
# Create index from "time" column
df = dataframe_index_and_sort(df, 'time')
# http://xarray.pydata.org/
# http://xarray.pydata.org/en/stable/io.html#netcdf
t = tempfile.NamedTemporaryFile(suffix='.nc')
try:
#df.to_xarray().to_netcdf(path=t.name, group=group_name)
#df.to_xarray().to_netcdf(path=t.name, format='NETCDF4', engine='h5netcdf', group=group_name)
df.to_xarray().to_netcdf(path=t.name, format='NETCDF4', engine='netcdf4', group=group_name)
buffer.write(t.read())
except Exception as ex:
return self.request.error_response(bucket, with_traceback=True)
elif format in ['dt', 'datatables']:
# https://datatables.net/
# Compute data_uri, forward "from" and "to" parameters
data_uri = get_data_uri(bucket, 'data.html')
# Render HTML snippet containing DataTable widget
page = DatatablesPage(data_uri=data_uri, bucket=bucket)
bucket.request.setHeader('Content-Type', 'text/html; charset=utf-8')
return renderElement(bucket.request, page)