Changeset 3065 in products
- Timestamp:
- Jan 27, 2011 5:06:39 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.transmogrifier/branches/plone-2.1/quintagroup.transmogrifier/quintagroup/transmogrifier/catalogsource.py
r436 r3065 1 import copy 2 import logging 3 1 4 from zope.interface import classProvides, implements 2 5 from zope.app.annotation.interfaces import IAnnotations … … 7 10 8 11 from quintagroup.transmogrifier.logger import VALIDATIONKEY 12 13 logger = logging.getLogger("CatalogSourceSection") 9 14 10 15 class CatalogSourceSection(object): … … 22 27 self.pathkey = options.pop('path-key', '_path') 23 28 self.entrieskey = options.pop('entries-key', '_entries') 29 30 # handle exclude-contained parameter 31 if "exclude-contained" in options.keys(): 32 self.exclude_contained = options.pop('exclude-contained') 33 self.exclude_contained = self.exclude_contained == "true" 34 else: 35 self.exclude_contained = False 24 36 25 37 # remove 'blueprint' option - it cannot be a query … … 43 55 44 56 exported = [] 57 exported_parents = [] 45 58 46 59 results = list(self.catalog(**self.query)) 47 60 results.sort(key=lambda x: x.getPath()) 61 48 62 for brain in results: 49 63 # discussion items are indexed and they must be replaced to … … 68 82 container_path = path.rsplit('/', 1)[0] 69 83 while container_path: 84 70 85 if container_path in exported: 71 86 container_path = container_path.rsplit('/', 1)[0] 72 87 continue 73 contained = self.getContained(container_path) 88 89 exported_parents.append(container_path) 90 91 contained = self.getContained(container_path, results, exported_parents) 92 74 93 if contained: 75 94 exported.append(container_path) … … 79 98 }) 80 99 container_path = container_path.rsplit('/', 1)[0] 100 81 101 containers.reverse() 82 102 # order metter for us … … 89 109 } 90 110 if brain.is_folderish: 91 contained = self.getContained(path )111 contained = self.getContained(path, results, exported_parents) 92 112 if contained: 93 113 item[self.entrieskey] = contained … … 100 120 del self.anno[VALIDATIONKEY] 101 121 102 def getContained(self, path ):122 def getContained(self, path, orignal_results, parents): 103 123 """ Return list of (object_id, portal_type) for objects that are returned by catalog 104 124 and contained in folder with given 'path'. … … 106 126 results = [] 107 127 seen = [] 108 raw_results = self.catalog(path=path, **self.query) 128 129 130 # Remove the orignal path element from the query if there was one 131 query = copy.deepcopy(self.query) 132 if "path" in query: 133 del query["path"] 134 135 raw_results = self.catalog(path=path, **query) 136 109 137 for brain in raw_results: 110 138 current = brain.getPath() … … 117 145 # object stored in subfolders, we need append to results their parent folder 118 146 parent_path = '/'.join([path, relative.split('/', 1)[0]]) 119 if parent_path not in seen: 147 if parent_path not in seen: 120 148 res = self.catalog(path=path) #, meta_type='Folder') 121 149 for i in res: … … 128 156 seen.append(current) 129 157 results.append(brain) 130 contained = [(i.getId, str(i.portal_type)) for i in results] 158 159 def filter(r): 160 161 # Parent objects must be allowed always 162 for parent in parents: 163 if r.getPath() == parent: 164 return True 165 166 if r["UID"] in allowed_uids: 167 return True 168 else: 169 logger.info("Excluded contained item as it did not match the orignal catalog query:" + str(r.getPath())) 170 171 if self.exclude_contained and orignal_results is not None: 172 # Filter contained results against our query, so that 173 # we do not export results from parent objects which did not match 174 # Build list of allowed object UIDs - 175 allowed_uids = [ r["UID"] for r in orignal_results ] 176 177 # All parents must be allowed always 178 filtered_results = [ r for r in results if filter(r) == True ] 179 else: 180 # Don't filter child items 181 filtered_results = results 182 183 contained = [(i.getId, str(i.portal_type)) for i in filtered_results ] 184 131 185 return tuple(contained)
Note: See TracChangeset
for help on using the changeset viewer.