Skip to content

Commit 6f9cc5c

Browse files
committed
Add simple support for xml output if the third party dict2xml.py module
https://pypi.org/project/dict2xml/ is installed. Also this checkin adds the ETag support comment to the CHANGES document. The file was accidently omitted from the rest of the etag checkin.
1 parent 7c78778 commit 6f9cc5c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Features:
5454
allowed to access. Note that unlike the web interface, passwords
5555
and roles for users are still retreivable if the user has access
5656
rights to the properties.
57+
- ETags are sent by GET operations and required for DELETE, PUT and
58+
PATCH operations. ETag can be supplied by HTTP header or in the
59+
payload by adding the field @etag to the form with the value of
60+
the etag.
61+
- If dict2xml.py is installed, the rest interface can produce an XML
62+
format response if the accept header is set to text/xml.
63+
(See: https://pypi.org/project/dict2xml/)
5764
(John Rouillard)
5865
- issue2550833: the export_csv web action now returns labels/names
5966
rather than id's. Replace calls to export_csv with the export_csv_id

roundup/rest.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
import traceback
2020
import re
2121

22+
try:
23+
from dicttoxml import dicttoxml
24+
except ImportError:
25+
dicttoxml = None
26+
2227
from roundup import hyperdb
2328
from roundup import date
2429
from roundup import actions
@@ -305,8 +310,8 @@ class RestfulInstance(object):
305310
__default_patch_op = "replace" # default operator for PATCH method
306311
__accepted_content_type = {
307312
"application/json": "json",
308-
"*/*": "json"
309-
# "application/xml": "xml"
313+
"*/*": "json",
314+
"application/xml": "xml"
310315
}
311316
__default_accept_type = "json"
312317

@@ -620,7 +625,7 @@ def get_attribute(self, class_name, item_id, attr_name, input):
620625
data = node.__getattr__(attr_name)
621626
result = {
622627
'id': item_id,
623-
'type': type(data),
628+
'type': str(type(data)),
624629
'link': "%s/%s/%s/%s" %
625630
(self.data_path, class_name, item_id, attr_name),
626631
'data': data,
@@ -1303,6 +1308,9 @@ def dispatch(self, method, uri, input):
13031308
else:
13041309
indent = None
13051310
output = RoundupJSONEncoder(indent=indent).encode(output)
1311+
elif data_type.lower() == "xml" and dicttoxml:
1312+
self.client.setHeader("Content-Type", "application/xml")
1313+
output = dicttoxml(output, root=False)
13061314
else:
13071315
self.client.response_code = 406
13081316
output = "Content type is not accepted by client"

0 commit comments

Comments
 (0)