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

Last change on this file since 113 was 113, checked in by chervol, 18 years ago

fixed metadata save

File size: 2.8 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                    REQUEST = None):
11    """ Save all needed RSS2 properties into 'syndication_information' """
12    import pdb;pdb.set_trace()
13    obj=aq_base(context)
14    status = 'success'
15    message = 'Your changes have been saved'
16
17    syInfo = getattr(obj, 'syndication_information', None)
18
19    if syInfo is None:
20        message = 'Syndication is Disabled'
21        status = 'failed'
22    syInfo.rss2_types = list(rss2_types)
23    syInfo.only_published = only_published
24    syInfo.include_subfolders = include_subfolders
25    syInfo.max_items = int(articles_number)
26    return status, message
27
28def getRSS2Properties(context):
29    """ Return directory of RSS2 properties from 'syndication_information' """
30    obj=aq_base(context)
31   
32    syInfo = getattr(obj, 'syndication_information', None)
33    syPropeties={}
34    syPropeties['rss2_types'] = getattr(syInfo,'rss2_types',[])
35    syPropeties['only_published'] = getattr(syInfo,'only_published',0)
36    syPropeties['include_subfolders'] = getattr(syInfo,'include_subfolders',0)
37    syPropeties['articles_number'] =int(getattr(syInfo,'max_items',20))
38    return  syPropeties
39
40
41
42def listSyndicatableContent(context):
43    """ List folder contents - catalog query
44        * filtered types only
45        * sort on effective
46        * take only first 'articles_number' of elements """
47    res = []
48    ps = getToolByName(context,'portal_syndication')
49    if ps.isSyndicationAllowed(context):
50        cpath = '/'.join(context.getPhysicalPath())
51        syProperties = getRSS2Properties(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            path_length=len(cpath)+1
66            for i in catalog.searchResults(args):
67                if i.getPath()[path_length:].find('/')<0:
68                    res.append(i)
69            res = res[:articles_number]
70        else:
71            args['sort_limit'] = articles_number
72            res=catalog.searchResults(args)
73        res = [r.getObject() for r in res]
74    return res
75
76
77def getFileContentType(context):
78    """  !ATAudio specific only! Get the content type of file field method """
79    return context.Schema()['file'].getContentType(context)
Note: See TracBrowser for help on using the repository browser.