Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
2296749b
authored
Aug 28, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: extend HumanReadable*
parent
57863a5b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
+23
-4
circle/common/models.py
+23
-4
No files found.
circle/common/models.py
View file @
2296749b
...
...
@@ -27,6 +27,7 @@ from warnings import warn
from
django.contrib
import
messages
from
django.contrib.auth.models
import
User
from
django.core.cache
import
cache
from
django.core.exceptions
import
PermissionDenied
from
django.core.serializers.json
import
DjangoJSONEncoder
from
django.db.models
import
(
CharField
,
DateTimeField
,
ForeignKey
,
NullBooleanField
...
...
@@ -413,6 +414,10 @@ class HumanReadableObject(object):
self
.
_set_values
(
user_text_template
,
admin_text_template
,
params
)
def
_set_values
(
self
,
user_text_template
,
admin_text_template
,
params
):
if
isinstance
(
user_text_template
,
Promise
):
user_text_template
=
user_text_template
.
_proxy____args
[
0
]
if
isinstance
(
admin_text_template
,
Promise
):
admin_text_template
=
admin_text_template
.
_proxy____args
[
0
]
self
.
user_text_template
=
user_text_template
self
.
admin_text_template
=
admin_text_template
self
.
params
=
params
...
...
@@ -451,6 +456,12 @@ class HumanReadableObject(object):
self
.
user_text_template
,
unicode
(
self
.
params
))
return
self
.
user_text_template
def
get_text
(
self
,
user
):
if
user
and
user
.
is_superuser
:
return
self
.
get_admin_text
()
else
:
return
self
.
get_user_text
()
def
to_dict
(
self
):
return
{
"user_text_template"
:
self
.
user_text_template
,
"admin_text_template"
:
self
.
admin_text_template
,
...
...
@@ -481,13 +492,21 @@ class HumanReadableException(HumanReadableObject, Exception):
self
.
level
=
"error"
def
send_message
(
self
,
request
,
level
=
None
):
if
request
.
user
and
request
.
user
.
is_superuser
:
msg
=
self
.
get_admin_text
()
else
:
msg
=
self
.
get_user_text
()
msg
=
self
.
get_text
(
request
.
user
)
getattr
(
messages
,
level
or
self
.
level
)(
request
,
msg
)
def
fetch_human_exception
(
exception
,
user
=
None
):
if
not
isinstance
(
exception
,
HumanReadableException
):
if
isinstance
(
exception
,
PermissionDenied
):
exception
=
create_readable
(
ugettext_noop
(
"Permission Denied"
))
else
:
exception
=
create_readable
(
_
(
"Unknown error"
),
_
(
"Unknown error:
%(ex)
s"
),
ex
=
unicode
(
exception
))
.
get_text
()
return
exception
.
get_text
(
user
)
if
user
else
exception
def
humanize_exception
(
message
,
exception
=
None
,
level
=
None
,
**
params
):
"""Return new dynamic-class exception which is based on
HumanReadableException and the original class with the dict of exception.
...
...
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