source: products/qRSS2Syndication/branches/Plone3.1/utils.py @ 1591

Last change on this file since 1591 was 127, checked in by fenix, 15 years ago

add docstrings to all classes and functions

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