Changeset 1586 in products


Ignore:
Timestamp:
Jan 26, 2010 9:20:11 AM (14 years ago)
Author:
mylan
Message:

Revert lost changes of export/import portlets:blacklist export/import and purge option on importing

File:
1 edited

Legend:

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

    r1584 r1586  
    1212 
    1313from plone.portlets.interfaces import ILocalPortletAssignable, IPortletManager,\ 
    14     IPortletAssignmentMapping, IPortletAssignment 
    15 from plone.portlets.constants import CONTEXT_CATEGORY 
     14    IPortletAssignmentMapping, IPortletAssignment, ILocalPortletAssignmentManager 
     15from plone.portlets.constants import USER_CATEGORY, GROUP_CATEGORY, \ 
     16    CONTENT_TYPE_CATEGORY, CONTEXT_CATEGORY 
    1617from plone.app.portlets.interfaces import IPortletTypeInterface 
    1718from plone.app.portlets.exportimport.interfaces import IPortletAssignmentExportImportHandler 
     
    5859                for elem in self.exportAssignments(obj): 
    5960                    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) 
    6263                if root.hasChildNodes(): 
    6364                    self.doc.appendChild(root) 
     
    106107        return assignments 
    107108 
     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 
    108133class PortletsImporterSection(object): 
    109134    classProvides(ISectionBlueprint) 
     
    116141        self.pathkey = defaultMatcher(options, 'path-key', name, 'path') 
    117142        self.fileskey = defaultMatcher(options, 'files-key', name, 'files') 
     143        self.purge = options.get('purge', 'false').strip().lower() == 'true' and True or False 
    118144 
    119145    def __iter__(self): 
     
    132158            if obj is None:         # path doesn't exist 
    133159                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] 
    134168 
    135169            if ILocalPortletAssignable.providedBy(obj): 
     
    141175                    if elem.nodeName == 'assignment': 
    142176                        self.importAssignment(obj, elem) 
    143                     #elif elem.nodeName == 'blacklist': 
    144                         #self.importBlacklist(obj, elem) 
     177                    elif elem.nodeName == 'blacklist': 
     178                        self.importBlacklist(obj, elem) 
    145179 
    146180            yield item 
     
    183217        assignment_handler = IPortletAssignmentExportImportHandler(assignment) 
    184218        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 
    185238 
    186239logger = logging.getLogger('quintagroup.transmogrifier.portletsimporter') 
Note: See TracChangeset for help on using the changeset viewer.