def patched_iter(self): for item in self.previous: yield item # finalization of importing references rc = getToolByName(self.context, atcfg.REFERENCE_CATALOG) uc = getToolByName(self.context, atcfg.UID_CATALOG) uids = uc.uniqueValuesFor("UID") existing = set(uids) for suid, rel_fields in REFERENCE_QUEUE.items(): instance = rc.lookupObject(suid) if instance is None: error = "Could not find ob to set references for for %s %s" % (suid, rel_fields) print error open(ERRORS_FILENAME, "a+").write("%s %s\n" % (datetime.now(), error)) continue for fname, tuids in rel_fields.items(): # now we update reference field only if all target UIDs are valid # but may be it is better to update with as much as possible valid # target UIDs (do existing.intersection(set(tuids))) if set(tuids).issubset(existing): mutator = instance.Schema()[fname].getMutator(instance) mutator(tuids) else: error = "Could not find all references for %s [%s] (%s)" % ( "/".join(instance.getPhysicalPath()), fname, tuids, ) print error open(ERRORS_FILENAME, "a+").write("%s %s\n" % (datetime.now(), error)) EXISTING_UIDS.clear() REFERENCE_QUEUE.clear()
def patched_iter(self): for item in self.previous: yield item # finalization of importing references rc = getToolByName(self.context, atcfg.REFERENCE_CATALOG) uc = getToolByName(self.context, atcfg.UID_CATALOG) uids = uc.uniqueValuesFor('UID') existing = set(uids) for suid, rel_fields in REFERENCE_QUEUE.items(): instance = rc.lookupObject(suid) if instance is None: error = 'Could not find ob to set references for for %s %s' % ( suid, rel_fields) print error open(ERRORS_FILENAME, 'a+').write('%s %s\n' % (datetime.now(), error)) continue for fname, tuids in rel_fields.items(): # now we update reference field only if all target UIDs are valid # but may be it is better to update with as much as possible valid # target UIDs (do existing.intersection(set(tuids))) if set(tuids).issubset(existing): mutator = instance.Schema()[fname].getMutator(instance) mutator(tuids) else: error = 'Could not find all references for %s [%s] (%s)' % ( '/'.join(instance.getPhysicalPath()), fname, tuids) print error open(ERRORS_FILENAME, 'a+').write('%s %s\n' % (datetime.now(), error)) EXISTING_UIDS.clear() REFERENCE_QUEUE.clear()
def __iter__(self): for item in self.previous: yield item # finalization of importing references rc = getToolByName(self.context, atcfg.REFERENCE_CATALOG) uc = getToolByName(self.context, atcfg.UID_CATALOG) uids = uc.uniqueValuesFor('UID') existing = set(uids) for suid, rel_fields in REFERENCE_QUEUE.items(): instance = rc.lookupObject(suid) for fname, tuids in rel_fields.items(): # now we update reference field only if all target UIDs are valid # but may be it is better to update with as much as possible valid # target UIDs (do existing.intersection(set(tuids))) if set(tuids).issubset(existing): mutator = instance.Schema()[fname].getMutator(instance) mutator(tuids) EXISTING_UIDS.clear() REFERENCE_QUEUE.clear()