Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
appify 403/404/500 templates (bug 704560)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Nov 22, 2011
1 parent a4a8d3b commit d1e374d
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 28 deletions.
23 changes: 23 additions & 0 deletions apps/amo/templates/amo/403_apps.html
@@ -0,0 +1,23 @@
{% set addon_type = amo.ADDON_WEBAPP %}
{% extends 'base_modal.html' if request.is_ajax() else 'impala/base_side_categories.html' %}

{% block title %}{{ _('Oops') }}{% endblock %}

{# TODO(apps): Finalize copy. #}

{% block primary %}
<section class="primary">
<header>
<h1>Oops! Not allowed.</h1>
</header>
<div class="island hero prose">
<p>You tried to do something that you weren't allowed to.</p>
{% if csrf %}
{% trans %}
<p>Try going back to the previous page, refreshing
and then trying again.</p>
{% endtrans %}
{% endif %}
</div>
</section>
{% endblock %}
43 changes: 43 additions & 0 deletions apps/amo/templates/amo/404_apps.html
@@ -0,0 +1,43 @@
{% set addon_type = amo.ADDON_WEBAPP %}
{% extends 'impala/base_side_categories.html' %}

{% block title %}{{ _('Not Found') }}{% endblock %}

{% set search = url('apps.search') %}
{% set home = url('apps.home') %}

{# TODO(apps): Finalize copy. #}

{% block primary %}
<section class="primary">
<header>
<h1>We're sorry, but we can't find what you're looking for.</h1>
</header>
<div class="island prose">
<p>
The page or file you requested wasn't found on our site. It's possible that
you clicked a link that's out of date, or typed in the address incorrectly.
</p>
<ul>
<li>If you typed in the address, please double check the spelling.</li>
<li>
If you followed a link from somewhere, please let us know at
<a href="mailto:webmaster@mozilla.com">webmaster@mozilla.com</a>.
Tell us where you came from and what you were looking for, and we'll do
our best to fix it.
</li>
</ul>
<p>Or you can just jump over to some of the popular pages on our website.</p>
<ul>
<li>
Do you want to <a href="{{ search }}">search for apps</a>? You may go to the
<a href="{{ search }}">search page</a> or just use the search field above.
</li>
<li>
If you prefer to start over, just go to the
<a href="{{ home }}">apps front page</a>.
</li>
</ul>
</div>
</section>
{% endblock %}
23 changes: 23 additions & 0 deletions apps/amo/templates/amo/500_apps.html
@@ -0,0 +1,23 @@
{% set addon_type = amo.ADDON_WEBAPP %}
{% extends 'impala/base_side_categories.html' %}

{% block title %}{{ _('Oops') }}{% endblock %}

{% set home = url('apps.home') %}

{# TODO(apps): Finalize copy. #}

{% block primary %}
<section class="primary">
<header>
<h1>Oops! We had an error.</h1>
</header>
<div class="island hero prose">
<p>We'll get to fixing that soon.</p>
<p>
You can try refreshing the page, or head back to the
<a href="{{ home }}">Apps homepage</a>.
</p>
</div>
</section>
{% endblock %}
42 changes: 25 additions & 17 deletions apps/amo/tests/test_views.py
Expand Up @@ -28,23 +28,31 @@
from users.models import UserProfile



def test_404_no_app():
"""Make sure a 404 without an app doesn't turn into a 500."""
# That could happen if helpers or templates expect APP to be defined.
url = reverse('amo.monitor')
response = test.Client().get(url + 'nonsense')
eq_(response.status_code, 404)


def test_404_app_links():
response = test.Client().get('/en-US/thunderbird/xxxxxxx')
eq_(response.status_code, 404)
links = pq(response.content)('[role=main] ul li a:not([href^=mailto])')
eq_(len(links), 4)
for link in links:
href = link.attrib['href']
assert href.startswith('/en-US/thunderbird'), href
class Test404(amo.tests.TestCase):

def test_404_no_app(self):
"""Make sure a 404 without an app doesn't turn into a 500."""
# That could happen if helpers or templates expect APP to be defined.
url = reverse('amo.monitor')
response = self.client.get(url + 'nonsense')
eq_(response.status_code, 404)
self.assertTemplateUsed(response, 'amo/404.html')

def test_404_app_links(self):
response = self.client.get('/en-US/thunderbird/xxxxxxx')
eq_(response.status_code, 404)
self.assertTemplateUsed(response, 'amo/404.html')
links = pq(response.content)('[role=main] ul li a:not([href^=mailto])')
eq_(len(links), 4)
for link in links:
href = link.attrib['href']
assert href.startswith('/en-US/thunderbird'), href

@patch.object(settings, 'APP_PREVIEW', True)
def test_404_webapps(self):
response = self.client.get('/xxx', follow=True)
eq_(response.status_code, 404)
self.assertTemplateUsed(response, 'amo/404_apps.html')


class TestCommon(amo.tests.TestCase):
Expand Down
15 changes: 11 additions & 4 deletions apps/amo/views.py
Expand Up @@ -67,19 +67,26 @@ def robots(request):


def handler404(request):
return jingo.render(request, 'amo/404.html', status=404)
webapp = settings.APP_PREVIEW
template = 'amo/404%s.html' % ('_apps' if webapp else '')
return jingo.render(request, template, {'webapp': webapp}, status=404)


def handler500(request):
webapp = settings.APP_PREVIEW
template = 'amo/500%s.html' % ('_apps' if webapp else '')
arecibo = getattr(settings, 'ARECIBO_SERVER_URL', '')
if arecibo:
post(request, 500)
return jingo.render(request, 'amo/500.html', status=500)
return jingo.render(request, template, {'webapp': webapp}, status=500)


def csrf_failure(request, reason=''):
return jingo.render(request, 'amo/403.html',
{'csrf': 'CSRF' in reason}, status=403)
webapp = settings.APP_PREVIEW
template = 'amo/403%s.html' % ('_apps' if webapp else '')
return jingo.render(request, template,
{'csrf': 'CSRF' in reason, 'webapp': webapp},
status=403)


def loaded(request):
Expand Down
5 changes: 5 additions & 0 deletions media/css/impala/prose.less
Expand Up @@ -31,6 +31,11 @@
margin-left: 1em;
margin-bottom: 1em;
}
> ul, > ol, > p {
&:first-child {
margin-top: 0;
}
}
b, strong {
font-weight: bold;
}
Expand Down
14 changes: 7 additions & 7 deletions media/css/impala/site.less
Expand Up @@ -75,13 +75,6 @@ header + .island {
width: 500px;
}

.full {
.border-box;
float: none;
margin: auto 0 !important;
width: 100%;
}

.primary {
margin-left: 210px;
position: relative;
Expand All @@ -106,6 +99,13 @@ header + .island {
}
}

.full {
.border-box;
float: none;
margin: auto 0 !important;
width: 100%;
}

.secondary {
float: left;
width: 180px;
Expand Down

0 comments on commit d1e374d

Please sign in to comment.