Tefnet Developers wrote:
>
> Hi,
>
> I need to get a single event at an extension in case of such operation:
>
> obj.colAttr = [x, y, z]
>
> right now I will receive:
> extension.remove(...) for each value currently in colAttr
> extension.append(...) for x, y and z.
>
> what I need is something like:
>
> extension.replace(oldvalues, values) with two lists or something like
> that.
>
> Right now my approach (yes, I know this is sick) is:
>
> def weComeFrom():
> f=inspect.currentframe().f_back.f_back
> while(inspect.getmodule(f).__name__.startswith('sqlalchemy.')):
> f=f.f_back
> return (f.f_lasti, f.f_code)
>
>
> class ImmutableExtension(TefAttributeExtension):
> active_history = True
> triggerName = 'immutable'
>
> def append(self, state, value, initiator):
> f = weComeFrom()
> try:
> lf = initiator.__tefLastComeFrom
> except AttributeError:
> lf = None
> if len(self._getOldValue(state, initiator)) == 0:
> initiator.__tefLastComeFrom = f
> return value
> elif f == lf:
> return value
> else:
> self.raiseError(state, value, None, initiator)
>
> What is the proper way to achieve this?
if it were me, I'd just constrain access to a set of methods, such as:
def set_col_attr(*values)
But if that's too simple and straightforward (sarcasm), if you want to
catch coarse-grained get/set events on a collection attribute you need to
create your own descriptor, with the descriptor/synonym approach described
at http://www.sqlalchemy.org/docs/05/mappers.html#using-descriptors.
That way your own descriptor can marshal access to/from the actual
attribute. As for events on the collection itself you can still use
attributeextension or alternatively a custom collection class.
>
> regards,
> Filip Zyzniewski
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---