source: products/qRSS2Syndication/tags/0.4.5/utils.py

Last change on this file was 1, checked in by myroslav, 18 years ago

Building directory structure

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