Changeset 2997 in products
- Timestamp:
- Nov 11, 2010 1:16:53 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/filters.txt
r2992 r2997 3 3 ================== 4 4 5 Sitemaps has option to filterout objects, which shouldn't present 6 in a sitemap. This option is accessable in sitemap edit form 7 and present as "Blackout entries" lines field. 8 9 In earlier (<3.0.7 and <4.0.1) versions of the package the field 10 filter-out objects only by its ids, and looks like: 5 Filtering introductioin 6 ======================= 7 8 Sitemap portal type has an option, designed to filter out 9 objects which should be excluded from a sitemap. This option is 10 accessable in sitemap edit form and is labeled as 11 "Blackout entries". 12 13 In earlier versions of the package (<4.0.1 for plone-4 branch 14 and <3.0.7 for plone-3 branch) this field allowed to 15 filter objects only by their ids, and looked like: 11 16 12 17 <pre> … … 15 20 </pre> 16 21 17 So all objects with "index.html" or "index_html" ids excluded18 from the sitemap.19 20 In the new versions of GoogleSitemaps filtering was rema ked21 to pluggable architecture. Now filters are named mutli adapters.22 By default there are only two most usefulfilters - "id" and22 So, all objects with "index.html" or "index_html" ids were 23 excluded from the sitemap. 24 25 In the new versions of GoogleSitemaps filtering was remade 26 to pluggable architecture. Now filters became named multi 27 adapters. There are only two default filters - "id" and 23 28 "path". 24 29 25 Because of different filters can be used - new syntaxapplied30 Since different filters can be used - new syntax was applied 26 31 to the "Blackout entries" field. Every record in the field 27 should follow the spec :32 should follow the specification: 28 33 29 34 [<filter name>:]<filter arguments> 30 35 31 By default (if no <filter name> specified) - "id" filter will 32 be used. If <filter name> specified - system looking for 33 <filter name> name multiadapter to IBlackoutFilter interface. 34 If such multiadapter was not found - it's ignored silently. 35 36 37 Setup 38 ===== 39 40 First, we must perform some setup. We use the testbrowser that is shipped 41 with Five, as this provides proper Zope 2 integration. Most of the 42 documentation, though, is in the underlying zope.testbrower package. 36 If no <filter name> is specified - "id" filter will 37 be used. If <filter name> is specified - system will look 38 for <filter name>-named multiadapter to IBlackoutFilter 39 interface. If such multiadapter is not found - filter 40 will be ignored without raising any errors. 41 42 43 Following parts demonstrate working of the filtering. 44 Aspects of default filters ("id" and "path") 45 are considered yet. 46 47 Setup demonstration environment 48 =============================== 49 50 First, we must perform some setup. We use the testbrowser that is 51 shipped with Five, as this provides proper Zope 2 integration. Most 52 of the documentation, though, is in the underlying zope.testbrower 53 package. 43 54 44 55 >>> from Products.Five.testbrowser import Browser … … 46 57 >>> portal_url = self.portal.absolute_url() 47 58 48 The following is useful when writing and debugging testbrowser tests. It lets49 us see all error messages in the error_log.59 The following is useful when writing and debugging testbrowser tests. 60 It lets us see all error messages in the error_log. 50 61 51 62 >>> self.portal.error_log._ignored_exceptions = () 52 63 53 With that in place, we can go to the portal front page and log in. We will54 do this using the default user from PloneTestCase:64 With that in place, we can go to the portal front page and log in. 65 We will do this using the default user from PloneTestCase: 55 66 56 67 >>> from Products.PloneTestCase.setup import portal_owner, default_password … … 74 85 75 86 76 77 87 Functionality 78 88 ============= 79 89 80 First create s everal documentsfor demonstrations.90 First create some content for demonstrations. 81 91 82 92 In the root of the portal … … 90 100 >>> self.addDocument(self.folder, "doc2", "Member Document 2 text") 91 101 92 We need add sitemap, of corse,for demonstration.102 We need to add sitemap for demonstration. 93 103 94 104 >>> browser.open(portal_url + "/prefs_gsm_settings") … … 96 106 97 107 Now we bring-up to edit form of the newly created content sitemap. 98 We interested in two things: "Blackout entries" field must present 99 in the form and it should be empty by default. 100 101 108 We are interested in two things: "Blackout entries" field must 109 present in the form and by default it should be empty. 110 102 111 >>> file("/tmp/browser.0.html","wb").write(browser.contents) 103 112 >>> blackout_list = browser.getControl("Blackout entries") … … 118 127 119 128 120 After adding "Content Sitemap", "sitemap.xml" link will appear 121 on "Settings" tab page of Plone Google Sitemap configlet. 129 "sitemap.xml" link should appear in "Settings" page of the 130 Plone Google Sitemap configlet when "Content Sitemap" 131 was added. 122 132 123 133 >>> browser.open(portal_url + "/prefs_gsm_settings") … … 125 135 >>> smedit_url = smedit_link.url 126 136 127 This link leadto edit form of the newly created sitemap.xml.128 Alsoprepare view link to simplifier following demonstrations.137 This link points to edit form of the newly created sitemap.xml. 138 Let prepare view link to simplifier following demonstrations. 129 139 130 140 >>> smedit_url.endswith("sitemap.xml/edit") … … 136 146 ========== 137 147 138 Resulted sitemap has no filters - all document should presentin it.148 Created sitemap has no filters and all documents should appear in it. 139 149 140 150 >>> browser.open(smview_url) … … 142 152 >>> no_filters_content = browser.contents 143 153 144 Check if resulted page is realsitemap...154 Check if resulted page really is sitemap... 145 155 146 156 >>> print browser.contents … … 148 158 149 159 150 To check urls, which pass filters - create regular expression...160 Create regular expression, which help us to test which urls pass the filters. 151 161 152 162 >>> reloc = re.compile("<loc>%s([^\<]*)</loc>" % self.portal.absolute_url(), re.S) 153 163 154 With help of reloc regular expression - check if all 4 documents + default 155 front-page present in the sitemapwithout filters.164 Test if all 4 documents and default front-page present in the sitemap 165 without filters. 156 166 157 167 >>> no_filters_res = reloc.findall(no_filters_content) … … 181 191 >>> id_filter_content = browser.contents 182 192 183 As result - all "doc1" and "front-page" documents must be184 filtered-out from thesitemap.193 "doc1" and "front-page" documents should be excluded from the 194 sitemap. 185 195 186 196 >>> id_filter_res = reloc.findall(id_filter_content) … … 194 204 =================== 195 205 196 Suppouse we wont to filter-out doc2 of the test_user_1_'s (but 197 not from the portal root) and the front-page from the portal root. 206 Suppouse we wont to exclude the "front_page" from portal root 207 and "doc2" document, located in test_user_1_ home folder, 208 but leave untouched "doc2" in portal root with all other objects. 198 209 199 210 >>> browser.open(smedit_url) … … 206 217 >>> path_filter_content = browser.contents 207 218 208 As result - "doc2" of the pointed member and "front-page" documents 209 must be filtered-outfrom the sitemap.219 "/Members/test_user_1_/doc2" and "/front_page" objects should 220 be excluded from the sitemap. 210 221 211 222 >>> path_filter_res = reloc.findall(path_filter_content) 212 223 >>> path_filter_res.sort() 213 224 >>> print "\n".join(path_filter_res) 214 /Membe rs/test_user_1_/doc1225 /Membe rs/test_user_1_/doc1 215 226 /doc1 216 227 /doc2 … … 220 231 ==================== 221 232 222 Lets check what filter should be used for old-feshion filters 223 (without any filter name prefixes)? 224 225 Go to the edit form of the sitemap and add "doc1" and front-page 226 lines without any filter name prefix to the "Blackout entries" 227 field. 233 Now I have the question: "What filter will be used when no 234 filter name prefix was specified (old-fashion filters for 235 example)?" 236 237 Go to the edit form of the sitemap and add "doc1" and 238 "front-page" lines without any filter name prefix to the 239 "Blackout entries" field. 228 240 229 241 >>> browser.open(portal_url + "/sitemap.xml/edit") … … 236 248 >>> default_filter_content = browser.contents 237 249 238 By default "id" filter must be used, so all "doc1" and "front-page" 239 objects must be filtered-outfrom the sitemap.250 "id" filter must be used as default filter. So all "doc1" and 251 "front-page" objects should be excluded from the sitemap. 240 252 241 253 >>> default_filter_res = reloc.findall(default_filter_content) … … 250 262 251 263 Suppouse we want to create own blackout filter, 252 which behave like id-filter, but withsome differencies.264 which behave like id-filter, but has some differencies. 253 265 Our fitler has following format: 254 266 255 267 (+|-)<filtered id> 256 268 257 - when 1st sign "+" then only objects with <filtered id> 258 must leave after filetering, 259 - if 1st sign is "-" or all objects with <filtered id> must be 260 filtered-out (like default id filter) 269 - when 1st sign is "+" then only objects with <filtered id> 270 should be leaved in sitemap after filetering; 271 - if 1st sign is "-" then all objects with <filtered id> 272 should be excluded from the sitemap (like default id 273 filter). 261 274 262 275 You need create new IBlckoutFilter multi-adapter, … … 289 302 ... name=u'signedid') 290 303 291 So th et's all what needeto add new filter.292 No test if newly added filter really take into consideration.293 294 Check if white filtering ("+" prefix) workcorrectly.295 Go to theedit form of the sitemap and add "signedid:+doc1"304 So that's all what needed to add new filter. 305 Now test newly created filter. 306 307 Check whether white filtering ("+" prefix) works correctly. 308 Go to edit form of the sitemap and add "signedid:+doc1" 296 309 to the "Blackout entries" field. 297 310 … … 304 317 >>> signedid_filter_content = browser.contents 305 318 306 As result - only objects with "doc1" id must presentin the sitemap.319 Only objects with "doc1" id should be leaved in the sitemap. 307 320 308 321 >>> signedid_filter_res = reloc.findall(signedid_filter_content) … … 313 326 314 327 315 An for the last - check black filtering ("-" prefix) is working. 328 And for the last - check wheter black filtering ("-" prefix) 329 works correctly. 316 330 Go to the edit form of the sitemap and add "signedid:-doc1" 317 331 to the "Blackout entries" field. … … 325 339 >>> signedid_filter_content = browser.contents 326 340 327 As result - all except objects with "doc1" id must present in the sitemap. 341 All objects except those having "doc1" id must be included in 342 the sitemap. 328 343 329 344 >>> signedid_filter_res = reloc.findall(signedid_filter_content)
Note: See TracChangeset
for help on using the changeset viewer.