1 from abc
import ABCMeta
3 from couchdbkit
.ext
.django
.schema
import DocumentMeta
7 class DocumentABCMeta(ABCMeta
, DocumentMeta
):
8 """ Meta class must be subclass of all parents' meta classes """
13 def proxy_object(obj
, **kwargs
):
14 """ Proxies an object to make it arbitrarily modifiable
16 It is not possible to add arbitrary values to an couchdbkit Document,
17 because all values have to fit the schema and have to be JSON serializable
20 class ProxyObject(object):
21 """ Proxy for obj that can have properties of arbitrary type """
23 # ensure that proxied objects can be proxied again
24 __metaclass__
= DocumentABCMeta
26 def __init__(self
, obj
, **kwargs
):
29 for key
, val
in kwargs
.items():
30 setattr(self
, key
, val
)
33 def __getattr__(self
, attr
):
34 return getattr(self
.obj
, attr
)
37 def __eq__(self
, other
):
38 # if "other" is of the same type as proxied obj, compare directly
39 if isinstance(other
, ProxyObject
):
40 return self
.obj
== other
.obj
43 return self
.obj
== other
50 cls
.register(ProxyObject
)
52 return ProxyObject(obj
, **kwargs
)