#-*- mode: python; mode: fold -*- from Globals import InitializeClass from AccessControl import ClassSecurityInfo from AccessControl.SecurityManagement import newSecurityManager from Products.CMFCore.utils import UniqueObject, getToolByName from Products.CMFCore.permissions import View from Products.CMFCore.permissions import ModifyPortalContent from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument from Products.CPSDocument.CPSDocument import CPSDocument from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser class StudentsFolder(BaseBTreeFolder): ###( """ WAeUP container for the various WAeUP containers data """ meta_type = 'Students Folder' portal_type = meta_type security = ClassSecurityInfo() InitializeClass(StudentsFolder) def addStudentsFolder(container, id, REQUEST=None, **kw): """Add a Student.""" ob = StudentsFolder(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) student_fti = { ###( 'title': 'WAeUP Student', 'description': '', 'content_icon': 'student.gif', 'content_meta_type': 'Student', 'factory': 'addStudent', 'immediate_view': 'cpsdocument_view', 'global_allow': True, 'filter_content_types': True, 'allowed_content_types': ('Jamb','StudentPersonal'), 'allow_discussion': False, } ###) class Student(CPSDocument): ###( """ WAeUP Student container for the various student data """ meta_type = 'Student' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") def Title(self): """compose title""" reg_nr = self.getId()[1:] data = getattr(self,'PERSONAL',None) if data is None: data = getattr(self,'JAMB',None) if data: content = data.getContent() return "%s %s" % (content.firstname,content.lastname) return self.title def Description(self): """compose description""" data = getattr(self,'JAMB',None) if data: content = data.getContent() return "%s %s is studying %s" % (content.firstname,content.lastname,content.course) return self.description security.declareProtected(View,"setScratchCardData") def setScratchCardData(self,ident,ds): """set this data """ dict = {'%s_sc_pin' % ident : ds.get('sc_pin'), '%s_sc_id' % ident : ds.get('sc_id'), '%s_sc_value' % ident : ds.get('sc_value'), '%s_date' % ident : ds.get('sc_date'), } if self.portal_membership.isAnonymousUser(): tmp_user = CPSUnrestrictedUser('s%(jamb_id)s' % ds, '', ['StudentManager'], '') tmp_user = tmp_user.__of__(self.acl_users) newSecurityManager(None, tmp_user) #print str(dict) self.edit(mapping=dict) security.declareProtected(View,"memberIsOwner") def memberIsOwner(self): """is the current user the owner""" member = self.portal_membership.getAuthenticatedMember() #print member, self.getId(),self.aq_parent.getId() if self.aq_parent.getId() == str(member): return True return False security.declareProtected(View,"accommodationIsBooked") def accommodationIsBooked(self): """is the accommodation booked""" if self.accommodation_sc_pin != '': return True return False security.declareProtected(View,"accommodationIsPayed") def accommodationIsPayed(self): """is the accommodation payed""" if self.accommodation_sc_pin != '': return True return False security.declareProtected(View,"isRegisteredForCurrentLevel") def isRegisteredForCurrentLevel(self): """is the student registered for the current level""" for l in self.aq_parent.objectValues(): if l.portal_type == 'StudyLevel': return True return False InitializeClass(Student) def addStudent(container, id, REQUEST=None, **kw): """Add a Student.""" ob = Student(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) studentpersonal_fti = { ###( 'title': 'WAeUP StudentPersonal', 'description': '', 'content_icon': 'student.gif', 'content_meta_type': 'StudentPersonal', 'factory': 'addStudent', 'immediate_view': 'student_personal_index_html', 'global_allow': True, 'filter_content_types': True, 'allowed_content_types': (), 'allow_discussion': False, } ###) class StudentPersonal(CPSDocument): ###( """ WAeUP Student container for the various student data """ meta_type = 'StudentPersonal' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") def Title(self): """compose title""" content = self.getContent() return "Personal Data for %s %s" % (content.firstname,content.lastname) InitializeClass(StudentPersonal) def addStudentPersonal(container, id, REQUEST=None, **kw): """Add a Students personal data.""" ob = StudentPersonal(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) studentdocuments_fti = { ###( 'title': 'WAeUP StudentDocuments', 'description': '', 'content_icon': 'student.gif', 'content_meta_type': 'StudentDocuments', 'factory': 'addStudent', 'immediate_view': 'temporary_view_all', 'global_allow': True, 'filter_content_types': True, 'allowed_content_types': (), 'allow_discussion': False, } ###) class StudentDocuments(CPSDocument): ###( """ WAeUP Student container for the various student data """ meta_type = 'StudentDocuments' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") def Title(self): """compose title""" content = self.getContent() return "Scanned Documents" InitializeClass(StudentDocuments) def addStudentDocuments(container, id, REQUEST=None, **kw): """Add a Students documents""" ob = StudentDocuments(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) jamb_fti = { ###( 'title': 'WAeUP Jamb', 'description': '', 'content_icon': '', 'content_meta_type': 'Jamb', 'factory': 'addJamb', 'immediate_view': 'cpsdocument_view', 'global_allow': True, 'filter_content_types': True, 'allowed_content_types': ('Course',), 'allow_discussion': False, } ###) class Jamb(CPSDocument): ###( """ WAeUP Jamb containing the courses and students """ meta_type = 'Jamb' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") def Title(self): """compose title""" content = self.getContent() return "JAMB Data for %s %s" % (content.firstname,content.lastname) security.declareProtected(View,"setOwnership") def setOwnership(self,member_id): """set ownership""" pm = getattr(self,'portal_membership') member = pm.getMemberById(member_id) self.changeOwnership(member) InitializeClass(Jamb) def addJamb(container, id, REQUEST=None, **kw): """Add a Jamb.""" ob = Jamb(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) study_level_fti = { ###( 'title': 'WAeUP StudyLevel', 'description': '', 'content_icon': '', 'content_meta_type': 'StudyLevel', 'factory': 'addStudyLevel', 'immediate_view': 'cpsdocument_view', 'global_allow': True, 'filter_content_types': True, 'allowed_content_types': ('Course',), 'allow_discussion': False, } ###) class StudyLevel(CPSDocument): ###( """ WAeUP StudyLevel containing the courses and students """ meta_type = 'StudyLevel' portal_type = meta_type security = ClassSecurityInfo() InitializeClass(StudyLevel) def addStudyLevel(container, id, REQUEST=None, **kw): """Add a StudyLevel.""" ob = StudyLevel(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) semester_fti = { ###( 'title': 'WAeUP Semester', 'description': '', 'content_icon': '', 'content_meta_type': 'Semester', 'factory': 'addSemester', 'immediate_view': 'cpsdocument_view', 'global_allow': True, 'filter_content_types': True, 'allowed_content_types': ('Course',), 'allow_discussion': False, } ###) class Semester(CPSDocument): ###( """ WAeUP Semester containing the courses and students """ meta_type = 'Semester' portal_type = meta_type security = ClassSecurityInfo() InitializeClass(Semester) def addSemester(container, id, REQUEST=None, **kw): """Add a Semester.""" ob = Semester(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###)