# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import TextField from Products.Archetypes.public import RichWidget from Products.Archetypes.public import BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME from BaseTask import BaseTask from Permissions import * schema = BaseTask.schema + 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 = RichWidget( label="Task", description="", label_msgid='label_task', description_msgid='description_task', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio", rows = 25)), )) schema.moveField('attachedFile', pos='bottom') schema.moveField('refsForAnswers', after='body') class ReflectionTask(BaseTask): """ Reflection task """ meta_type = "ReflectionTask" archetype_name = "ReflectionTask" global_allow = 0 security = ClassSecurityInfo() security.declareObjectPublic() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/task_preview', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Edit Task',), }, { 'id':'report', 'name':'Report', 'action':'string:${object_url}/report_view', 'permissions': ('Mark Task',), }, { 'id':'metadata', 'visible':False, }, ) def __init__(self, id): self.id = id def allowRestricted(self): return True def allowAccepted(self): return False security.declareProtected('View', 'startAnswering') def startAnswering(self, REQUEST): """ Saves Answer """ user = str(REQUEST.AUTHENTICATED_USER) homefolder = self.portal_membership.getHomeFolder(user) blog_ob = getattr(homefolder, 'blog') #typestool = getToolByName(self, 'portal_types') #puf_type = getattr(typestool, 'ReflectionAnswer', None) #if not puf_type: # return 0 #puf_type.global_allow = 1 #red_id = self.id #if not hasattr(blog, self.id): # id = blog.invokeFactory("ReflectionAnswer", id=self.id, title=self.title) # new_bt = getattr(blog, id) # new_bt.setRefToTask(self.UID()) # red_id = id #puf_type.global_allow = 0 new_id = self.id new_title = self.title #XXX: test me if not self.hasAnswer(user): from AnswerTask import ReflectionAnswer blog = ReflectionAnswer(new_id) blog_ob._setObject(blog.id, blog) ob=getattr(blog_ob,blog.id) ob.setTitle(new_title) ob.setRefToTask(self.UID()) ob.content_status_modify(workflow_action='restrict') ob.manage_permission(View, ('Manager','Owner','Viewer','Lecturer','Student'), 0) ob.setPermissionsHere(self.getLecturer()+(self.Creator(),),'Lecturer') ob.reindexObject() homefolder.competency.setReferencesForAnswers(ob.UID(), self.getrefsForAnswers()) return REQUEST.RESPONSE.redirect(blog_ob.absolute_url()+'/'+new_id+'/edit') registerType(ReflectionTask, PROJECT_NAME)