def importAssignment(self, obj, node): """ Import an assignment from a node """ # 1. Determine the assignment mapping and the name manager_name = node.getAttribute('manager') manager = getUtility(IPortletManager, manager_name) mapping = getMultiAdapter((obj, manager), IPortletAssignmentMapping) if mapping is None: return # 2. Either find or create the assignment assignment = None name = node.getAttribute('name') if name: assignment = mapping.get(name, None) type_ = node.getAttribute('type') if assignment is None: portlet_factory = getUtility(IFactory, name=type_) assignment = portlet_factory() if not name: chooser = INameChooser(mapping) name = chooser.chooseName(None, assignment) mapping[name] = assignment # aq-wrap it so that complex fields will work assignment = assignment.__of__(obj) # set visibility setting visible = node.getAttribute('visible') or 'true' if visible: settings = IPortletAssignmentSettings(assignment) settings['visible'] = visible.lower() in ('true', 'yes', '1') # 3. Use an adapter to update the portlet settings portlet_interface = getUtility(IPortletTypeInterface, name=type_) assignment_handler = IPortletAssignmentExportImportHandler(assignment) assignment_handler.import_assignment(portlet_interface, node)
def importAssignment(self, obj, node): """ Import an assignment from a node """ # 1. Determine the assignment mapping and the name manager_name = node.getAttribute('manager') manager = getUtility(IPortletManager, manager_name) mapping = getMultiAdapter((obj, manager), IPortletAssignmentMapping) if mapping is None: return # 2. Either find or create the assignment assignment = None name = node.getAttribute('name') if name: assignment = mapping.get(name, None) type_ = node.getAttribute('type') if assignment is None: portlet_factory = getUtility(IFactory, name=type_) assignment = portlet_factory() if not name: chooser = INameChooser(mapping) name = chooser.chooseName(None, assignment) mapping[name] = assignment # aq-wrap it so that complex fields will work assignment = assignment.__of__(obj) # 3. Use an adapter to update the portlet settings portlet_interface = getUtility(IPortletTypeInterface, name=type_) assignment_handler = IPortletAssignmentExportImportHandler(assignment) assignment_handler.import_assignment(portlet_interface, node)
def _initAssignmentNode(self, node): """Create an assignment from a node """ site = self.environ.getSite() # 1. Determine the assignment mapping and the name manager = node.getAttribute('manager') category = node.getAttribute('category') key = node.getAttribute('key') # convert unicode to str as unicode paths are not allowed in # restrictedTraverse called in assignment_mapping_from_key if six.PY2: key = key.encode() purge = False if node.hasAttribute('purge'): purge = self._convertToBoolean(node.getAttribute('purge')) mapping = assignment_mapping_from_key(site, manager, category, key, create=True) # 2. Either find or create the assignment assignment = None name = node.getAttribute('name') if name: name = str(name) assignment = mapping.get(name, None) __traceback_info__ = "Assignment name: " + name if node.hasAttribute('remove'): if assignment is not None: del mapping[name] return if purge: for portlet in mapping.keys(): del mapping[portlet] return type_ = str(node.getAttribute('type')) if assignment is None: portlet_factory = getUtility(IFactory, name=type_) assignment = portlet_factory() if not name: chooser = INameChooser(mapping) name = chooser.chooseName(None, assignment) mapping[name] = assignment # aq-wrap it so that complex fields will work assignment = assignment.__of__(site) # set visibility setting visible = node.getAttribute('visible') if visible: settings = IPortletAssignmentSettings(assignment) settings['visible'] = self._convertToBoolean(visible) # 3. Use an adapter to update the portlet settings portlet_interface = getUtility(IPortletTypeInterface, name=type_) assignment_handler = IPortletAssignmentExportImportHandler(assignment) assignment_handler.import_assignment(portlet_interface, node) # 4. Handle ordering insert_before = node.getAttribute('insert-before') if insert_before: position = None keys = list(mapping.keys()) if insert_before == "*": position = 0 elif insert_before in keys: position = keys.index(insert_before) if position is not None: keys.remove(name) keys.insert(position, name) mapping.updateOrder(keys)
def _initAssignmentNode(self, node): """Create an assignment from a node """ site = self.environ.getSite() # 1. Determine the assignment mapping and the name manager = node.getAttribute('manager') category = node.getAttribute('category') key = node.getAttribute('key') # convert unicode to str as unicode paths are not allowed in # restrictedTraverse called in assignment_mapping_from_key key = key.encode() purge = False if node.hasAttribute('purge'): purge = self._convertToBoolean(node.getAttribute('purge')) mapping = assignment_mapping_from_key(site, manager, category, key, create=True) # 2. Either find or create the assignment assignment = None name = node.getAttribute('name') if name: name = str(name) assignment = mapping.get(name, None) __traceback_info__ = "Assignment name: " + name if node.hasAttribute('remove'): if assignment is not None: del mapping[name] return if purge: for portlet in mapping.keys(): del mapping[portlet] return type_ = str(node.getAttribute('type')) if assignment is None: portlet_factory = getUtility(IFactory, name=type_) assignment = portlet_factory() if not name: chooser = INameChooser(mapping) name = chooser.chooseName(None, assignment) mapping[name] = assignment # aq-wrap it so that complex fields will work assignment = assignment.__of__(site) # set visibility setting visible = node.getAttribute('visible') if visible: settings = IPortletAssignmentSettings(assignment) settings['visible'] = self._convertToBoolean(visible) # 3. Use an adapter to update the portlet settings portlet_interface = getUtility(IPortletTypeInterface, name=type_) assignment_handler = IPortletAssignmentExportImportHandler(assignment) assignment_handler.import_assignment(portlet_interface, node) # 4. Handle ordering insert_before = node.getAttribute('insert-before') if insert_before: position = None keys = list(mapping.keys()) if insert_before == "*": position = 0 elif insert_before in keys: position = keys.index(insert_before) if position is not None: keys.remove(name) keys.insert(position, name) mapping.updateOrder(keys)