[1] | 1 | from Products.CMFCore.utils import getToolByName |
---|
| 2 | from Acquisition import aq_base |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | def setupRSS2Types(context, |
---|
| 6 | rss2_types = (), |
---|
| 7 | only_published = 0, |
---|
| 8 | include_subfolders = 0, |
---|
| 9 | articles_number = 20, |
---|
| 10 | REQUEST = None): |
---|
| 11 | """ Save all needed RSS2 properties into 'syndication_information' """ |
---|
| 12 | obj=aq_base(context) |
---|
| 13 | status = 'success' |
---|
| 14 | message = 'Your changes have been saved' |
---|
| 15 | |
---|
| 16 | syInfo = getattr(obj, 'syndication_information', None) |
---|
| 17 | |
---|
| 18 | if syInfo is None: |
---|
| 19 | message = 'Syndication is Disabled' |
---|
| 20 | status = 'failed' |
---|
| 21 | syInfo.rss2_types = list(rss2_types) |
---|
| 22 | syInfo.only_published = only_published |
---|
| 23 | syInfo.include_subfolders = include_subfolders |
---|
| 24 | syInfo.max_items = articles_number |
---|
| 25 | return status, message |
---|
| 26 | |
---|
| 27 | def getRSS2Properties(context): |
---|
| 28 | """ Return directory of RSS2 properties from 'syndication_information' """ |
---|
| 29 | obj=aq_base(context) |
---|
| 30 | syInfo = getattr(obj, 'syndication_information', None) |
---|
| 31 | syPropeties={} |
---|
| 32 | syPropeties['rss2_types'] = getattr(syInfo,'rss2_types',[]) |
---|
| 33 | syPropeties['only_published'] = getattr(syInfo,'only_published',0) |
---|
| 34 | syPropeties['include_subfolders'] = getattr(syInfo,'include_subfolders',0) |
---|
| 35 | syPropeties['articles_number'] =int(getattr(syInfo,'max_items',20)) |
---|
| 36 | return syPropeties |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | def listSyndicatableContent(context): |
---|
| 41 | """ List folder contents - catalog query |
---|
| 42 | * filtered types only |
---|
| 43 | * sort on effective |
---|
| 44 | * take only first 'articles_number' of elements """ |
---|
| 45 | res = [] |
---|
| 46 | ps = getToolByName(context,'portal_syndication') |
---|
| 47 | cpath = '/'.join(context.getPhysicalPath()) |
---|
| 48 | syProperties = {} |
---|
| 49 | syProperties = getRSS2Properties(context) |
---|
| 50 | include_subfolders = 0 |
---|
| 51 | if ps.isSyndicationAllowed(context): |
---|
| 52 | types = syProperties['rss2_types'] |
---|
| 53 | only_published = syProperties['only_published'] |
---|
| 54 | include_subfolders = syProperties['include_subfolders'] |
---|
| 55 | articles_number = syProperties['articles_number'] |
---|
| 56 | |
---|
| 57 | catalog = getToolByName(context,'portal_catalog') |
---|
| 58 | args = {'portal_type':types, |
---|
| 59 | 'path':cpath, |
---|
| 60 | 'sort_on':'effective', |
---|
| 61 | 'sort_order':'reverse',} |
---|
| 62 | if only_published: |
---|
| 63 | args['review_state'] = 'published' |
---|
| 64 | if include_subfolders == 0: |
---|
| 65 | args['sort_limit'] = articles_number |
---|
| 66 | res=catalog.searchResults(args) |
---|
| 67 | path_length=len(cpath)+1 |
---|
| 68 | res1=[] |
---|
| 69 | if include_subfolders == 0: |
---|
| 70 | for i in res : |
---|
| 71 | if i.getPath()[path_length:].find('/')<0: |
---|
| 72 | res1.append(i) |
---|
| 73 | res = res1[:articles_number] |
---|
| 74 | res = [r.getObject() for r in res] |
---|
| 75 | return res |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | def getFileContentType(context): |
---|
| 79 | """ !ATAudio specific only! Get the content type of file field method """ |
---|
| 80 | return context.Schema()['file'].getContentType(context) |
---|