示例#1
0
 def applyChanges(self, data):
     content = self.getContent()
     changes = applyChanges(self, content, data)
     # ``changes`` is a dictionary; if empty, there were no changes
     if changes:
         #import pdb;pdb.set_trace()
         # Construct change-descriptions for the object-modified event
         descriptions = []
         for interface, attrs in changes.items():
             if interface == IAdmUtilEvent:
                 print "##### Event 2 #######"
             elif IEventIfSuperclass.isEqualOrExtendedBy(interface):
                 print "##### Superclass 2 #######"
             names = attrs.keys()
             for attr in attrs:
                 if attr.find("eventInpObjs_"
                              ) == 0:  # attribute name starts with ...
                     functionName = attr[len('eventInpObjs_'):]
                     print "attr: %s (I:%s)" % (attr, interface)
                     print "   old: ", attrs[attr]['oldval']
                     print "   new: ", attrs[attr]['newval']
                     newSet = attrs[attr]['newval']
                     oldSet = attrs[attr]['oldval']
                     if type(newSet) == type(set()) and \
                        type(oldSet) == type(set()):
                         newEntries = newSet.difference(oldSet)
                         oldEntries = oldSet.difference(newSet)
                         for oldOid in oldEntries:
                             my_catalog = zapi.getUtility(ICatalog)
                             for resObj in my_catalog.searchResults(
                                     oid_index=oldOid):
                                 if IAdmUtilEvent.providedBy(resObj):
                                     resObj.removeOidFromOutObjects(
                                         content.objectID + "." +
                                         functionName)
                                     resObj.removeInvalidOidFromInpOutObjects(
                                     )
                                     resObj._p_changed = True
                         for newOid in newEntries:
                             my_catalog = zapi.getUtility(ICatalog)
                             for resObj in my_catalog.searchResults(
                                     oid_index=newOid):
                                 if IAdmUtilEvent.providedBy(resObj):
                                     resObj.addOidToOutObjects(
                                         content.objectID + "." +
                                         functionName)
                                     resObj.removeInvalidOidFromInpOutObjects(
                                     )
                                     resObj._p_changed = True
             descriptions.append(Attributes(interface, *names))
         # Send out a detailed object-modified event
         zope.event.notify(ObjectModifiedEvent(content, *descriptions))
     return changes
示例#2
0
 def applyChanges(self, data):
     content = self.getContent()
     changes = applyChanges(self, content, data)
     # ``changes`` is a dictionary; if empty, there were no changes
     if changes:
         #import pdb;pdb.set_trace()
         # Construct change-descriptions for the object-modified event
         descriptions = []
         for interface, attrs in changes.items():
             if interface == IAdmUtilEvent and \
                'outObjects' in attrs:
                 print "##### Event 3 #######"
                 newSet = attrs['outObjects']['newval']
                 oldSet = attrs['outObjects']['oldval']
                 if type(newSet) == type(set()) and \
                    type(oldSet) == type(set()):
                     newEntries = newSet.difference(oldSet)
                     oldEntries = oldSet.difference(newSet)
                     #print "oldEntries", oldEntries
                     #print "newEntries", newEntries
                     for myString in oldEntries:
                         [oid, funct] = myString.split('.', 2)
                         my_catalog = zapi.getUtility(ICatalog)
                         for resObj in my_catalog.searchResults(
                                 oid_index=oid):
                             #print "delete from ", resObj
                             resObj.delFromEventInpObjs(funct, content)
                     for myString in newEntries:
                         [oid, funct] = myString.split('.', 2)
                         my_catalog = zapi.getUtility(ICatalog)
                         for resObj in my_catalog.searchResults(
                                 oid_index=oid):
                             #print "add to ", resObj
                             resObj.addToEventInpObjs(funct, content)
             names = attrs.keys()
             #for attr in attrs:
             #print "attr: %s (I:%s)" % (attr, interface)
             #print "   old: ", attrs[attr]['oldval']
             #print "   new: ", attrs[attr]['newval']
             descriptions.append(Attributes(interface, *names))
         # Send out a detailed object-modified event
         zope.event.notify(ObjectModifiedEvent(content, *descriptions))
     return changes