Exemple #1
0
 def _update_model(self, events, msg, root, model, doc, comm=None):
     if comm:
         filtered = {}
         for k, v in msg.items():
             try:
                 change = (k not in self._changing or self._changing[k] != v
                           or self._changing['id'] != model.ref['id'])
             except:
                 change = True
             if change:
                 filtered[k] = v
         for attr, new in filtered.items():
             setattr(model, attr, new)
             event = doc._held_events[-1] if doc._held_events else None
             if (event and event.model is model and event.attr == attr
                     and event.new is new):
                 continue
             # If change did not trigger event trigger it manually
             old = getattr(model, attr)
             serializable_new = model.lookup(attr).serializable_value(model)
             event = ModelChangedEvent(doc, model, attr, old, new,
                                       serializable_new)
             _combine_document_events(event, doc._held_events)
     else:
         model.update(**msg)
Exemple #2
0
 def update_model():
     update = {k: v for msg in msgs for k, v in msg.items()}
     if comm:
         for attr, new in update.items():
             setattr(model, attr, new)
             event = doc._held_events[
                 -1] if doc._held_events else None
             if (event and event.model is model
                     and event.attr == attr and event.new is new):
                 continue
             # If change did not trigger event trigger it manually
             old = getattr(model, attr)
             serializable_new = model.lookup(
                 attr).serializable_value(model)
             event = ModelChangedEvent(doc, model, attr, old, new,
                                       serializable_new)
             _combine_document_events(event, doc._held_events)
     else:
         model.update(**update)