|
@@ 310-333 (lines=24) @@
|
| 307 |
|
return HttpResponse(obj.to_json(), 'application/json', status=202) |
| 308 |
|
|
| 309 |
|
|
| 310 |
|
class NodeGroupSerializer(Serializer): |
| 311 |
|
|
| 312 |
|
""" |
| 313 |
|
Our custom node group serializer. Using the default serializer would demand that the |
| 314 |
|
graph reference is included, while we take it from the nested resource URL. |
| 315 |
|
""" |
| 316 |
|
formats = ['json'] |
| 317 |
|
content_types = { |
| 318 |
|
'json': 'application/json' |
| 319 |
|
} |
| 320 |
|
|
| 321 |
|
def from_json(self, content): |
| 322 |
|
data_dict = json.loads(content) |
| 323 |
|
if 'properties' in data_dict: |
| 324 |
|
props = data_dict['properties'] |
| 325 |
|
for key, val in props.iteritems(): |
| 326 |
|
# JS code: {'prop_name': {'value':'prop_value'}} |
| 327 |
|
# All others: {'prop_name': 'prop_value'} |
| 328 |
|
if isinstance(val, dict) and 'value' in val: |
| 329 |
|
props[key] = val['value'] |
| 330 |
|
return data_dict |
| 331 |
|
|
| 332 |
|
def to_json(self, data): |
| 333 |
|
return json.dumps(data) |
| 334 |
|
|
| 335 |
|
|
| 336 |
|
class NodeGroupResource(ModelResource): |
|
@@ 204-227 (lines=24) @@
|
| 201 |
|
noti.save() |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
class NodeSerializer(Serializer): |
| 205 |
|
|
| 206 |
|
""" |
| 207 |
|
Our custom node serializer. Using the default serializer would demand that the |
| 208 |
|
graph reference is included, while we take it from the nested resource URL. |
| 209 |
|
""" |
| 210 |
|
formats = ['json'] |
| 211 |
|
content_types = { |
| 212 |
|
'json': 'application/json' |
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
def from_json(self, content): |
| 216 |
|
data_dict = json.loads(content) |
| 217 |
|
if 'properties' in data_dict: |
| 218 |
|
props = data_dict['properties'] |
| 219 |
|
for key, val in props.iteritems(): |
| 220 |
|
# JS code: {'prop_name': {'value':'prop_value'}} |
| 221 |
|
# All others: {'prop_name': 'prop_value'} |
| 222 |
|
if isinstance(val, dict) and 'value' in val: |
| 223 |
|
props[key] = val['value'] |
| 224 |
|
return data_dict |
| 225 |
|
|
| 226 |
|
def to_json(self, data): |
| 227 |
|
return json.dumps(data) |
| 228 |
|
|
| 229 |
|
|
| 230 |
|
class NodeResource(ModelResource): |
|
@@ 442-464 (lines=23) @@
|
| 439 |
|
return HttpResponse(obj.to_json(), 'application/json', status=202) |
| 440 |
|
|
| 441 |
|
|
| 442 |
|
class EdgeSerializer(Serializer): |
| 443 |
|
|
| 444 |
|
""" |
| 445 |
|
Our custom edge serializer. Using the default serializer would demand that the |
| 446 |
|
graph reference is included, while we take it from the nested resource URL. |
| 447 |
|
It would also demand that nodes are referenced by their full URL's, which we do not |
| 448 |
|
do. |
| 449 |
|
""" |
| 450 |
|
formats = ['json'] |
| 451 |
|
content_types = { |
| 452 |
|
'json': 'application/json' |
| 453 |
|
} |
| 454 |
|
|
| 455 |
|
def from_json(self, content): |
| 456 |
|
data_dict = json.loads(content) |
| 457 |
|
if 'properties' in data_dict: |
| 458 |
|
props = data_dict['properties'] |
| 459 |
|
for key, val in props.iteritems(): |
| 460 |
|
# JS code: {'prop_name': {'value':'prop_value'}} |
| 461 |
|
# All others: {'prop_name': 'prop_value'} |
| 462 |
|
if isinstance(val, dict) and 'value' in val: |
| 463 |
|
props[key] = val['value'] |
| 464 |
|
return data_dict |
| 465 |
|
|
| 466 |
|
|
| 467 |
|
class EdgeResource(ModelResource): |