Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
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
Show 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 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
unicode_literals
from
collections
import
deque
from
contextlib
import
contextmanager
from
hashlib
import
sha224
...
...
@@ -25,10 +26,13 @@ from warnings import warn
from
django.contrib.auth.models
import
User
from
django.core.cache
import
cache
from
django.core.serializers.json
import
DjangoJSONEncoder
from
django.db.models
import
(
CharField
,
DateTimeField
,
ForeignKey
,
NullBooleanField
)
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
jsonfield
import
JSONField
...
...
@@ -110,9 +114,20 @@ def split_activity_code(activity_code):
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
):
activity_code
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'activity code'
))
readable_name_data
=
JSONField
(
blank
=
True
,
null
=
True
,
dump_kwargs
=
{
"cls"
:
Encoder
},
verbose_name
=
_
(
'human readable name'
),
help_text
=
_
(
'Human readable name of '
'activity.'
))
...
...
@@ -132,6 +147,7 @@ class ActivityModel(TimeStampedModel):
help_text
=
_
(
'True, if the activity has '
'finished successfully.'
))
result_data
=
JSONField
(
verbose_name
=
_
(
'result'
),
blank
=
True
,
null
=
True
,
dump_kwargs
=
{
"cls"
:
Encoder
},
help_text
=
_
(
'Human readable result of activity.'
))
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