# -*- coding: utf-8 # Copyright 2005 by Vahur Rebas from Products.Archetypes.public import BaseFolderSchema, Schema from Products.Archetypes.public import BaseFolder from Products.Archetypes.public import registerType from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo from config import PROJECT_NAME schema = BaseFolderSchema class ProgressFolder(BaseFolder): """ This folder holds all progress interviews. """ meta_type = "ProgressFolder" archetype_name = "ProgressFolder" allowed_content_types = [] filter_content_types = 1 global_allow = 1 security = ClassSecurityInfo() schema = schema actions = ( { 'id': 'view', 'name': 'View', 'action': 'string:${object_url}/prog_folder_view', 'permissions': ('View',), }, ) def getClasses(self): """ returs a list of classes(groups) """ klassid = [] massiiv = self.prefs_user_group_search('','groups') for klassist in massiiv: if klassist.klass: klassid.append(klassist) return klassid def getURLtoClass(self, klass): """ in PIF we render links to classes. this method returns proper object, or creates one """ if hasattr(self.aq_self, klass.id): return getattr(self.aq_self, klass.id) else: # create object typestool = getToolByName(self, 'portal_types') puf_type = getattr(typestool, 'ProgressFolder', None) if not puf_type: return 0 puf_type.allowed_content_types = ("ProgressClassFolder") id = self.invokeFactory('ProgressClassFolder', klass.id, title=klass.title) puf_type.allowed_content_types = [] created_object = getattr(self.aq_self, klass.id) for luuser in self.prefs_user_group_search('','users'): map = self.time_tool.getTeacherMap(str(luuser)) try: juhatatav = 'group_'+str(map['direct']) if juhatatav == klass.id: created_object.manage_setLocalRoles(str(luuser),('Manager',)) break except KeyError: pass return created_object def getUserInClass(self, user): for klass in self.getClasses(): for member in klass.getGroupMembers(): if str(member) == str(user): return klass registerType(ProgressFolder, PROJECT_NAME)