def exception(self, environ, start_response): import traceback from pprint import pformat exc_type, exc_value, tb = sys.exc_info() tblines = traceback.format_exception(exc_type, exc_value, tb) tbstr = "\n".join(tblines) # render the error title = tblines[-1] body = html.Body([ html.Div([ html.H1(self.exception_heading), html.P([self.exception_description]), html.H2("Traceback"), html.Pre([tbstr]), html.H2("Variables"), html.Pre([ "request_uri: %s\nos.getcwd(): %s" % (request_uri(environ), os.getcwd()) ]), html.H2("environ"), html.Pre([pformat(environ)]), html.H2("sys.path"), html.Pre([pformat(sys.path)]), html.H2("os.environ"), html.Pre([pformat(dict(os.environ))]) ]) ]) msg = self._transform(title, body, environ) return self._return_response(msg, start_response, status="500 Internal Server Error", contenttype="text/html")
def search(self, environ, start_response): """WSGI method, called by the wsgi app for requests that matches ``searchendpoint``.""" queryparams = self._search_parse_query(environ['QUERY_STRING']) res, pager = self._search_run_query(queryparams) if pager['totalresults'] == 1: title = "1 match" else: title = "%s matches" % pager['totalresults'] title += " for '%s'" % queryparams.get("q") body = html.Body() for r in res: if not 'dcterms_title' in r or r['dcterms_title'] is None: r['dcterms_title'] = r['uri'] if r.get('dcterms_identifier', False): r['dcterms_title'] = r['dcterms_identifier'] + ": " + r[ 'dcterms_title'] body.append( html.Div([ html.H2([elements.Link(r['dcterms_title'], uri=r['uri'])]), r.get('text', '') ], **{'class': 'hit'})) pagerelem = self._search_render_pager(pager, queryparams, environ['PATH_INFO']) body.append( html.Div([ html.P([ "Results %(firstresult)s-%(lastresult)s " "of %(totalresults)s" % pager ]), pagerelem ], **{'class': 'pager'})) data = self._transform(title, body, environ, template="xsl/search.xsl") return self._return_response(data, start_response)
def test_html(self): # test 2: use element.html elements only, to make a similar # document (although without metadata about # sections/subsection and classses). Uses some HTML5 elements # that are converted to divs when rendering as XHTML 1.1 body = html.Body([ html.H1(['Toplevel heading']), html.Summary(['Introductory preamble']), html.Section([ html.H2(['First section']), html.P(['Some text']), html.Section( [html.H3(['First subsection']), html.P(['More text'])]) ]), html.Section( [html.H2(['Second section']), html.P(['Even more text'])]) ]) want = """ <body xmlns="http://www.w3.org/1999/xhtml" about="http://localhost:8000/res/base/basefile"> <h1>Toplevel heading</h1> <div class="summary">Introductory preamble</div> <div class="section"> <h2>First section</h2> <p>Some text</p> <div class="section"> <h3>First subsection</h3> <p>More text</p> </div> </div> <div class="section"> <h2>Second section</h2> <p>Even more text</p> </div> </body> """ self._test_asxhtml(want, body)
def handle_search(self, request, **values): # return Response("<h1>Hello search: " + request.args.get("q") +" </h1>", mimetype="text/html") res, pager = self._search_run_query(request.args) if pager['totalresults'] == 1: title = "1 match" else: title = "%s matches" % pager['totalresults'] title += " for '%s'" % request.args.get("q") body = html.Body() for r in res: if not 'dcterms_title' in r or r['dcterms_title'] is None: r['dcterms_title'] = r['uri'] if r.get('dcterms_identifier', False): r['dcterms_title'] = r['dcterms_identifier'] + ": " + r[ 'dcterms_title'] body.append( html.Div([ html.H2([elements.Link(r['dcterms_title'], uri=r['uri'])]), r.get('text', '') ], **{'class': 'hit'})) pagerelem = self._search_render_pager(pager, dict(request.args), request.path) body.append( html.Div([ html.P([ "Results %(firstresult)s-%(lastresult)s " "of %(totalresults)s" % pager ]), pagerelem ], **{'class': 'pager'})) data = self._transform(title, body, request.environ, template="xsl/search.xsl") return Response(data, mimetype="text/html")