Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6f5281c4
authored
Apr 10, 2015
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: add http403 handler
parent
b1653128
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
12 deletions
+46
-12
circle/circle/urls.py
+1
-0
circle/common/views.py
+21
-11
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':
...
@@ -88,3 +88,4 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
)
)
handler500
=
'common.views.handler500'
handler500
=
'common.views.handler500'
handler403
=
'common.views.handler403'
circle/common/views.py
View file @
6f5281c4
...
@@ -19,32 +19,42 @@ from sys import exc_info
...
@@ -19,32 +19,42 @@ from sys import exc_info
import
logging
import
logging
from
django.template
import
RequestContext
from
django.shortcuts
import
render_to_response
from
django.shortcuts
import
render_to_response
from
django.template
import
RequestContext
from
.models
import
HumanReadableException
from
.models
import
HumanReadableException
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
def
handler500
(
request
):
def
get_context
(
request
,
exception
):
cls
,
exception
,
traceback
=
exc_info
()
logger
.
exception
(
"unhandled exception"
)
ctx
=
{}
ctx
=
{}
if
is
instance
(
exception
,
HumanReadableException
):
if
is
subclass
(
exception
.
__class__
,
HumanReadableException
):
try
:
try
:
ctx
[
'error'
]
=
exception
.
get_user_text
()
if
request
.
user
.
is_superuser
:
except
:
pass
else
:
try
:
if
request
.
user
.
is_superuser
():
ctx
[
'error'
]
=
exception
.
get_admin_text
()
ctx
[
'error'
]
=
exception
.
get_admin_text
()
else
:
ctx
[
'error'
]
=
exception
.
get_user_text
()
except
:
except
:
pass
pass
return
ctx
def
handler500
(
request
):
cls
,
exception
,
traceback
=
exc_info
()
logger
.
exception
(
"unhandled exception"
)
ctx
=
get_context
(
request
,
exception
)
try
:
try
:
resp
=
render_to_response
(
"500.html"
,
ctx
,
RequestContext
(
request
))
resp
=
render_to_response
(
"500.html"
,
ctx
,
RequestContext
(
request
))
except
:
except
:
resp
=
render_to_response
(
"500.html"
,
ctx
)
resp
=
render_to_response
(
"500.html"
,
ctx
)
resp
.
status_code
=
500
resp
.
status_code
=
500
return
resp
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
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 %}
circle/templates/500.html
View file @
6f5281c4
{% extends "
dashboard/
base.html" %}
{% extends "base.html" %}
{% load i18n %}
{% load i18n %}
{% block title %}HTTP 500{% endblock %}
{% block title %}HTTP 500{% endblock %}
...
...
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