Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
c068bc95
Commit
c068bc95
authored
Nov 11, 2015
by
Saleem Latif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Custom 500 error message should only be seen for Preview
parent
a8cca47c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
6 deletions
+24
-6
common/djangoapps/util/views.py
+15
-4
lms/djangoapps/certificates/tests/test_webview_views.py
+5
-1
lms/djangoapps/certificates/views/webview.py
+4
-1
No files found.
common/djangoapps/util/views.py
View file @
c068bc95
...
...
@@ -56,13 +56,18 @@ def jsonable_server_error(request, template_name='500.html'):
return
server_error
(
request
,
template_name
=
template_name
)
def
handle_500
(
template_path
,
context
=
None
):
def
handle_500
(
template_path
,
context
=
None
,
test_func
=
None
):
"""
Decorator for view specific 500 error handling.
Custom handling will be skipped only if test_func is passed and it returns False
Usage:
:
Usage:
@handle_500(template_path='certificates/server-error.html', context={'error-info': 'Internal Server Error'})
@handle_500(
template_path='certificates/server-error.html',
context={'error-info': 'Internal Server Error'},
test_func=lambda request: request.GET.get('preview', None)
)
def my_view(request):
# Any unhandled exception in this view would be handled by the handle_500 decorator
# ...
...
...
@@ -83,9 +88,15 @@ def handle_500(template_path, context=None):
if
settings
.
DEBUG
:
# In debug mode let django process the 500 errors and display debug info for the developer
raise
else
:
elif
test_func
is
None
or
test_func
(
request
):
# Display custom 500 page if either
# 1. test_func is None (meaning nothing to test)
# 2. or test_func(request) returns True
log
.
exception
(
"Error in django view."
)
return
render_to_response
(
template_path
,
context
)
else
:
# Do not show custom 500 error when test fails
raise
return
inner
return
decorator
...
...
lms/djangoapps/certificates/tests/test_webview_views.py
View file @
c068bc95
...
...
@@ -454,9 +454,13 @@ class CertificatesViewsTests(ModuleStoreTestCase, EventTrackingTestCase):
user_id
=
self
.
user
.
id
,
course_id
=
unicode
(
self
.
course
.
id
)
)
response
=
self
.
client
.
get
(
test_url
)
response
=
self
.
client
.
get
(
test_url
+
"?preview=honor"
)
self
.
assertIn
(
"Invalid Certificate Configuration"
,
response
.
content
)
# Verify that Exception is raised when certificate is not in the preview mode
with
self
.
assertRaises
(
Exception
):
self
.
client
.
get
(
test_url
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
def
test_certificate_evidence_event_emitted
(
self
):
self
.
client
.
logout
()
...
...
lms/djangoapps/certificates/views/webview.py
View file @
c068bc95
...
...
@@ -281,7 +281,10 @@ def _update_certificate_context(context, course, user, user_certificate):
)
@handle_500
(
template_path
=
"certificates/server-error.html"
)
@handle_500
(
template_path
=
"certificates/server-error.html"
,
test_func
=
lambda
request
:
request
.
GET
.
get
(
'preview'
,
None
)
)
def
render_html_view
(
request
,
user_id
,
course_id
):
"""
This public view generates an HTML representation of the specified student's certificate
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment