source: products/SimpleBlog/trunk/content/blogfolder.py

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

Building directory structure

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1from Products.Archetypes.public import BaseFolderSchema, Schema
2from Products.Archetypes.public import StringField, LinesField, ComputedField, ComputedWidget
3from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget
4from Products.Archetypes.public import BaseFolder, registerType
5from Products.CMFCore import CMFCorePermissions
6
7from Products.ATContentTypes.content.base import  ATCTBTreeFolder, ATCTFolder
8from Products.ATContentTypes.lib.constraintypes import  ConstrainTypesMixinSchema
9
10import Products.SimpleBlog.Permissions
11
12
13schema = ConstrainTypesMixinSchema.copy() + ATCTFolder.schema.copy() +  Schema((
14    StringField('description',
15                isMetadata=1,
16                accessor='Description',
17                widget=TextAreaWidget(label='Description', 
18                                      label_msgid="label_blogfolder_description",
19                                      description_msgid="help_blogfolder_description",
20                                      i18n_domain="SimpleBlog",
21                                      description='Give a description for this SimpleBlog folder.'),),
22    ComputedField('existingCats', 
23                  expression='here.getInheritedCategories()',
24                  widget=ComputedWidget(label='Existing categories.', 
25                                  label_msgid="label_blogfolder_existing_cats",
26                                  i18n_domain="SimpleBlog",)),
27    LinesField('categories', 
28               widget=LinesWidget(label='Additional categories', 
29                                  label_msgid="label_additional_categories",
30                                  description_msgid="help_additional_categories",
31                                  i18n_domain="SimpleBlog",
32                                  description='Supply a list of possible additional categories that will be available to BlogEntries inside this folder or in sub folders.'),
33               )
34        ))
35
36
37class BlogFolder(ATCTBTreeFolder, ATCTFolder):
38    """
39    A folder object to store BlogEntries in
40    """
41    portal_type = meta_type = 'BlogFolder'
42    archetype_name = 'Blog Folder'
43    content_icon='blogfolder_icon.gif'
44    schema = schema
45    global_allow=0
46   
47    default_view = 'simpleblog_view_title_description'
48    immediate_view = 'simpleblog_view_title_description'
49    suppl_views = ('simpleblog_view_title_description', 'simpleblog_view_title', 'simpleblog_view_title_description_body',  'folder_listing')
50
51    filter_content_types=1   
52   
53    allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet')
54    filter_content_types=1
55
56    def canSetDefaultPage(self):
57        return False   
58   
59    def getInheritedCategories(self):
60        """ Traverse upwards in the tree to collect all the available categories."""
61        cats=[]
62        parent=self.aq_parent
63        portal=self.portal_url.getPortalObject()
64        categories='<ul>'
65        while parent!=portal:
66            if parent.portal_type=='Blog' or parent.portal_type=='BlogFolder':
67                # add cats
68                pcats=parent.getCategories()
69                for c in pcats:
70                    if c not in cats:
71                        categories=categories + '<li>' + c + '</li>'
72                        cats.append(c)
73                if parent.portal_type=='Blog':
74                    break
75            parent=parent.aq_parent
76        categories = categories + '</li>'
77        if len(cats)==0:
78            return '-'
79        else:
80            return categories
81
82    def getEntries(self, maxResults=None, **kwargs):
83        """ Return all the contained published entries, real objects, not the brains """
84        blog = self.simpleblog_tool.getFrontPage(self)
85        kwargs.update({'path':{'query':'/'+'/'.join(self.getPhysicalPath()),'level':0}})
86        return blog.getEntries(maxResults=maxResults, **kwargs)
87
88
89    def synContentValues(self):
90        entries = self.simpleblog_tool.searchForEntries(self, fromHere=1, maxResults=0)
91        objs = [e.getObject() for e in entries]
92        return objs
93
94registerType(BlogFolder)
Note: See TracBrowser for help on using the repository browser.