Mixin way?

Neil Cerutti neilc at norwich.edu
Wed Apr 3 13:16:07 EDT 2013


On 2013-04-03, andrea crotti <andrea.crotti.0 at gmail.com> wrote:
> Well I can explain better the situation to make it more clear.
>
> We are using CouchDb and so far it has been (sigh) a brutal
> manipulation of dictionaries everywhere, with code duplication
> and so on.
>
> Now I wanted to encapsulate all the entities in the DB in
> proper objects, so I have a CouchObject:
>
>
> class CouchObject(object) :
>     """
>     Encapsulate an object which has the ability to be saved to a couch
>     database.
>     """
>     #: list of fields that get filled in automatically if not passed in
>     AUTO = ['created_datetime', 'doc_type', '_id', '_rev']
>     #: dictionary with some extra fields with default values if not
>     # passed in the constructor the default value gets set to the attribute
>     DEFAULTS = {}
>     REQUIRED = []
>     OPTIONAL = []
>     TO_RESOLVE = []
>     MIXINS = []
>
> Where every subclass can redefine these attributes to get
> something done automatically by the constructor for
> convenience.

Hopefully someone with experience with them can help you further,
but this seems like a job for a metaclass.

-- 
Neil Cerutti



More information about the Python-list mailing list