1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

templates: add new 'not_found.html' template, which will be called for any missing replay request

instead of default error.html
'not_found_html' settable in the config per collection, as per #65
for not found index query, still use query.html but add condition to check for 0 results
add more query and replay not found
remove unused conditional (for search_view -- always exists)
This commit is contained in:
Ilya Kreymer 2015-01-24 12:32:50 -08:00
parent 80fd47ba3e
commit 38e3bbbaef
7 changed files with 50 additions and 19 deletions

View File

@ -9,10 +9,3 @@
</pre>
</p>
{% endif %}
{% if env.pywb_proxy_magic and err_url and status == '404 Not Found' %}
<p>
<a href="//select.{{ env.pywb_proxy_magic }}/{{ err_url }}">Try Different Collection</a>
</p>
{% endif %}

10
pywb/ui/not_found.html Normal file
View File

@ -0,0 +1,10 @@
<h2>Url Not Found</h2>
The url <b>{{ url }}</b> could not be found in this collection.
{% if env.pywb_proxy_magic and url %}
<p>
<a href="//select.{{ env.pywb_proxy_magic }}/{{ url }}">Try Different Collection</a>
</p>
{% endif %}

View File

@ -24,7 +24,8 @@ function ts_to_date(ts, is_gmt)
</script>
</head>
<body>
<h2>pywb Sample Calendar Results</h2>
<h2>pywb Query Results</h2>
{% if cdx_lines | length > 0 %}
<b>{{ cdx_lines | length }}</b> captures of <b>{{ url }}</b>
<table id="captures" style="border-spacing: 10px;">
<tr>
@ -47,5 +48,8 @@ function ts_to_date(ts, is_gmt)
<p>
<i><b>* Unique captures are bold.</b> Other captures are duplicates of a previous capture.</i>
</p>
{% else %}
<i>No captures found for <b>{{ url }}</b></i>
{% endif %}
</body>
</html>

View File

@ -49,12 +49,9 @@ class SearchPageWbUrlHandler(WbUrlHandler):
self.banner_html = None
def render_search_page(self, wbrequest, **kwargs):
if self.search_view:
return self.search_view.render_response(wbrequest=wbrequest,
prefix=wbrequest.wb_prefix,
**kwargs)
else:
return WbResponse.text_response('No Lookup Url Specified')
return self.search_view.render_response(wbrequest=wbrequest,
prefix=wbrequest.wb_prefix,
**kwargs)
def __call__(self, wbrequest):
# root search page
@ -110,6 +107,9 @@ class WBHandler(SearchPageWbUrlHandler):
super(WBHandler, self).__init__(config)
self.index_reader = query_handler
self.not_found_view = (J2TemplateView.
create_template(config.get('not_found_html'),
'Not Found Error'))
cookie_maker = config.get('cookie_maker')
record_loader = ArcWarcRecordLoader(cookie_maker=cookie_maker)
@ -152,12 +152,19 @@ class WBHandler(SearchPageWbUrlHandler):
cdx_callback)
def handle_not_found(self, wbrequest, nfe):
if (not self.fallback_handler or
wbrequest.wb_url.is_query() or
wbrequest.wb_url.is_identity):
raise
# check fallback: only for replay queries and not for identity
if (self.fallback_handler and
not wbrequest.wb_url.is_query() and
not wbrequest.wb_url.is_identity):
return self.fallback_handler(wbrequest)
return self.fallback_handler(wbrequest)
# if capture query, just return capture page
if wbrequest.wb_url.is_query():
return self.index_reader.make_cdx_response(wbrequest, [], 'html')
else:
return self.not_found_view.render_response(status='404 Not Found',
env=wbrequest.env,
url=wbrequest.wb_url.url)
def __str__(self):
return 'Web Archive Replay Handler'

View File

@ -34,6 +34,7 @@ DEFAULTS = {
'search_html': 'ui/search.html',
'home_html': 'ui/index.html',
'error_html': 'ui/error.html',
'not_found_html': 'ui/not_found.html',
'proxy_select_html': 'ui/proxy_select.html',
'proxy_cert_download_html': 'ui/proxy_cert_download.html',

View File

@ -86,6 +86,10 @@ home_html: ui/index.html
# if omitted, a text response is returned
error_html: ui/error.html
# template for 404 not found error, may be customized per collection
not_found_html: ui/not_found.html
# ==== Other Paths ====
# Rewrite urls with absolute paths instead of relative

View File

@ -77,6 +77,13 @@ class TestWb:
# 17 Captures + header
assert len(resp.html.find_all('tr')) == 18
def test_calendar_not_found(self):
# query with no results
resp = self.testapp.get('/pywb/*/http://not-exist.example.com')
self._assert_basic_html(resp)
assert 'No captures found' in resp.body, resp.body
assert len(resp.html.find_all('tr')) == 0
def test_cdx_query(self):
resp = self.testapp.get('/pywb/cdx_/*/http://www.iana.org/')
self._assert_basic_text(resp)
@ -374,6 +381,11 @@ class TestWb:
assert resp.status_int == 403
assert 'Excluded' in resp.body
def test_replay_not_found(self):
resp = self.testapp.head('/pywb/http://not-exist.example.com', status=404)
assert resp.content_type == 'text/html'
assert resp.status_int == 404
def test_static_content(self):
resp = self.testapp.get('/static/test/route/wb.css')
assert resp.status_int == 200