source: trunk/BlogPost.py @ 441

Revision 441, 7.1 KB checked in by jukka, 13 years ago (diff)

Fixed #460, spent 6h. There is now 'activity score' for every member. Tagclouds for members use this to decide the size of a person. This could have other uses too. Also activities for member are collected for month so that other similar information can be retrieved if needed. Activity scores for groups and tagcloud sizing by it is also done, but needs decisions on what to count as an activity of group. See your member view page after creating stuff.

Line 
1# Copyright 2006 by the LeMill Team (see AUTHORS)
2#
3# This file is part of LeMill.
4#
5# LeMill is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# LeMill is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with LeMill; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19from SharedMetadata import age_group, description, tags
20from Products.Archetypes.public import *
21from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import ReferenceBrowserWidget
22from Products.CMFCore.permissions import ModifyPortalContent
23from Products.Archetypes.public import BaseSchema, BaseContent, registerType
24from Products.Archetypes.atapi import DisplayList
25from Globals import InitializeClass
26from Products.CMFCore.utils import getToolByName
27from AccessControl import ClassSecurityInfo, Unauthorized
28from config import PROJECTNAME, MODIFY_CONTENT, VIEW
29from SharedMetadata import *
30from Products.Archetypes.atapi import DisplayList
31
32
33# Same thing as with MemberFolder but easier: MemberBlogs contain the values of groups itself in indexable storage.
34
35schema = BaseSchema + bodytext + tags + coverImage + Schema((
36    StringField('category',
37        vocabulary='getCategories',
38        index = 'FieldIndex:schema',
39        enforceVocabulary=True,
40        default='blog post',
41        widget=SelectionWidget(
42             label = 'Category',
43             label_msgid = 'label_post_category',
44             description = "Choose category for post. Collaboration proposals are invitations that  are visible for anyone in Community page.",
45             description_msgid = 'help_post_category',
46             i18n_domain = "lemill"
47             ),
48    ),           
49
50    TagsField('tags',
51        schemata='default'
52        ),
53))
54
55#    StringField('description',
56#        default_method=None,
57#        widget=TextAreaWidget(
58#           visible={'view':'invisible','edit':'invisible'}       
59#        )
60#    ),
61#
62
63
64
65class BlogPost(BaseContent):
66
67    meta_type = "BlogPost"
68    archetype_name = "BlogPost" 
69    allow_discussion = True
70    _at_rename_after_creation = True
71
72    security = ClassSecurityInfo()
73    security.declareObjectPublic()
74    schema = schema
75
76    def manage_afterAdd(self, item, container):
77        """1) Replaces the left side portlets with the content type's own action portlet. 2) add obj id to list of recent entries in parent GroupBlog. 3) add to list of collaboration proposals if such"""
78        BaseContent.manage_afterAdd(self, item, container)
79        self.content_status_modify(workflow_action='publish')
80        if not hasattr(item.aq_base, 'left_slots'):
81            self._setProperty('left_slots', ['here/portlet_%s_actions/macros/portlet' % item.meta_type.lower(),], 'lines')
82        if hasattr(container, 'recent_posts'):
83            container.addRecent_post(self.getId())
84        cat=self.getCategory()
85        uid=self.UID()
86        my_id=self.getId()
87        try:
88            proposals = self.community.getCollaboration_proposals()
89        except:
90            proposals = [uid]
91        if cat.lower()=='collaboration proposal' and uid not in proposals and not my_id.startswith('blogpost.'):
92            self.community.addCollaboration_proposal(uid)
93        mtool = getToolByName(self, 'portal_membership')
94        memberfolder=mtool.getHomeFolder()
95        if memberfolder!=None:
96            memberfolder.note_action(item.UID(), item.portal_type, 'afterAdd')
97
98
99
100    def at_post_edit_script(self):
101        """ Rename id to resemble title, add to list of collaboration proposals of community if such, and add to recent posts of blog. """
102        old=self.getId()
103        cat=self.getCategory()
104        uid=self.UID()
105        self._renameAfterCreation()
106        new=self.getId()
107
108        try:
109            proposals = self.community.getCollaboration_proposals()
110        except:
111            proposals = [uid]
112        if cat.lower()=='collaboration proposal' and uid not in proposals and not new.startswith('blogpost.'):
113            self.community.addCollaboration_proposal(uid)
114        if old != new: # new id is updated to recent posts list
115            try: # if for some reason posts are not inside blogs
116                blog=self.getBlog()
117                blog.replaceRecent_post(old, new)
118            except:
119                pass
120        mtool = getToolByName(self, 'portal_membership')
121        memberfolder=mtool.getHomeFolder()
122        if memberfolder!=None:
123            memberfolder.note_action(self.UID(), self.portal_type, 'post_edit')
124
125               
126
127    def getCategories(self):
128        blog=self.getBlog()
129        return blog.getCategories()
130               
131
132    def getCoverImageURL(self):
133        """BlogPosts shouldn't have their own cover images -- returns authors portrait."""
134        mtool   = getToolByName(self, 'portal_membership')
135        portrait = mtool.getPersonalPortrait(self.Creator)
136        return portrait.absolute_url()
137       
138    def NiceName(self):
139        """ I don't think this will get called but just to make sure. """
140        return self.getTitle()
141
142    def hide_post(self):
143        """ Hide, remove from recent posts and remove from Collaboration proposals """
144        container=self.getBlog()
145        uid=self.UID()
146        self.content_status_modify(workflow_action='hide')
147        if hasattr(container, 'recent_posts'):
148            container.removeRecent_post(self.getId())
149        try:
150            proposals = self.community.getCollaboration_proposals()
151        except:
152            proposals = [uid]
153        if self.getCategory().lower()=='collaboration proposal' and uid not in proposals:
154            self.community.addCollaboration_proposal(uid)
155
156
157
158   
159#    def setProperties(self, newprops=None, **kw):
160#        """ just a helper method """
161#        if newprops is None:
162#            newprops = kw
163#        for (key, value) in newprops.items():
164#            accessor='get'+str(key.capitalize())
165#            mutator='set'+str(key.capitalize())
166#
167#            if hasattr(self, accessor):
168#                if eval('self.'+accessor+'()') != value:
169#                    eval('self.'+mutator+'(value)')
170
171    def setCoverImage(self, value, **kwargs):
172        """ This modification for a mutator flags object to have a coverImage """
173        cover=self.getField('coverImage')
174        cover.set(self,value,**kwargs)
175        has_cover=self.getField('hasCoverImage')
176        has_cover.set(self,True)
177
178    def setBodyText(self, value, **kwargs):
179        bt=self.getField('bodyText')
180        bt.set(self,value,**kwargs)
181        desc=self.getField('description')
182        if len(value)>200:
183            desc.set(self, '--More--'.join((value[:500],'')), **kwargs)
184        else:
185            desc.set(self, value, **kwargs)
186   
187
188
189
190
191registerType(BlogPost, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.