Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Xbus Common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
Xbus Common
Commits
ac442b797458
Commit
ac442b797458
authored
2 months ago
by
Houzefa Abbasbhay
Browse files
Options
Downloads
Patches
Plain Diff
Fix JSON pretty-print in envelope/message forms
parent
2df42804e8d2
No related branches found
Branches containing commit
Tags
18.0.3.0.0.1
Tags containing commit
No related merge requests found
Pipeline
#117506
passed
2 months ago
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
NEWS.rst
+5
-0
5 additions, 0 deletions
NEWS.rst
__manifest__.py
+1
-1
1 addition, 1 deletion
__manifest__.py
models/xbus_message.py
+9
-19
9 additions, 19 deletions
models/xbus_message.py
tests/test_xbus.py
+8
-1
8 additions, 1 deletion
tests/test_xbus.py
with
23 additions
and
21 deletions
NEWS.rst
+
5
−
0
View file @
ac442b79
Changelog
=========
18.0.2.1.2
----------
Fix JSON pretty-print in envelope/message forms.
18.0.2.1.1
----------
...
...
This diff is collapsed.
Click to expand it.
__manifest__.py
+
1
−
1
View file @
ac442b79
...
...
@@ -22,7 +22,7 @@
"
license
"
:
"
AGPL-3
"
,
"
summary
"
:
"
Xbus common elements
"
,
"
icon
"
:
"
/xbus_common/static/description/icon.svg
"
,
"
version
"
:
"
18.0.2.1.
1
"
,
"
version
"
:
"
18.0.2.1.
2
"
,
"
category
"
:
"
Technical
"
,
"
author
"
:
"
XCG Consulting
"
,
"
website
"
:
"
https://orbeet.io/
"
,
...
...
This diff is collapsed.
Click to expand it.
models/xbus_message.py
+
9
−
19
View file @
ac442b79
...
...
@@ -17,7 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import
base64
import
json
import
pprint
...
...
@@ -59,10 +58,10 @@
@api.depends
(
"
header
"
)
def
_compute_header_json
(
self
):
for
message
in
self
:
message
.
header_json
=
message
.
_
convert_binary_to
_json
(
message
.
header_json
=
message
.
_
pprint
_json
(
message
.
with_context
(
bin_size
=
False
).
header
)
@api.depends
(
"
body
"
)
def
_compute_body_json
(
self
):
for
message
in
self
:
...
...
@@ -63,10 +62,10 @@
message
.
with_context
(
bin_size
=
False
).
header
)
@api.depends
(
"
body
"
)
def
_compute_body_json
(
self
):
for
message
in
self
:
message
.
body_json
=
message
.
_
convert_binary_to
_json
(
message
.
body_json
=
message
.
_
pprint
_json
(
message
.
with_context
(
bin_size
=
False
).
body
)
...
...
@@ -70,22 +69,13 @@
message
.
with_context
(
bin_size
=
False
).
body
)
def
_convert_binary_to_json
(
self
,
binary_value
):
if
binary_value
:
if
isinstance
(
binary_value
,
bytes
):
# Check if it is of type bytes before decoding
string_value
=
base64
.
b64decode
(
binary_value
).
decode
()
# utf-8 by default
else
:
string_value
=
binary_value
if
string_value
.
startswith
(
"
{
"
)
or
string_value
.
startswith
(
"
[
"
):
try
:
json_dict
=
json
.
loads
(
string_value
)
return
pprint
.
pformat
(
json_dict
)
except
json
.
JSONDecodeError
:
return
False
def
_pprint_json
(
self
,
bin_value
):
"""
Pretty-print when payloads actually are JSON.
"""
if
bin_value
and
bin_value
[:
1
]
in
(
b
"
{
"
,
b
"
[
"
):
try
:
return
pprint
.
pformat
(
json
.
loads
(
bin_value
))
except
json
.
JSONDecodeError
:
return
False
return
False
def
_get_type_selection
(
self
)
->
list
[
tuple
[
str
,
str
]]:
...
...
This diff is collapsed.
Click to expand it.
tests/test_xbus.py
+
8
−
1
View file @
ac442b79
...
...
@@ -103,7 +103,7 @@
self
.
cr
.
execute
(
"
INSERT INTO xbus_message (envelope_id, uid, type, header, body) VALUES
"
"
(%s, %s, %s, %s, %s) RETURNING id
"
,
(
envelope_id
,
uid
,
"
test_1
"
,
b
"
header
"
,
b
"
body
"
),
(
envelope_id
,
uid
,
"
test_1
"
,
b
'
{
"
key
"
:
"
value
"
}
'
,
b
"
body
"
),
)
message1_id
=
self
.
cr
.
fetchall
()[
0
][
0
]
# Add a message with body only
...
...
@@ -119,5 +119,6 @@
self
.
env
[
"
xbus.message
"
]
.
with_user
(
self
.
env
.
ref
(
"
base.user_admin
"
))
.
search
([(
"
envelope_id
"
,
"
=
"
,
envelope_id
)])
.
sorted
(
"
id
"
)
)
self
.
assertEqual
(
len
(
messages
),
2
)
...
...
@@ -122,2 +123,8 @@
)
self
.
assertEqual
(
len
(
messages
),
2
)
self
.
assertEqual
((
message
:
=
messages
[
0
]).
type
,
"
test_1
"
)
self
.
assertEqual
(
message
.
header
,
b
'
{
"
key
"
:
"
value
"
}
'
)
self
.
assertEqual
(
message
.
header_json
,
"
{
'
key
'
:
'
value
'
}
"
)
self
.
assertEqual
((
message
:
=
messages
[
1
]).
type
,
"
test_2
"
)
self
.
assertFalse
(
message
.
header
)
self
.
assertFalse
(
message
.
header_json
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment