# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField, DateTimeField, TextField from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget, CalendarWidget, RichWidget from Products.Archetypes.public import OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from Common import CommonMix as Common from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME, TASK_TYPES from Permissions import * schema = BaseSchema + Schema(( )) class TaskManager(OrderedBaseFolder, Common): """ Task Manager product """ meta_type = "TaskManager" archetype_name = "TaskManager" global_allow = 0 filter_content_types = True allowed_content_types = TASK_TYPES + ['StructuredTemplate',] security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/taskmanager_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Manage portal content',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Manage Portal',), }, ) def __init__(self, id): self.id = id self.largeIcon = "taskmanager.gif" def getLargeIcon(self): """ returns large icon name """ return self.largeIcon def getOutgoing(self): """ returns a list of outgoing assignments """ return self.objectValues(TASK_TYPES) def getIncoming(self): """ returns a list of incoming assignments """ user = str(self.REQUEST.AUTHENTICATED_USER) if user == 'Anonymous User': return [] groups = self.REQUEST.AUTHENTICATED_USER.getGroups() groups.append(user) pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':TASK_TYPES, 'getTarget':groups},sort_on='getDeadline', sort_order='descending') #descending return [ x.getObject() for x in res ] def getTemplates(self): """ returns { 'own': ['brain1', 'brain2'], 'other': ['brain1', 'brain2'] } """ pc = getToolByName(self, 'portal_catalog') user = str(self.REQUEST.AUTHENTICATED_USER) res = pc({'portal_type': 'StructuredTemplate', 'review_state': 'public'}) res2 = pc({'portal_type': 'StructuredTemplate', 'Creator': user, 'review_state': 'private'}) own = [ x for x in res2 ] other = [] for x in res: if x.Creator == user: own.append(x) else: other.append(x) return { 'own': own, 'other': other } def getTasks(self): """ get tasks to lecturer""" user = str(self.REQUEST.AUTHENTICATED_USER) pc = getToolByName(self, 'portal_catalog') res = pc({'portal_type':TASK_TYPES, 'getLecturer':user},sort_on='getDeadline', sort_order='descending') return [ x.getObject() for x in res ] def struct_use_template(self, REQUEST, uid): """ structured task using template """ rc = getToolByName(self, 'uid_catalog') obj = rc(UID=uid) if len(obj) == 0: raise 'Error, object not found' templ = obj[0].getObject() print "Template using:", templ nr = 1 mid = "structured-templ-task-"+templ.getId()+"-"+str(nr) while hasattr(self, "structured-templ-task-"+templ.getId()+"-"+str(nr)): nr += 1 mid = "structured-templ-task-"+templ.getId()+"-"+str(nr) id = self.invokeFactory('StructuredTask', id = mid) obj = getattr(self, id) obj.setTitle(templ.Title()) obj.setHelp(templ.getHelp()) obj.setDatafields(templ.getDatafields()) print "Data fields 1", templ.getDatafields() print "Data fields 2", obj.getDatafields() print "App fields 1", templ.getFields() obj.appFields = templ.getFields() return REQUEST.RESPONSE.redirect(obj.absolute_url()+'/edit') registerType(TaskManager, PROJECT_NAME)