# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from Products.Archetypes.public import BaseContent, registerType from Permissions import * from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME class BaseFunctions(BaseContent): """ BaseFunctions """ def getClasses(self): """ Classes massive """ classes = [] member = self.REQUEST.AUTHENTICATED_USER groupstool = getToolByName(self, 'portal_groups') groups = groupstool.listGroupIds() roles = member.getRolesInContext(self) for target in groups: target2 = groupstool.getGroupById(target) if 'Manager' in roles: target = str(target) if target not in ['Administrators', 'Reviewers']: classes.append(target) else: for md in target2.getGroupMembers(): if md.id == str(member): classes.append(str(target)) return classes def getStudents(self, groupId): """ Students massive """ students = [] member = self.REQUEST.AUTHENTICATED_USER groupstool = getToolByName(self, 'portal_groups') group = groupstool.getGroupById(str(groupId)) for md in group.getGroupMembers(): if 'Teacher' not in md.getRolesInContext(self) and self.portal_membership.getHomeFolder(md.id)!=None: students.append(md) return students def getFullName(self, username): """ gets members fullname """ if username == None: return '' return self.portal_membership.getMemberById(username).getProperty('fullname') def canSeeData(self): """ member can see data """ member = self.REQUEST.AUTHENTICATED_USER for role in ['Teacher','Manager']: if role in member.getRolesInContext(self): return True return False def isOwner(self, member): """ is owner? """ homefolder = self.portal_membership.getHomeFolder(member) if hasattr(homefolder, str(self.Target[0])): object = getattr(homefolder, str(self.Target[0])) if str(object.Creator())==str(member): return True return False def getRemoteUrl(self): return self.absolute_url()