Changeset 2951 in products for quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/filters.txt
- Timestamp:
- Nov 1, 2010 1:20:51 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/filters.txt
r2950 r2951 245 245 246 246 247 Creation own filters 248 ==================== 249 250 Suppouse we want to create own blackout filter, 251 which behave like id-filter, but with some differencies. 252 Our fitler has following format: 253 254 (+|-)<filtered id> 255 256 - when 1st sign "+" then only objects with <filtered id> 257 must leave after filetering, 258 - if 1st sign is "-" or all objects with <filtered id> must be 259 filtered-out (like default id filter) 260 261 You need create new IBlckoutFilter multi-adapter, 262 and register it with unique name. 263 264 >>> from zope.component import adapts 265 >>> from zope.interface import Interface, implements 266 >>> from zope.publisher.interfaces.browser import IBrowserRequest 267 >>> from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter 268 >>> class SignedIdFilter(object): 269 ... adapts(Interface, IBrowserRequest) 270 ... implements(IBlackoutFilter) 271 ... def __init__(self, context, request): 272 ... self.context = context 273 ... self.request = request 274 ... def filterOut(self, fdata, fargs): 275 ... sign = fargs[0] 276 ... fid = fargs[1:] 277 ... if sign == "+": 278 ... return [b for b in fdata if b.getId==fid] 279 ... elif sign == "-": 280 ... return [b for b in fdata if b.getId!=fid] 281 ... return fdata 282 283 284 Now register this new filter as named multiadapter ... 285 286 >>> from zope.component import provideAdapter 287 >>> provideAdapter(SignedIdFilter, 288 ... name=u'signedid') 289 290 So thet's all what neede to add new filter. 291 No test if newly added filter really take into consideration. 292 293 Check if white filtering ("+" prefix) work correctly. 294 Go to the edit form of the sitemap and add "signedid:+doc1" 295 to the "Blackout entries" field. 296 297 >>> browser.open(smedit_url) 298 >>> filtercontrol = browser.getControl("Blackout entries") 299 >>> filtercontrol.value = "signedid:+doc1" 300 >>> browser.getControl("Save").click() 301 >>> signedid_filter_content = browser.contents 302 303 As result - only objects with "doc1" id must present in the sitemap. 304 305 >>> signedid_filter_res = reloc.findall(signedid_filter_content) 306 >>> len(signedid_filter_res) == 2 307 True 308 >>> signedid_filter_res.sort() 309 >>> print "\n".join(signedid_filter_res) 310 /Members/test_user_1_/doc1 311 /doc1 312 313 314 An for the last - check black filtering ("-" prefix) is working. 315 Go to the edit form of the sitemap and add "signedid:-doc1" 316 to the "Blackout entries" field. 317 318 >>> browser.open(smedit_url) 319 >>> filtercontrol = browser.getControl("Blackout entries") 320 >>> filtercontrol.value = "signedid:-doc1" 321 >>> browser.getControl("Save").click() 322 >>> signedid_filter_content = browser.contents 323 324 As result - all except objects with "doc1" id must present in the sitemap. 325 326 >>> signedid_filter_res = reloc.findall(signedid_filter_content) 327 >>> len(signedid_filter_res) == 3 328 True 329 >>> signedid_filter_res.sort() 330 >>> print "\n".join(signedid_filter_res) 331 /Members/test_user_1_/doc2 332 /doc2 333 /front-page
Note: See TracChangeset
for help on using the changeset viewer.