j2labs/dictshield — Issue #45: Feature request: add global for underscored internal fields only
Author: alexanderdean
Created: 2011-12-03 11:16:43+00:00
State: open

To work with the new permissions system I'm having to override the `_internal_private_fields` in a few places:

class BaseRepresentation(Representation):
"""The fields shared by all existing representations
"""
_internal_fields = ['_id', '_cls', '_types'] # Exclude id as this is an actual field

id = UUIDField(required=True)
created_at = DateTimeField(required=True)
updated_at = DateTimeField(required=True)

class RepresentationLink(EmbeddedDocument):
"""A RepresentationLink holds the ID of and HATEOAS
path to an individual Representation
"""
_internal_fields = ['_id', '_cls', '_types'] # Exclude id as this is an actual field

id = UUIDField(required=True)
link = EmbeddedDocumentField(AtomLink)

def __repr__(self):
return "" % (self.id, self.link)

This works okay but it's a bit fragile - if DictShield introduces a new internal field (e.g. `_timestamp`), then my code will start exposing this field incorrectly. One solution would be a DictShield global like:

UNDERSCORE_ONLY = ['_id', '_cls', '_types']

And then I could override with:

_internal_fields = UNDERSCORE_ONLY

I imagine that this will be a very common use case - because `id` is a very common public field in JSONs.