Changeset 1584 in products


Ignore:
Timestamp:
Jan 25, 2010 3:52:11 PM (14 years ago)
Author:
mylan
Message:

Fix breakage portlets importing/exporting for objects, which are not adapterd to IPortletAssignmentMapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/portlets.py

    r1576 r1584  
    1212 
    1313from plone.portlets.interfaces import ILocalPortletAssignable, IPortletManager,\ 
    14     IPortletAssignmentMapping, IPortletAssignment, ILocalPortletAssignmentManager 
    15 from plone.portlets.constants import USER_CATEGORY, GROUP_CATEGORY, \ 
    16     CONTENT_TYPE_CATEGORY, CONTEXT_CATEGORY 
     14    IPortletAssignmentMapping, IPortletAssignment 
     15from plone.portlets.constants import CONTEXT_CATEGORY 
    1716from plone.app.portlets.interfaces import IPortletTypeInterface 
    1817from plone.app.portlets.exportimport.interfaces import IPortletAssignmentExportImportHandler 
     
    5958                for elem in self.exportAssignments(obj): 
    6059                    root.appendChild(elem) 
    61                 for elem in self.exportBlacklists(obj): 
    62                     root.appendChild(elem) 
     60                #for elem in self.exportBlacklists(obj) 
     61                    #root.appendChild(elem) 
    6362                if root.hasChildNodes(): 
    6463                    self.doc.appendChild(root) 
     
    7877        for manager_name, manager in self.portlet_managers: 
    7978            mapping = queryMultiAdapter((obj, manager), IPortletAssignmentMapping) 
     79            if mapping is None: 
     80                continue 
     81 
    8082            mapping = mapping.__of__(obj) 
    8183 
     
    104106        return assignments 
    105107 
    106     def exportBlacklists(self, obj): 
    107         assignments = [] 
    108         for manager_name, manager in self.portlet_managers: 
    109             assignable = queryMultiAdapter((obj, manager), ILocalPortletAssignmentManager) 
    110             if assignable is None: 
    111                 continue 
    112             for category in (USER_CATEGORY, GROUP_CATEGORY, CONTENT_TYPE_CATEGORY, CONTEXT_CATEGORY,): 
    113                 child = self.doc.createElement('blacklist') 
    114                 child.setAttribute('manager', manager_name) 
    115                 child.setAttribute('category', category) 
    116              
    117                 status = assignable.getBlacklistStatus(category) 
    118                 if status == True: 
    119                     child.setAttribute('status', u'block') 
    120                 elif status == False: 
    121                     child.setAttribute('status', u'show') 
    122                 else: 
    123                     child.setAttribute('status', u'acquire') 
    124                      
    125                 assignments.append(child) 
    126  
    127         return assignments 
    128  
    129  
    130108class PortletsImporterSection(object): 
    131109    classProvides(ISectionBlueprint) 
     
    138116        self.pathkey = defaultMatcher(options, 'path-key', name, 'path') 
    139117        self.fileskey = defaultMatcher(options, 'files-key', name, 'files') 
    140         self.purge = options.get('purge', 'false').strip().lower() == 'true' and True or False 
    141118 
    142119    def __iter__(self): 
     
    155132            if obj is None:         # path doesn't exist 
    156133                yield item; continue 
    157  
    158             # Purge assignments if 'purge' option set to true 
    159             if self.purge: 
    160                 for name, portletManager in getUtilitiesFor(IPortletManager): 
    161                     assignable = queryMultiAdapter((obj, portletManager), IPortletAssignmentMapping) 
    162                     if assignable is not None: 
    163                         for key in list(assignable.keys()): 
    164                             del assignable[key] 
    165134 
    166135            if ILocalPortletAssignable.providedBy(obj): 
     
    172141                    if elem.nodeName == 'assignment': 
    173142                        self.importAssignment(obj, elem) 
    174                     elif elem.nodeName == 'blacklist': 
    175                         self.importBlacklist(obj, elem) 
     143                    #elif elem.nodeName == 'blacklist': 
     144                        #self.importBlacklist(obj, elem) 
    176145 
    177146            yield item 
     
    186155        manager = getUtility(IPortletManager, manager_name) 
    187156        mapping = getMultiAdapter((obj, manager), IPortletAssignmentMapping) 
     157        if mapping is None: 
     158            return 
    188159 
    189160        # 2. Either find or create the assignment 
     
    212183        assignment_handler = IPortletAssignmentExportImportHandler(assignment) 
    213184        assignment_handler.import_assignment(portlet_interface, node) 
    214  
    215     def importBlacklist(self, obj, node): 
    216         """ Import a blacklist from a node 
    217         """ 
    218         manager = node.getAttribute('manager') 
    219         category = node.getAttribute('category') 
    220         status = node.getAttribute('status') 
    221          
    222         manager = getUtility(IPortletManager, name=manager) 
    223          
    224         assignable = queryMultiAdapter((obj, manager), ILocalPortletAssignmentManager) 
    225          
    226         if status.lower() == 'block': 
    227             assignable.setBlacklistStatus(category, True) 
    228         elif status.lower() == 'show': 
    229             assignable.setBlacklistStatus(category, False) 
    230         elif status.lower() == 'acquire': 
    231             assignable.setBlacklistStatus(category, None) 
    232  
    233185 
    234186logger = logging.getLogger('quintagroup.transmogrifier.portletsimporter') 
Note: See TracChangeset for help on using the changeset viewer.