1 | from Products.Archetypes.public import BaseFolderSchema, Schema |
---|
2 | from Products.Archetypes.public import StringField, LinesField, ComputedField, ComputedWidget |
---|
3 | from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget |
---|
4 | from Products.Archetypes.public import BaseFolder, registerType |
---|
5 | from Products.CMFCore import CMFCorePermissions |
---|
6 | |
---|
7 | from Products.ATContentTypes.content.base import ATCTFolder |
---|
8 | |
---|
9 | import Products.SimpleBlog.Permissions |
---|
10 | |
---|
11 | |
---|
12 | schema = ATCTFolder.schema.copy() + Schema(( |
---|
13 | StringField('description', |
---|
14 | isMetadata=1, |
---|
15 | accessor='Description', |
---|
16 | widget=TextAreaWidget(label='Description', |
---|
17 | label_msgid="label_blogfolder_description", |
---|
18 | description_msgid="help_blogfolder_description", |
---|
19 | i18n_domain="SimpleBlog", |
---|
20 | description='Give a description for this SimpleBlog folder.'),), |
---|
21 | ComputedField('existingCats', |
---|
22 | expression='here.getInheritedCategories()', |
---|
23 | widget=ComputedWidget(label='Existing categories.', |
---|
24 | label_msgid="label_blogfolder_existing_cats", |
---|
25 | i18n_domain="SimpleBlog",)), |
---|
26 | LinesField('categories', |
---|
27 | widget=LinesWidget(label='Additional categories', |
---|
28 | label_msgid="label_additional_categories", |
---|
29 | description_msgid="help_additional_categories", |
---|
30 | i18n_domain="SimpleBlog", |
---|
31 | description='Supply a list of possible additional categories that will be available to BlogEntries inside this folder or in sub folders.'), |
---|
32 | ) |
---|
33 | )) |
---|
34 | |
---|
35 | |
---|
36 | class BlogFolder(ATCTFolder): |
---|
37 | """ |
---|
38 | A folder object to store BlogEntries in |
---|
39 | """ |
---|
40 | portal_type = meta_type = 'BlogFolder' |
---|
41 | archetype_name = 'Blog Folder' |
---|
42 | content_icon='blogfolder_icon.gif' |
---|
43 | schema = schema |
---|
44 | global_allow=0 |
---|
45 | |
---|
46 | default_view = 'simpleblog_view_title_description' |
---|
47 | immediate_view = 'simpleblog_view_title_description' |
---|
48 | suppl_views = ('simpleblog_view_title_description', 'simpleblog_view_title', 'simpleblog_view_title_description_body', 'folder_listing') |
---|
49 | |
---|
50 | filter_content_types=1 |
---|
51 | |
---|
52 | allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet') |
---|
53 | filter_content_types=1 |
---|
54 | |
---|
55 | def canSetDefaultPage(self): |
---|
56 | return False |
---|
57 | |
---|
58 | def getInheritedCategories(self): |
---|
59 | # traverse upwards in the tree to collect all the available categories |
---|
60 | # stop collecting when a SimpleBlog object is reached |
---|
61 | |
---|
62 | cats=[] |
---|
63 | parent=self.aq_parent |
---|
64 | portal=self.portal_url.getPortalObject() |
---|
65 | categories='<ul>' |
---|
66 | while parent!=portal: |
---|
67 | if parent.portal_type=='Blog' or parent.portal_type=='BlogFolder': |
---|
68 | # add cats |
---|
69 | pcats=parent.getCategories() |
---|
70 | for c in pcats: |
---|
71 | if c not in cats: |
---|
72 | categories=categories + '<li>' + c + '</li>' |
---|
73 | cats.append(c) |
---|
74 | if parent.portal_type=='Blog': |
---|
75 | break |
---|
76 | parent=parent.aq_parent |
---|
77 | categories = categories + '</li>' |
---|
78 | if len(cats)==0: |
---|
79 | return '-' |
---|
80 | else: |
---|
81 | return categories |
---|
82 | |
---|
83 | def getEntries(self, maxResults=None, **kwargs): |
---|
84 | """ Return all the contained published entries, real objects, not the brains """ |
---|
85 | # see simpleblog_tool.searchForEntries for API description |
---|
86 | |
---|
87 | query=kwargs |
---|
88 | |
---|
89 | publishedState = self.simpleblog_tool.getPublishedState() |
---|
90 | |
---|
91 | query['getAlwaysOnTop']=1 |
---|
92 | |
---|
93 | # first the items that need to be listed on top |
---|
94 | localOnTop = self.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.simpleblog_tool.getObjectPath(self),'level':0}, sort_order='reverse', sort_on='effective') |
---|
95 | localOnTop = [r.getObject() for r in localOnTop ] |
---|
96 | |
---|
97 | # then the other items |
---|
98 | query['getAlwaysOnTop']=0 |
---|
99 | localNoTop = self.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.simpleblog_tool.getObjectPath(self),'level':0}, sort_order='reverse', sort_on='effective') |
---|
100 | localNoTop= [r.getObject() for r in localNoTop] |
---|
101 | |
---|
102 | results = localOnTop+localNoTop |
---|
103 | |
---|
104 | if maxResults==0: |
---|
105 | return results |
---|
106 | elif maxResults==None: |
---|
107 | return results[:self.simpleblog_tool.getMaxItemsInPortlet()] |
---|
108 | else: |
---|
109 | return results[:maxResults] |
---|
110 | |
---|
111 | def synContentValues(self): |
---|
112 | # get brains for items that are published within the context of this blog. |
---|
113 | entries = self.simpleblog_tool.searchForEntries(self, fromHere=1, maxResults=0) |
---|
114 | |
---|
115 | # convert to objects |
---|
116 | objs = [e.getObject() for e in entries] |
---|
117 | return objs |
---|
118 | |
---|
119 | registerType(BlogFolder) |
---|