changed decorator to custom ddp_property

This commit is contained in:
Cody Parker 2016-02-25 15:33:21 -06:00
parent 54ec9b8cbc
commit 291b3b882f

View file

@ -94,6 +94,22 @@ class Array(aggregates.Aggregate):
return value
def ddp_property(method):
"""
Simple decorator that adds a "serialize_ddp" attribute to tell the
serializer to include it in the payload returning to the client
Args:
method: the decorated method
Returns:
Callable: Decorated method with new attribute
"""
method.serialize_ddp = True
return method
def api_endpoint(path_or_func=None, decorate=True):
"""
Decorator to mark a method as an API endpoint for later registration.
@ -495,11 +511,11 @@ class Collection(APIMixin):
field.rel.to, fields.pop(field.name),
).values()
# run serialization for all properties
# run serialization for all methods decoratored with ddp_property
for o in obj.__class__.mro():
for attr in o.__dict__:
if isinstance(o.__dict__[attr], property):
val = o.__dict__[attr].__get__(obj)
if hasattr(o.__dict__[attr], 'serialize_ddp'):
val = o.__dict__[attr].__call__(obj)
fields[attr] = val
return data