def evolve(context): linkcatalogs.ensureEvolved(context) root = context.connection.root().get(ZopePublication.root_name, None) savepoint_counter = 0 # Groups are no longer allowed as members of a section. groups = findObjectsProviding(root, IGroup) for group in groups: targets = getRelatedObjects(group, URIGroup, rel_type=URIMembership) group_members = getRelatedObjects(group, URIMember, rel_type=URIMembership) for target in targets: target_members = getRelatedObjects(target, URIMember, rel_type=URIMembership) for member in group_members: if member not in target_members: relate(URIMembership, (member, URIMember), (target, URIGroup)) savepoint_counter += 1 unrelate(URIMembership, (group, URIMember), (target, URIGroup)) if savepoint_counter % 2000 == 0: transaction.savepoint(optimistic=True) # Courses gained several new attributes, fill in their course_id courses = findObjectsProviding(root, ICourse) for course in courses: if getattr(course, 'course_id', None) is None: course.course_id = course.__name__
def evolve(context): linkcatalogs.ensureEvolved(context) root = context.connection.root().get(ZopePublication.root_name, None) savepoint_counter = 0 # Groups are no longer allowed as members of a section. groups = findObjectsProviding(root, IGroup) for group in groups: targets = getRelatedObjects( group, URIGroup, rel_type=URIMembership) group_members = getRelatedObjects( group, URIMember, rel_type=URIMembership) for target in targets: target_members = getRelatedObjects( target, URIMember, rel_type=URIMembership) for member in group_members: if member not in target_members: relate(URIMembership, (member, URIMember), (target, URIGroup)) savepoint_counter += 1 unrelate(URIMembership, (group, URIMember), (target, URIGroup)) if savepoint_counter % 2000 == 0: transaction.savepoint(optimistic=True) # Courses gained several new attributes, fill in their course_id courses = findObjectsProviding(root, ICourse) for course in courses: if getattr(course, 'course_id', None) is None: course.course_id = course.__name__
def relate(self, other, meaning=ACTIVE, code=ACTIVE_CODE): links = IRelationshipLinks(self.this) try: link = links.find(self.my_role, other, self.other_role, self.rel_type) except ValueError: relate(self.rel_type, (self.this, self.my_role), (other, self.other_role)) link = links.find(self.my_role, other, self.other_role, self.rel_type) link.state.set(self.filter_date, meaning=meaning, code=code) notify(LinkStateModifiedEvent( link, self.this, other, self.filter_date, meaning, code))
def relate(self, other, meaning=ACTIVE, code=ACTIVE_CODE): links = IRelationshipLinks(self.this) try: link = links.find(self.my_role, other, self.other_role, self.rel_type) except ValueError: relate(self.rel_type, (self.this, self.my_role), (other, self.other_role)) link = links.find(self.my_role, other, self.other_role, self.rel_type) link.state.set(self.filter_date, meaning=meaning, code=code) notify( LinkStateModifiedEvent(link, self.this, other, self.filter_date, meaning, code))