""" Container for Groups """ __version__ = "$Revision$"[11:-2] import Globals from Globals import Acquisition, Persistent from Acquisition import aq_base, aq_inner, aq_parent, Explicit from AccessControl import ClassSecurityInfo from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from zope.interface import implements from common import commons from Permissions import * from interfaces import IGroups class Groups(BTreeFolder2, Persistent, Explicit, commons): """ container class for groups """ meta_type = 'Groups' security = ClassSecurityInfo() security.declareObjectPublic() implements(IGroups) manage_options = BTreeFolder2.manage_options id = 'groups' def __init__(self): BTreeFolder2.__init__(self, self.id) def index_html(self, REQUEST): """ index -> groups_index()""" return self.groups_index() def setupGroup(self, REQUEST): """ """ from GroupObject import Group group_id = self.random_generator('group_') g = Group(str(group_id)) self._setObject(group_id, g) obj = getattr(self, group_id) obj.changeGroupInfo(REQUEST) def _getAllGroups(self): return self.objectValues('Group') def getUserGroups(self, user): g_results = self.cat_groups(getUser=str(user), sort_on='getTitle', sort_order='ascending') return g_results def deleteGroups(self, REQUEST, remove=''): """ """ if remove: if isinstance(remove, type('')): remove = [remove,] for group in remove: self._delObject(group) return REQUEST.RESPONSE.redirect('groups_index.html') def getGroupStats(self, group_id, test_id): """ """ group = self.getGroupById(group_id) test = self.getTestById(test_id) grouptests = group.getTests() if not test_id in grouptests: return '-' points = [] test_points = test.getTestMaxPoints() gmembers = group.getMembers() for member_id in gmembers: member = self.getStudentById(member_id) container = self.getContainerByTestId(member['ans_containers'], test_id, group_id) if container != None: sessions = container.getSessions() done = container.checkDoneOrNot() if done == True: user_points = test.getUserTestPoints(sessions) #percent = (user_points/test_points)*100 points.append(user_points) sum = 0 for point in points: sum += point count = len(points) if count == 0: return '-' if test_points == 0: return "" all = (sum/(test_points*count))*100 return self.roundNumber(all)+'%' def getGroupsStatsFile(self, REQUEST): """ comaseparated file """ user = REQUEST.get('AUTHENTICATED_USER') groups = self.getGroups(user) tests = self.tests.getTests(user) text = ';' for test in tests: text += test.getTitle + ';' for group in groups: text += '\n'+str(group.getTitle())+';' group_id = group.getId() for test in tests: test_id = test.getId text += self.getGroupStats(group_id, test_id) + ';' self.REQUEST.RESPONSE.setHeader('content-type', 'text/txt') self.REQUEST.RESPONSE.setHeader('Content-disposition','attachment; filename=groups_statistics.txt') return text Globals.InitializeClass(Groups) #EOF