# -*- coding: utf-8 # Copyright 2005 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget from Products.Archetypes.public import BaseContent, OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME schema = BaseSchema class ToDo(BaseContent): """ ToDo """ meta_type = "ToDo" archetype_name = "ToDo" global_allow = 0 filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema + Schema(( LinesField('Target', required=1, accessor="getTarget", isMetadata=1, searchable=1, vocabulary='getTargets', widget=SelectionWidget( format="select", label="Target", label_msgid='label_target', description="Target whos get that task.", description_msgid='desc_target', visible={'view':'invisible','edit':'visible'}, i18n_domain="krihvel"), ), StringField('task', widget=TextAreaWidget( label="Task", description="", label_msgid='label_task', description_msgid='description_task', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio"), ), )) actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/task_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage Portal',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Manage Portal',), }, ) def getTargets(self): """ Targets array """ targets = [] groups = self.prefs_user_group_search('','groups') for target in groups: target = str(target) if target not in ['Administrators', 'Reviewers']: targets.append(target) return targets def getAnswerText(self, student): """ gets students answer if possible""" homeFolder = self.portal_membership.getHomeFolder(student) if hasattr(homeFolder, 'tasks'): taskFolder = getattr(homeFolder, 'tasks') answer_id = self.id+"-answer" if hasattr(taskFolder, answer_id): answerObj = getattr(taskFolder, answer_id) return answerObj.answer else: return "" else: return "" def getAccepted(self, student): """ gets students answer if possible""" homeFolder = self.portal_membership.getHomeFolder(student) if hasattr(homeFolder, 'tasks'): taskFolder = getattr(homeFolder, 'tasks') answer_id = self.id+"-answer" if hasattr(taskFolder, answer_id): answerObj = getattr(taskFolder, answer_id) if answerObj.accepted!='none': return True else: return False else: return False else: return False def answerTask(self, REQUEST): """ Copies already made form to users forms folder """ user = str(REQUEST.AUTHENTICATED_USER) homeFolder = self.portal_membership.getHomeFolder(user) taskFolder = getattr(homeFolder, 'tasks') answer_id = str(self.id)+"-answer" if hasattr(taskFolder, answer_id): answerObj = getattr(taskFolder,answer_id) answerObj.answer = REQUEST.get('answer') else: #make new answer from Task import Answer new_answer = Answer(answer_id) taskFolder._setObject(new_answer.id, new_answer) answerObj=getattr(taskFolder, new_answer.id) answerObj.setTitle(self.title) answerObj.answer = REQUEST.get('answer') answerObj.task = self.task answerObj.parent_task = self.id answerObj.reindexObject() self._p_changed = 1 return answerObj def allowAccept(self, user): """ is accepting allowed no, not here """ return False registerType(ToDo, PROJECT_NAME) class Answer(BaseContent): """ Answer """ meta_type = "Answer" archetype_name = "Answer" global_allow = 0 filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema + Schema(( StringField('task', widget=TextAreaWidget( label="Task", description="", label_msgid='label_task', description_msgid='description_task', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio"), ), StringField('answer', widget=TextAreaWidget( label="Answer", description="", label_msgid='label_answer', description_msgid='description_answer', visible={'view':'visible','edit':'visible'}, i18n_domain="eportfolio"), ), )) actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/task_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage Portal',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Manage Portal',), }, ) def saveTask(self, REQUEST): """ Saves data """ self.answer = REQUEST.get('answer') return 1 def getAnswerText(self, student): """ gets answer """ return self.answer def getAccepted(self, student): """ gets answer """ if self.accepted!='none': return True else: return False def acceptAnswer(self): """ Accept this answer """ self.accepted = "True" self._p_changed = 1 return 1 def allowAccept(self, user): """ is accepting allowed """ if user in ['metz'] and self.accepted=='none': return True return False def __init__(self, id): self.id = id self.parent_task = "none" self.accepted = "none" registerType(Answer, PROJECT_NAME) class TaskFolder(OrderedBaseFolder): """ TaskFolder """ meta_type = "TaskFolder" archetype_name = "TaskFolder" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = ('ToDo',) security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage Portal',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Manage Portal',), }, ) def __init__(self, id): self.id = id self.largeIcon = "presentation.gif" def getLargeIcon(self): """ returns subfolders large icon """ return self.largeIcon registerType(TaskFolder, PROJECT_NAME)