Skip to content

Commit

Permalink
Added custom 500 page
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Di Milia committed Jun 22, 2016
1 parent ca84e3f commit 7366bd2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions micromasters/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

handler404 = 'ui.views.page_404'
handler500 = 'ui.views.page_500'
20 changes: 20 additions & 0 deletions ui/templates/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "base_error.html" %}
{% load i18n static %}

{% block title %}{% trans "MIT MicroMasters" %}{% endblock %}

{% block error_header %}
INTERNAL SERVER ERROR
{% endblock %}

{% block error_content %}
<div id="page-not-found">
<p>The page you requested has problems: an engineer will be blamed for this.</p>

<p>We get emails every time you see this page, keep refreshing if you're mad or just write to
<a href="mailto:[email protected]">[email protected]</a></p>

<iframe width="630" height="473" src="https://www.youtube.com/embed/IAIPUGO1iko"
frameborder="0" allowfullscreen></iframe>
</div>
{% endblock %}
2 changes: 2 additions & 0 deletions ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ui.views import (
dashboard,
page_404,
page_500,
)

dashboard_urlpatterns = [
Expand All @@ -27,4 +28,5 @@
urlpatterns = [
url(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
url(r'^404/$', page_404, name='ui-404'),
url(r'^500/$', page_500, name='ui-500'),
] + dashboard_urlpatterns
21 changes: 21 additions & 0 deletions ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,24 @@ def page_404(request):
)
response.status_code = 404
return response


def page_500(request):
"""
Overridden handler for the 500 error pages.
"""
name = request.user.profile.preferred_name if not request.user.is_anonymous() else ""

response = render(
request,
"500.html",
context={
"style_src": get_bundle_url(request, "style.js"),
"dashboard_src": get_bundle_url(request, "dashboard.js"),
"js_settings_json": "{}",
"authenticated": not request.user.is_anonymous(),
"name": name,
}
)
response.status_code = 500
return response
23 changes: 23 additions & 0 deletions ui/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,29 @@ def test_404_error_context_logged_out(self):
assert response.context['authenticated'] is False
assert response.context['name'] == ""

def test_500_error_context_logged_in(self):
"""
Assert context values for 500 error page when logged in
"""
with mute_signals(post_save):
profile = ProfileFactory.create()
self.client.force_login(profile.user)

response = self.client.get('/500/')
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
assert response.context['authenticated'] is True
assert response.context['name'] == profile.preferred_name

def test_500_error_context_logged_out(self):
"""
Assert context values for 500 error page when logged out
"""
# case with specific page
response = self.client.get('/500/')
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
assert response.context['authenticated'] is False
assert response.context['name'] == ""


class TestProgramPage(TestCase):
"""
Expand Down

0 comments on commit 7366bd2

Please sign in to comment.