Changeset 1461 in products
- Timestamp:
- Dec 16, 2009 6:39:42 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/views.py
r1460 r1461 12 12 PROP_PREFIX = 'qSEO_' 13 13 SUFFIX = '_override' 14 PROP_CUSTOM_PREFIX = 'qSEO_custom_' 15 14 16 try: 15 17 from quintagroup.canonicalpath.interfaces import ICanonicalPath … … 303 305 template = ViewPageTemplateFile('templates/seo_context_properties.pt') 304 306 305 def updateSEOProps(self, **kw): 307 308 def test( self, condition, first, second ): 309 """ 310 """ 311 return condition and first or second 312 313 def manageSEOProps(self, **kw): 314 context = aq_inner(self.context) 306 315 delete_list, overrides, values = [], [], [] 307 316 seo_items = dict([(k[len(SEO_PREFIX):],v) for k,v in kw.items() if k.startswith(SEO_PREFIX)]) … … 312 321 values.append(key) 313 322 314 315 323 for val in values: 316 324 if val in overrides and seo_items[val+SUFFIX]: 317 se tProperty(context,PROP_PREFIX+val, seo_items[val])325 self.setProperty(PROP_PREFIX+val, seo_items[val]) 318 326 elif context.hasProperty(PROP_PREFIX+val): 319 327 delete_list.append(PROP_PREFIX+val) 320 328 if delete_list: context.manage_delProperties(delete_list) 321 329 330 def delSEOCustomMetaTags(self): 331 context = self.context 332 delete_list = [] 333 for property, value in context.propertyItems(): 334 if property.find(PROP_CUSTOM_PREFIX) == 0 and len(property) > len(PROP_CUSTOM_PREFIX): 335 delete_list.append(property) 336 if delete_list: context.manage_delProperties(delete_list) 337 338 def delSEOCustomMetaTag(self, custommetatag): 339 context = self.context 340 if context.hasProperty(custommetatag): 341 context.manage_delProperties(custommetatag) 342 343 def manageSEOCustomMetaTags(self, **kw): 344 context = aq_inner(self.context) 345 if kw.has_key('seo_custommetatags_override'): 346 if kw.get('seo_custommetatags_override'): 347 custommetatags = kw.get('seo_custommetatags', {}) 348 self.updateSEOCustomMetaTags(custommetatags) 349 else: 350 self.delSEOCustomMetaTags() 351 elif kw.get('seo_custommetatags'): 352 self.delSEOCustomMetaTags() 353 354 def updateSEOCustomMetaTags(self, custommetatags): 355 context = aq_inner(self.context) 356 site_properties = getToolByName(context, 'portal_properties') 357 globalCustomMetaTags = [] 358 359 if hasattr(site_properties, 'seo_properties'): 360 custom_meta_tags = getattr(site_properties.seo_properties, 'default_custom_metatags', []) 361 for tag in custom_meta_tags: 362 name_value = tag.split(SEPERATOR) 363 if name_value[0]: 364 globalCustomMetaTags.append({'meta_name' : name_value[0], 365 'meta_content' : len(name_value) == 1 and '' or name_value[1]}) 366 367 for tag in custommetatags: 368 meta_name, meta_content = tag['meta_name'], tag['meta_content'] 369 if meta_name: 370 if not [gmt for gmt in globalCustomMetaTags if (gmt['meta_name']==meta_name and gmt['meta_content']==meta_content)]: 371 self.setProperty('%s%s' % (PROP_CUSTOM_PREFIX, meta_name), meta_content) 372 373 def setSEOCustomMetaTags(self, custommetatags=None): 374 context = aq_inner(self.context) 375 if custommetatags is not None: 376 if len(custommetatags): 377 self.delSEOCustomMetaTags() 378 else: 379 for k, v in custommetatags.items(): 380 self.setProperty('%s%s' % (PROP_CUSTOM_PREFIX, meta_name), meta_content) 381 322 382 def setProperty(self, property, value, type='string'): 323 context = self.context383 context = aq_inner(self.context) 324 384 if context.hasProperty(property): 325 385 context.manage_changeProperties({property: value}) … … 327 387 context.manage_addProperty(property, value, type) 328 388 329 330 389 def __call__( self ): 331 390 """ … … 336 395 submitted = form.get('form.submitted', False) 337 396 if submitted: 338 self.updateSEOProps(**form) 339 340 341 #delete_list = [] 342 343 ## update custom meta tags 344 #property_prefix = 'qSEO_custom_' 345 #custom_existing = [] 346 #for property, value in context.propertyItems(): 347 #if property.find(property_prefix) == 0 and len(property) > len(property_prefix): 348 #custom_existing.append(property) 349 350 #globalCustomMetaTags = [] 351 #site_properties = getToolByName(context, 'portal_properties') 352 #if hasattr(site_properties, 'seo_properties'): 353 #custom_meta_tags = getattr(site_properties.seo_properties, 'default_custom_metatags', []) 354 #for tag in custom_meta_tags: 355 #name_value = tag.split(SEPERATOR) 356 #if name_value[0]: 357 #globalCustomMetaTags.append({'meta_name' : name_value[0], 358 #'meta_content' : len(name_value) == 1 and '' or name_value[1]}) 359 360 #custom_updated = [] 361 #for tag in custommetatags: 362 #meta_name, meta_content = tag['meta_name'], tag['meta_content'] 363 #if meta_name: 364 #if not [gmt for gmt in globalCustomMetaTags if (gmt['meta_name']==meta_name and gmt['meta_content']==meta_content)]: 365 #setProperty(context, '%s%s' % (property_prefix, meta_name), meta_content) 366 #custom_updated.append('%s%s' % (property_prefix, meta_name)) 367 368 ##add not updated custom metatags to delete list 369 #for tag in custom_existing: 370 #if tag not in custom_updated: 371 #delete_list.append(tag) 372 373 #msg ='Content SEO properties have been saved.' 374 #try: 375 #context.plone_utils.addPortalMessage(msg) 376 #return state 377 #except AttributeError: 378 #return state.set(context=context, portal_status_message=msg) 397 self.manageSEOProps(**form) 398 self.manageSEOCustomMetaTags(**form) 399 msg = 'Content SEO properties have been saved.' 400 context.plone_utils.addPortalMessage(msg) 379 401 return request.response.redirect(self.context.absolute_url()) 380 402 else:
Note: See TracChangeset
for help on using the changeset viewer.