[1] | 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 | |
---|
| 8 | import Permissions |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | schema = BaseFolderSchema + Schema(( |
---|
| 12 | StringField('id', |
---|
| 13 | required=0, ## Still actually required, but |
---|
| 14 | ## the widget will supply the missing value |
---|
| 15 | ## on non-submits |
---|
| 16 | mode="rw", |
---|
| 17 | accessor="getId", |
---|
| 18 | mutator="setId", |
---|
| 19 | default=None, |
---|
| 20 | widget=IdWidget(label="Short Name", |
---|
| 21 | label_msgid="label_short_name", |
---|
| 22 | description="Should not contain spaces, underscores or mixed case. "\ |
---|
| 23 | "Short Name is part of the item's web address.", |
---|
| 24 | description_msgid="help_shortname", |
---|
| 25 | visible={'view' : 'visible'}, |
---|
| 26 | i18n_domain="plone"), |
---|
| 27 | ), |
---|
| 28 | StringField('title', |
---|
| 29 | required=1, |
---|
| 30 | searchable=1, |
---|
| 31 | default='', |
---|
| 32 | accessor='Title', |
---|
| 33 | widget=StringWidget(label_msgid="label_title", |
---|
| 34 | description_msgid="help_title", |
---|
| 35 | i18n_domain="plone"), |
---|
| 36 | ), |
---|
| 37 | StringField('description', |
---|
| 38 | isMetadata=1, |
---|
| 39 | accessor='Description', |
---|
| 40 | widget=TextAreaWidget(label='Description', |
---|
| 41 | label_msgid="label_blogfolder_description", |
---|
| 42 | description_msgid="help_blogfolder_description", |
---|
| 43 | i18n_domain="SimpleBlog", |
---|
| 44 | description='Give a description for this SimpleBlog folder.'),), |
---|
| 45 | ComputedField('existingCats', |
---|
| 46 | expression='here.getInheritedCategories()', |
---|
| 47 | widget=ComputedWidget(label='Existing categories.', |
---|
| 48 | label_msgid="label_blogfolder_existing_cats", |
---|
| 49 | i18n_domain="SimpleBlog",)), |
---|
| 50 | LinesField('categories', |
---|
| 51 | widget=LinesWidget(label='Additional categories', |
---|
| 52 | label_msgid="label_additional_categories", |
---|
| 53 | description_msgid="help_additional_categories", |
---|
| 54 | i18n_domain="SimpleBlog", |
---|
| 55 | description='Supply a list of possible additional categories that will be available to BlogEntries inside this folder or in sub folders.'), |
---|
| 56 | ) |
---|
| 57 | )) |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | class BlogFolder(BaseFolder): |
---|
| 61 | """ |
---|
| 62 | A folder object to store BlogEntries in |
---|
| 63 | """ |
---|
| 64 | allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet') |
---|
| 65 | filter_content_types=1 |
---|
| 66 | |
---|
| 67 | global_allow=0 |
---|
| 68 | |
---|
| 69 | schema=schema |
---|
| 70 | |
---|
| 71 | content_icon='blogfolder_icon.gif' |
---|
| 72 | |
---|
| 73 | actions = ({ |
---|
| 74 | 'id': 'view', |
---|
| 75 | 'name': 'View', |
---|
| 76 | 'action': 'string:${object_url}/blogfolder_view', |
---|
| 77 | 'permissions': (CMFCorePermissions.View,) |
---|
| 78 | }, |
---|
| 79 | {'id': 'references', |
---|
| 80 | 'name': 'References', |
---|
| 81 | 'action': 'string:${object_url}/reference_edit', |
---|
| 82 | 'permissions': (CMFCorePermissions.ModifyPortalContent,), |
---|
| 83 | 'visible':0}, |
---|
| 84 | {'id': 'metadata', |
---|
| 85 | 'name': 'Properties', |
---|
| 86 | 'action': 'string:${object_url}/base_metadata', |
---|
| 87 | 'permissions': (CMFCorePermissions.ModifyPortalContent,), |
---|
| 88 | 'visible':0}) |
---|
| 89 | |
---|
| 90 | def getInheritedCategories(self): |
---|
| 91 | # traverse upwards in the tree to collect all the available categories |
---|
| 92 | # stop collecting when a SimpleBlog object is reached |
---|
| 93 | |
---|
| 94 | cats=[] |
---|
| 95 | parent=self.aq_parent |
---|
| 96 | portal=self.portal_url.getPortalObject() |
---|
| 97 | categories='<ul>' |
---|
| 98 | while parent!=portal: |
---|
| 99 | if parent.portal_type=='Blog' or parent.portal_type=='BlogFolder': |
---|
| 100 | # add cats |
---|
| 101 | pcats=parent.getCategories() |
---|
| 102 | for c in pcats: |
---|
| 103 | if c not in cats: |
---|
| 104 | categories=categories + '<li>' + c + '</li>' |
---|
| 105 | cats.append(c) |
---|
| 106 | if parent.portal_type=='Blog': |
---|
| 107 | break |
---|
| 108 | parent=parent.aq_parent |
---|
| 109 | categories = categories + '</li>' |
---|
| 110 | if len(cats)==0: |
---|
| 111 | return '-' |
---|
| 112 | else: |
---|
| 113 | return categories |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | def synContentValues(self): |
---|
| 117 | # get brains for items that are published within the context of this blog. |
---|
| 118 | entries = self.simpleblog_tool.searchForEntries(self, fromHere=1, maxResults=0) |
---|
| 119 | |
---|
| 120 | # convert to objects |
---|
| 121 | objs = [e.getObject() for e in entries] |
---|
| 122 | return objs |
---|
| 123 | |
---|
| 124 | registerType(BlogFolder) |
---|