Changeset 3152 in products for quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser
- Timestamp:
- Apr 20, 2011 8:20:36 AM (13 years ago)
- Location:
- quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/commonview.py
r3002 r3152 7 7 from Products.CMFCore.utils import getToolByName 8 8 9 from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _ 9 from quintagroup.plonegooglesitemaps \ 10 import qPloneGoogleSitemapsMessageFactory as _ 10 11 from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter 11 from quintagroup.plonegooglesitemaps.browser.utils import additionalURLs, applyOperations 12 from quintagroup.plonegooglesitemaps.browser.utils import additionalURLs, \ 13 applyOperations 12 14 13 15 … … 33 35 numEntries = Attribute("Return number of entries") 34 36 37 35 38 class CommonSitemapView(BrowserView): 36 39 """ … … 42 45 # with mapping data 43 46 additional_maps = () 44 45 47 46 48 def __init__(self, context, request): … … 75 77 # Prepare dictionary for view 76 78 for url, b in brain_url_map.items(): 77 res_map = {'url' : url,}78 [res_map.update({k 79 res_map = {'url': url, } 80 [res_map.update({k: f(b)}) for k, f in self.additional_maps] 79 81 result.append(res_map) 80 82 self.num_entries = len(result) … … 91 93 4| path:./folder_near_sitemap/obj_in_folder 92 94 5| foo_filter:arg-1, arg-2 93 95 94 96 1->used default "id" filter - remove "index.html" objects; 95 97 2->explicit "id" filter - remove "index.html" objects; 96 98 3->"path" filter - remove /folder_1_level/obj_in_folder object, 97 99 path from the root of the plone site; 98 4->same to 3), but path get from the folder, where sitemap is located; 100 4->same to 3), but path get from the folder, where sitemap is 101 located; 99 102 5->filter name is "foo_filter" (must be registered IBlackoutFilter, 100 103 named "foo_filter"), which get filter arguments: arg-1, arg-2 101 104 102 105 Detailed explanation look in filters.txt doctest. 103 """ 106 """ 104 107 blackout_list = self.context.getBlackout_list() 105 108 for frec in blackout_list: -
quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/configletview.py
r3006 r3152 8 8 9 9 from quintagroup.plonegooglesitemaps.interfaces import ISitemap 10 from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _ 10 from quintagroup.plonegooglesitemaps \ 11 import qPloneGoogleSitemapsMessageFactory as _ 12 11 13 12 14 def splitNum(num): … … 14 16 prefn = 3 15 17 for c in str(num)[::-1]: 16 res.insert(0, c)17 if not len(res) %prefn:18 res.insert(0, ',')18 res.insert(0, c) 19 if not len(res) % prefn: 20 res.insert(0, ',') 19 21 prefn += 4 20 return "".join(res[0]==',' and res[1:] or res) 22 return "".join(res[0] == ',' and res[1:] or res) 23 21 24 22 25 class IConfigletSettingsView(Interface): … … 25 28 """ 26 29 27 sitemaps = Attribute("Returns mapping of sitemap's type to list of appropriate objects") 28 hasContentSM = Attribute("Returns boolean about existance of content sitemap") 29 hasMobileSM = Attribute("Returns boolean about existance of mobile sitemap") 30 sitemaps = Attribute("Returns mapping of sitemap's type to list of " \ 31 "appropriate objects") 32 hasContentSM = Attribute("Returns boolean about existance of content " \ 33 "sitemap") 34 hasMobileSM = Attribute("Returns boolean about existance of mobile " \ 35 "sitemap") 30 36 hasNewsSM = Attribute("Returns boolean about existance of news sitemap") 31 37 sm_types = Attribute("List of sitemap types") … … 46 52 def uploadVerificationFile(vfile): 47 53 """ Upload passed site verification file to the site. 48 On success - update googlesitemaps verification files list. 54 On success - update googlesitemaps verification files list. 49 55 Return tuple where : 50 56 1. boolean value - is verification file successfully created. … … 53 59 2.2. if failure - error descirption 54 60 """ 61 55 62 56 63 class ConfigletSettingsView(BrowserView): … … 65 72 self.request = request 66 73 67 self.tools = queryMultiAdapter((self.context, self.request), name="plone_tools") 68 self.pps = queryMultiAdapter((self.context, self.request), name="plone_portal_state") 69 self.sitemaps = [i.getObject() for i in self.tools.catalog()(portal_type='Sitemap')] 74 self.tools = queryMultiAdapter((self.context, self.request), 75 name="plone_tools") 76 self.pps = queryMultiAdapter((self.context, self.request), 77 name="plone_portal_state") 78 self.sitemaps = [i.getObject() for i in \ 79 self.tools.catalog()(portal_type='Sitemap')] 70 80 71 81 @property … … 88 98 sitemaps = {} 89 99 for sm in self.sitemaps: 90 smlist = sitemaps.setdefault(sm.getSitemapType(), [])91 smlist.append({'url': sm.absolute_url(),'id':sm.id})92 sitemaps['all'] = sitemaps.setdefault('content', []) + \93 sitemaps.setdefault('mobile', []) + \94 sitemaps.setdefault('news', [])100 smlist = sitemaps.setdefault(sm.getSitemapType(), []) 101 smlist.append({'url': sm.absolute_url(), 'id': sm.id}) 102 sitemaps['all'] = sitemaps.setdefault('content', []) + \ 103 sitemaps.setdefault('mobile', []) + \ 104 sitemaps.setdefault('news', []) 95 105 return sitemaps 96 106 … … 98 108 sitemaps = {} 99 109 for sm in self.sitemaps: 100 smlist = sitemaps.setdefault(sm.getSitemapType(), [])110 smlist = sitemaps.setdefault(sm.getSitemapType(), []) 101 111 smlist.append(sm.absolute_url()) 102 112 return sitemaps 103 113 104 114 def sitemapsDict(self): 105 content, mobile, news = [], [],[]115 content, mobile, news = [], [], [] 106 116 for sm in self.sitemaps: 107 117 data = self.getSMData(sm) … … 116 126 def getSMData(self, ob): 117 127 size, entries = self.getSitemapData(ob) 118 return {'sm_type' 119 'sm_id' 120 'sm_url' 121 'sm_size' 122 'sm_entries' 128 return {'sm_type': ob.getSitemapType().capitalize(), 129 'sm_id': ob.id, 130 'sm_url': ob.absolute_url(), 131 'sm_size': size and splitNum(size) or '', 132 'sm_entries': entries and splitNum(entries) or '', 123 133 } 124 134 … … 128 138 if view: 129 139 resp = self.request.RESPONSE 130 bview = queryMultiAdapter((ob, self.request), name=view)140 bview = queryMultiAdapter((ob, self.request), name=view) 131 141 if bview: 132 142 try: 133 143 size = len(bview()) 134 144 entries = bview.numEntries 135 self.request.RESPONSE.setHeader('Content-Type', 'text/html') 145 self.request.RESPONSE.setHeader('Content-Type', 146 'text/html') 136 147 except: 137 148 pass … … 140 151 def getVerificationFiles(self): 141 152 vfs = [] 142 props = getattr(self.tools.properties(), 'googlesitemap_properties')153 props = getattr(self.tools.properties(), 'googlesitemap_properties') 143 154 if props: 144 155 portal_ids = self.pps.portal().objectIds() 145 props_vfs = list(props.getProperty('verification_filenames', []))156 props_vfs = list(props.getProperty('verification_filenames', [])) 146 157 vfs = [vf for vf in props_vfs if vf in portal_ids] 147 if not props_vfs ==vfs:158 if not props_vfs == vfs: 148 159 props._updateProperty('verification_filenames', vfs) 149 160 return vfs … … 157 168 portal.manage_addFile(id="", file=vfile) 158 169 portal[vfilename].manage_addProperty( 159 'CreatedBy', 'quintagroupt.plonegooglesitemaps', 'string')170 'CreatedBy', 'quintagroupt.plonegooglesitemaps', 'string') 160 171 except BadRequestException, e: 161 172 return False, str(e) 162 173 else: 163 174 props = self.tools.properties().googlesitemap_properties 164 vfilenames = list(props.getProperty('verification_filenames', []))175 vfilenames = list(props.getProperty('verification_filenames', [])) 165 176 vfilenames.append(vfilename) 166 props.manage_changeProperties(verification_filenames =vfilenames)177 props.manage_changeProperties(verification_filenames=vfilenames) 167 178 return True, vfilename -
quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/mobilesitemapview.py
r2742 r3152 2 2 from quintagroup.plonegooglesitemaps.browser.commonview import * 3 3 4 MOBILE_INTERFACES = ['quintagroup.mobileextender.interfaces.IMobile',] 4 MOBILE_INTERFACES = ['quintagroup.mobileextender.interfaces.IMobile', ] 5 5 6 6 7 class MobileSitemapView(CommonSitemapView): … … 11 12 12 13 additional_maps = ( 13 ('modification_date', lambda x: DateTime(x.ModificationDate).HTML4()),14 ('modification_date', lambda x: DateTime(x.ModificationDate).HTML4()), 14 15 ) 15 16 16 17 def getFilteredObjects(self): 17 18 return self.portal_catalog( 18 path =self.search_path,19 portal_type =self.context.getPortalTypes(),20 review_state =self.context.getStates(),21 object_provides =MOBILE_INTERFACES,19 path=self.search_path, 20 portal_type=self.context.getPortalTypes(), 21 review_state=self.context.getStates(), 22 object_provides=MOBILE_INTERFACES, 22 23 ) -
quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/newssitemapview.py
r2751 r3152 7 7 reTrailingParenthtical = re.compile("\s*\(.*\)\s*", re.S) 8 8 9 formatDate = lambda d:DateTime(d).strftime("%Y-%m-%d") 9 formatDate = lambda d: DateTime(d).strftime("%Y-%m-%d") 10 10 11 11 12 class NewsSitemapView(CommonSitemapView): … … 17 18 @property 18 19 def additional_maps(self): 19 20 20 21 return ( 21 ('publication_date', lambda x:x.Date and formatDate(x.Date) or ""), 22 ('keywords', lambda x:x.Subject and ', '.join(x.Subject) or ""), 23 ('title', lambda x:x.Title or x.getId or x.id), 24 ('name', lambda x:x.Title and reTrailingParenthtical.sub("",x.Title) or ""), 25 ('language', lambda x:x.Language or self.default_language()), 26 ('access', lambda x:x.gsm_access or ""), 27 ('genres', lambda x:x.gsm_genres and ", ".join(x.gsm_genres) or ""), 28 ('stock', lambda x:x.gsm_stock or ""), 22 ('publication_date', lambda x: x.Date and \ 23 formatDate(x.Date) or ""), 24 ('keywords', lambda x: x.Subject and ', '.join(x.Subject) or ""), 25 ('title', lambda x: x.Title or x.getId or x.id), 26 ('name', lambda x: x.Title and \ 27 reTrailingParenthtical.sub("", x.Title) or ""), 28 ('language', lambda x: x.Language or self.default_language()), 29 ('access', lambda x: x.gsm_access or ""), 30 ('genres', lambda x: x.gsm_genres and \ 31 ", ".join(x.gsm_genres) or ""), 32 ('stock', lambda x: x.gsm_stock or ""), 29 33 ) 30 34 31 35 @memoize 32 36 def default_language(self): 33 pps = getMultiAdapter((self.context, self.request), name="plone_portal_state") 37 pps = getMultiAdapter((self.context, self.request), 38 name="plone_portal_state") 34 39 return pps.default_language 35 40 … … 37 42 min_date = DateTime() - 3 38 43 return self.portal_catalog( 39 path =self.search_path,40 portal_type =self.context.getPortalTypes(),41 review_state =self.context.getStates(),42 effective ={"query": min_date,43 "range": "min"}44 path=self.search_path, 45 portal_type=self.context.getPortalTypes(), 46 review_state=self.context.getStates(), 47 effective={"query": min_date, 48 "range": "min"} 44 49 ) -
quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/sitemapview.py
r2742 r3152 1 1 from DateTime import DateTime 2 2 from quintagroup.plonegooglesitemaps.browser.commonview import * 3 3 4 4 5 class SitemapView(CommonSitemapView): … … 9 10 10 11 additional_maps = ( 11 ('modification_date', lambda x: DateTime(x.ModificationDate).HTML4()),12 ('modification_date', lambda x: DateTime(x.ModificationDate).HTML4()), 12 13 ) 13 14 14 15 def getFilteredObjects(self): 15 16 return self.portal_catalog( 16 path =self.search_path,17 portal_type =self.context.getPortalTypes(),18 review_state =self.context.getStates()17 path=self.search_path, 18 portal_type=self.context.getPortalTypes(), 19 review_state=self.context.getStates() 19 20 ) -
quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/utils.py
r2181 r3152 14 14 _marker = [] 15 15 16 16 17 def searchAndReplace(string, what, withs): 17 18 """Emulate sed command s/""" 18 res = re.sub(what, withs,string)19 res = re.sub(what, withs, string) 19 20 return res 20 OPERATORS = {'s': searchAndReplace,} 21 OPERATORS = {'s': searchAndReplace, } 22 21 23 22 24 def applyOperations(objects, operations): 23 25 """Parse Operations """ 24 operations =[OPERATIONS_PARSE.match(op).groups() for op in operations]26 operations = [OPERATIONS_PARSE.match(op).groups() for op in operations] 25 27 result = {} 26 28 for ob in objects: … … 38 40 if url in result.keys(): 39 41 continue 40 #TODO: replace brain with only data necessary to 42 #TODO: replace brain with only data necessary to 41 43 #generate sitemap 42 result[url] =ob44 result[url] = ob 43 45 return result 46 44 47 45 48 def additionalURLs(context): … … 49 52 plone_home = getToolByName(context, 'portal_url')() 50 53 root = context.getPhysicalRoot().absolute_url() 51 URLs = 54 URLs = context.getUrls() 52 55 53 56 for url in URLs: 54 57 if ADD_ZOPE.match(url): 55 res.append(root +url)58 res.append(root + url) 56 59 elif ADD_PLONE.match(url): 57 res.append(plone_home +'/'+url)60 res.append(plone_home + '/' + url) 58 61 else: 59 62 res.append(url)
Note: See TracChangeset
for help on using the changeset viewer.