Changeset 1586 in products for quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/portlets.py
- Timestamp:
- Jan 26, 2010 9:20:11 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/portlets.py
r1584 r1586 12 12 13 13 from plone.portlets.interfaces import ILocalPortletAssignable, IPortletManager,\ 14 IPortletAssignmentMapping, IPortletAssignment 15 from plone.portlets.constants import CONTEXT_CATEGORY 14 IPortletAssignmentMapping, IPortletAssignment, ILocalPortletAssignmentManager 15 from plone.portlets.constants import USER_CATEGORY, GROUP_CATEGORY, \ 16 CONTENT_TYPE_CATEGORY, CONTEXT_CATEGORY 16 17 from plone.app.portlets.interfaces import IPortletTypeInterface 17 18 from plone.app.portlets.exportimport.interfaces import IPortletAssignmentExportImportHandler … … 58 59 for elem in self.exportAssignments(obj): 59 60 root.appendChild(elem) 60 #for elem in self.exportBlacklists(obj)61 #root.appendChild(elem)61 for elem in self.exportBlacklists(obj): 62 root.appendChild(elem) 62 63 if root.hasChildNodes(): 63 64 self.doc.appendChild(root) … … 106 107 return assignments 107 108 109 def exportBlacklists(self, obj): 110 assignments = [] 111 for manager_name, manager in self.portlet_managers: 112 assignable = queryMultiAdapter((obj, manager), ILocalPortletAssignmentManager) 113 if assignable is None: 114 continue 115 for category in (USER_CATEGORY, GROUP_CATEGORY, CONTENT_TYPE_CATEGORY, CONTEXT_CATEGORY,): 116 child = self.doc.createElement('blacklist') 117 child.setAttribute('manager', manager_name) 118 child.setAttribute('category', category) 119 120 status = assignable.getBlacklistStatus(category) 121 if status == True: 122 child.setAttribute('status', u'block') 123 elif status == False: 124 child.setAttribute('status', u'show') 125 else: 126 child.setAttribute('status', u'acquire') 127 128 assignments.append(child) 129 130 return assignments 131 132 108 133 class PortletsImporterSection(object): 109 134 classProvides(ISectionBlueprint) … … 116 141 self.pathkey = defaultMatcher(options, 'path-key', name, 'path') 117 142 self.fileskey = defaultMatcher(options, 'files-key', name, 'files') 143 self.purge = options.get('purge', 'false').strip().lower() == 'true' and True or False 118 144 119 145 def __iter__(self): … … 132 158 if obj is None: # path doesn't exist 133 159 yield item; continue 160 161 # Purge assignments if 'purge' option set to true 162 if self.purge: 163 for name, portletManager in getUtilitiesFor(IPortletManager): 164 assignable = queryMultiAdapter((obj, portletManager), IPortletAssignmentMapping) 165 if assignable is not None: 166 for key in list(assignable.keys()): 167 del assignable[key] 134 168 135 169 if ILocalPortletAssignable.providedBy(obj): … … 141 175 if elem.nodeName == 'assignment': 142 176 self.importAssignment(obj, elem) 143 #elif elem.nodeName == 'blacklist':144 #self.importBlacklist(obj, elem)177 elif elem.nodeName == 'blacklist': 178 self.importBlacklist(obj, elem) 145 179 146 180 yield item … … 183 217 assignment_handler = IPortletAssignmentExportImportHandler(assignment) 184 218 assignment_handler.import_assignment(portlet_interface, node) 219 220 def importBlacklist(self, obj, node): 221 """ Import a blacklist from a node 222 """ 223 manager = node.getAttribute('manager') 224 category = node.getAttribute('category') 225 status = node.getAttribute('status') 226 227 manager = getUtility(IPortletManager, name=manager) 228 229 assignable = queryMultiAdapter((obj, manager), ILocalPortletAssignmentManager) 230 231 if status.lower() == 'block': 232 assignable.setBlacklistStatus(category, True) 233 elif status.lower() == 'show': 234 assignable.setBlacklistStatus(category, False) 235 elif status.lower() == 'acquire': 236 assignable.setBlacklistStatus(category, None) 237 185 238 186 239 logger = logging.getLogger('quintagroup.transmogrifier.portletsimporter')
Note: See TracChangeset
for help on using the changeset viewer.