Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6f5281c4
authored
9 years ago
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: add http403 handler
parent
b1653128
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
13 deletions
+47
-13
circle/circle/urls.py
+1
-0
circle/common/views.py
+22
-12
circle/templates/403.html
+23
-0
circle/templates/500.html
+1
-1
No files found.
circle/circle/urls.py
View file @
6f5281c4
...
...
@@ -88,3 +88,4 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
)
handler500
=
'common.views.handler500'
handler403
=
'common.views.handler403'
This diff is collapsed.
Click to expand it.
circle/common/views.py
View file @
6f5281c4
...
...
@@ -19,32 +19,42 @@ from sys import exc_info
import
logging
from
django.template
import
RequestContext
from
django.shortcuts
import
render_to_response
from
django.template
import
RequestContext
from
.models
import
HumanReadableException
logger
=
logging
.
getLogger
(
__name__
)
def
handler500
(
request
):
cls
,
exception
,
traceback
=
exc_info
()
logger
.
exception
(
"unhandled exception"
)
def
get_context
(
request
,
exception
):
ctx
=
{}
if
is
instance
(
exception
,
HumanReadableException
):
if
is
subclass
(
exception
.
__class__
,
HumanReadableException
):
try
:
ctx
[
'error'
]
=
exception
.
get_user_text
()
if
request
.
user
.
is_superuser
:
ctx
[
'error'
]
=
exception
.
get_admin_text
()
else
:
ctx
[
'error'
]
=
exception
.
get_user_text
()
except
:
pass
else
:
try
:
if
request
.
user
.
is_superuser
():
ctx
[
'error'
]
=
exception
.
get_admin_text
()
except
:
pass
return
ctx
def
handler500
(
request
):
cls
,
exception
,
traceback
=
exc_info
()
logger
.
exception
(
"unhandled exception"
)
ctx
=
get_context
(
request
,
exception
)
try
:
resp
=
render_to_response
(
"500.html"
,
ctx
,
RequestContext
(
request
))
except
:
resp
=
render_to_response
(
"500.html"
,
ctx
)
resp
.
status_code
=
500
return
resp
def
handler403
(
request
):
cls
,
exception
,
traceback
=
exc_info
()
ctx
=
get_context
(
request
,
exception
)
resp
=
render_to_response
(
"403.html"
,
ctx
)
resp
.
status_code
=
403
return
resp
This diff is collapsed.
Click to expand it.
circle/templates/403.html
0 → 100644
View file @
6f5281c4
{% extends "base.html" %}
{% load i18n %}
{% block title %}HTTP 403{% endblock %}
{% block page_title %}{% trans ":(" %}{% endblock page_title %}
{% block content %}
<div
class=
"alert alert-danger"
style=
"font-size: 22px; margin-top: 2em;"
>
<div
class=
"row"
>
<div
class=
"col-md-2"
style=
"text-align: center;"
>
HTTP 403
</div>
<div
class=
"col-md-10"
style=
"text-align: center;"
>
{% if error %}
{{ error }}
{% else %}
{% trans "Forbidden" %}
{% endif %}
</div>
</div>
</div>
{% endblock content %}
This diff is collapsed.
Click to expand it.
circle/templates/500.html
View file @
6f5281c4
{% extends "
dashboard/
base.html" %}
{% extends "base.html" %}
{% load i18n %}
{% block title %}HTTP 500{% endblock %}
...
...
This diff is collapsed.
Click to expand it.
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