Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
82af31c5
authored
Jul 16, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: force unicode() on nonserializable objs for HROs
parent
b37ca46b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
circle/common/models.py
+16
-0
No files found.
circle/common/models.py
View file @
82af31c5
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License along
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
unicode_literals
from
collections
import
deque
from
collections
import
deque
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
from
hashlib
import
sha224
from
hashlib
import
sha224
...
@@ -25,10 +26,13 @@ from warnings import warn
...
@@ -25,10 +26,13 @@ from warnings import warn
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.cache
import
cache
from
django.core.cache
import
cache
from
django.core.serializers.json
import
DjangoJSONEncoder
from
django.db.models
import
(
from
django.db.models
import
(
CharField
,
DateTimeField
,
ForeignKey
,
NullBooleanField
CharField
,
DateTimeField
,
ForeignKey
,
NullBooleanField
)
)
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.encoding
import
force_text
from
django.utils.functional
import
Promise
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
jsonfield
import
JSONField
from
jsonfield
import
JSONField
...
@@ -110,9 +114,20 @@ def split_activity_code(activity_code):
...
@@ -110,9 +114,20 @@ def split_activity_code(activity_code):
return
activity_code
.
split
(
activity_code_separator
)
return
activity_code
.
split
(
activity_code_separator
)
class
Encoder
(
DjangoJSONEncoder
):
def
default
(
self
,
obj
):
if
isinstance
(
obj
,
Promise
):
obj
=
force_text
(
obj
)
try
:
return
super
(
Encoder
,
self
)
.
default
(
obj
)
except
TypeError
:
return
unicode
(
obj
)
class
ActivityModel
(
TimeStampedModel
):
class
ActivityModel
(
TimeStampedModel
):
activity_code
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'activity code'
))
activity_code
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'activity code'
))
readable_name_data
=
JSONField
(
blank
=
True
,
null
=
True
,
readable_name_data
=
JSONField
(
blank
=
True
,
null
=
True
,
dump_kwargs
=
{
"cls"
:
Encoder
},
verbose_name
=
_
(
'human readable name'
),
verbose_name
=
_
(
'human readable name'
),
help_text
=
_
(
'Human readable name of '
help_text
=
_
(
'Human readable name of '
'activity.'
))
'activity.'
))
...
@@ -132,6 +147,7 @@ class ActivityModel(TimeStampedModel):
...
@@ -132,6 +147,7 @@ class ActivityModel(TimeStampedModel):
help_text
=
_
(
'True, if the activity has '
help_text
=
_
(
'True, if the activity has '
'finished successfully.'
))
'finished successfully.'
))
result_data
=
JSONField
(
verbose_name
=
_
(
'result'
),
blank
=
True
,
null
=
True
,
result_data
=
JSONField
(
verbose_name
=
_
(
'result'
),
blank
=
True
,
null
=
True
,
dump_kwargs
=
{
"cls"
:
Encoder
},
help_text
=
_
(
'Human readable result of activity.'
))
help_text
=
_
(
'Human readable result of activity.'
))
def
__unicode__
(
self
):
def
__unicode__
(
self
):
...
...
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