# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import FileField from Products.Archetypes.public import FileWidget from Products.Archetypes.public import TextField from Products.Archetypes.public import TextAreaWidget from Products.Archetypes.public import RichWidget from Products.Archetypes.public import OrderedBaseFolder, BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME, TASK_TYPES, BLOG_TYPES from Common import CommonMix schema = BaseSchema TopicSchema = BaseSchema.copy() + Schema(( TextField('body', accessor='getBody', isMetadata=0, required=True, searchable=True, primary=True, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = TextAreaWidget( label="Your Post", description="", label_msgid='label_post', description_msgid='description_post', i18n_domain="eportfolio", rows = 10)), )) class TopicAnswer(BaseContent, CommonMix): """Forumtopic""" meta_type = "TopicAnswer" archetype_name = "Topic Answer" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema + Schema(( TextField('topicanswer', accessor='getTopicanswer', isMetadata=0, required=True, searchable=True, primary=True, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label="Reply", description="", label_msgid='label_reply', description_msgid='description_reply', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio", ), ), )) actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'visible':False, }, { 'id':'metadata', 'visible':False, }, ) registerType(TopicAnswer, PROJECT_NAME) class ForumTopicFolder(OrderedBaseFolder, CommonMix): """ForumTopicFolder""" meta_type = "ForumTopicFolder" archetype_name = "NewTopic" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = ('TopicAnswer',) security = ClassSecurityInfo() schema = TopicSchema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/topic_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'visible':False, }, { 'id':'metadata', 'visible':False, }, ) def getTopicAnswers(self): """ """ return self.objectValues('TopicAnswer') def getMostRecentAnswer(self): """ """ answers = self.getTopicAnswers() answers.reverse() an = '' if answers != []: an = answers[0] return an def addTopicReply(self, topic_reply): """add reply""" if topic_reply == '': return self.REQUEST.RESPONSE.redirect('topic_view') import time newId = 'reply-'+str(time.time()).replace('.','') title = 'reply-'+str(time.time()).replace('.','') nid = self.invokeFactory("TopicAnswer", id=newId, title=title) obj = getattr(self, nid) obj.topicanswer = topic_reply return self.REQUEST.RESPONSE.redirect('topic_view') def delTopicReply(self,reply_id): """del topic reply""" if hasattr(self,reply_id): self._delObject(reply_id) return self.REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()) registerType(ForumTopicFolder, PROJECT_NAME) class GroupForumFolder(OrderedBaseFolder, CommonMix): """GroupForumFolder""" meta_type = "GroupForumFolder" archetype_name = "Group Forum Folder" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = ('ForumTopicFolder',) security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/forum_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Access Denied',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Access Denied',), }, ) # def getTopics(self): # """ """ # return self.objectValues('ForumTopicFolder') def getTopics(self): """OrderByLastPost""" topics = self.objectValues('ForumTopicFolder') count = 0 ordered = [] times = [] for i in topics: if i.Title() != '': answers = i.getTopicAnswers() answers.reverse() an = '' if answers != []: an = answers[0] an = answers[0].ModificationDate() else: an = i.ModificationDate() num = 0 while num < count: x = times[num] z = ordered[num] if an > x: times[num] = an ordered[num] = i an = x i = z num = num + 1 times.append(an) ordered.append(i) count += 1 return ordered def getRecentTopics(self): en = [] entries = self.getTopics() showCount = 0 for x in entries: en.append(x) if showCount >= 2: break showCount = showCount + 1 return en def delForumTopic(self,topic_id): """del forum topic""" if hasattr(self,topic_id): self._delObject(topic_id) return self.REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()) def addForumTopic(self, topic_title, topic_content): """add reply""" print 'add' # if hasattr(self, note_id): # nid = note_id # else: import time newId = 'topic-'+str(time.time()).replace('.','') nid = self.invokeFactory("ForumTopicFolder", id=newId, title=topic_title) #res = ["new",newId,title,topic_reply] obj = getattr(self, nid) obj.body = topic_content return self.REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()) registerType(GroupForumFolder, PROJECT_NAME)