| 1 | #-*- mode: python; mode: fold -*- |
|---|
| 2 | # $Id: Students.py 200 2006-05-10 06:58:10Z joachim $ |
|---|
| 3 | from Globals import InitializeClass |
|---|
| 4 | from AccessControl import ClassSecurityInfo |
|---|
| 5 | from AccessControl.SecurityManagement import newSecurityManager |
|---|
| 6 | |
|---|
| 7 | from Products.CMFCore.utils import UniqueObject, getToolByName |
|---|
| 8 | from Products.CMFCore.permissions import View |
|---|
| 9 | from Products.CMFCore.permissions import ModifyPortalContent |
|---|
| 10 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
|---|
| 11 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
|---|
| 12 | from Products.CPSDocument.CPSDocument import CPSDocument |
|---|
| 13 | from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
|---|
| 14 | from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser |
|---|
| 15 | ##class StudentsFolder(BaseBTreeFolder): ###( |
|---|
| 16 | ## """ |
|---|
| 17 | ## WAeUP container for the various WAeUP containers data |
|---|
| 18 | ## """ |
|---|
| 19 | ## meta_type = 'Students Folder' |
|---|
| 20 | ## portal_type = meta_type |
|---|
| 21 | ## security = ClassSecurityInfo() |
|---|
| 22 | ## |
|---|
| 23 | ## |
|---|
| 24 | ##InitializeClass(StudentsFolder) |
|---|
| 25 | |
|---|
| 26 | ##def addStudentsFolder(container, id, REQUEST=None, **kw): |
|---|
| 27 | ## """Add a Student.""" |
|---|
| 28 | ## ob = StudentsFolder(id, **kw) |
|---|
| 29 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 30 | #####) |
|---|
| 31 | |
|---|
| 32 | class Student(CPSDocument): ###( |
|---|
| 33 | """ |
|---|
| 34 | WAeUP Student container for the various student data |
|---|
| 35 | """ |
|---|
| 36 | meta_type = 'Student' |
|---|
| 37 | portal_type = meta_type |
|---|
| 38 | security = ClassSecurityInfo() |
|---|
| 39 | |
|---|
| 40 | security.declareProtected(View,"Title") |
|---|
| 41 | def Title(self): |
|---|
| 42 | """compose title""" |
|---|
| 43 | reg_nr = self.getId()[1:] |
|---|
| 44 | data = getattr(self,'PERSONAL',None) |
|---|
| 45 | if data is None: |
|---|
| 46 | data = getattr(self,'JAMB',None) |
|---|
| 47 | if data: |
|---|
| 48 | content = data.getContent() |
|---|
| 49 | return "%s %s" % (content.firstname,content.lastname) |
|---|
| 50 | return self.title |
|---|
| 51 | |
|---|
| 52 | def Description(self): |
|---|
| 53 | """compose description""" |
|---|
| 54 | data = getattr(self,'PERSONAL',None) |
|---|
| 55 | if data is None: |
|---|
| 56 | return "none" |
|---|
| 57 | if data: |
|---|
| 58 | content = data.getContent() |
|---|
| 59 | return "%s" % (content.description) |
|---|
| 60 | return self.description |
|---|
| 61 | |
|---|
| 62 | security.declareProtected(View,"setScratchCardData") |
|---|
| 63 | def setScratchCardData(self,ident,ds): |
|---|
| 64 | """set this data """ |
|---|
| 65 | dict = {'%s_sc_pin' % ident : ds.get('sc_pin'), |
|---|
| 66 | '%s_sc_id' % ident : ds.get('sc_id'), |
|---|
| 67 | '%s_sc_value' % ident : ds.get('sc_value'), |
|---|
| 68 | '%s_date' % ident : ds.get('sc_date'), |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | old_user = self.portal_membership.getAuthenticatedMember() |
|---|
| 72 | if self.portal_membership.isAnonymousUser(): |
|---|
| 73 | tmp_user = CPSUnrestrictedUser('s%(jamb_id)s' % ds, '', |
|---|
| 74 | ['StudentManager'], '') |
|---|
| 75 | tmp_user = tmp_user.__of__(self.acl_users) |
|---|
| 76 | newSecurityManager(None, tmp_user) |
|---|
| 77 | #print str(dict) |
|---|
| 78 | self.edit(mapping=dict) |
|---|
| 79 | newSecurityManager(None, old_user) |
|---|
| 80 | |
|---|
| 81 | security.declareProtected(View,"memberIsOwner") |
|---|
| 82 | def memberIsOwner(self): |
|---|
| 83 | """is the current user the owner""" |
|---|
| 84 | member = self.portal_membership.getAuthenticatedMember() |
|---|
| 85 | #print member, self.getId(),self.aq_parent.getId() |
|---|
| 86 | if self.aq_parent.getId() == str(member): |
|---|
| 87 | return True |
|---|
| 88 | return False |
|---|
| 89 | |
|---|
| 90 | security.declareProtected(View,"accommodationIsBooked") |
|---|
| 91 | def accommodationIsBooked(self): |
|---|
| 92 | """is the accommodation booked""" |
|---|
| 93 | if self.accommodation_sc_pin != '': |
|---|
| 94 | return True |
|---|
| 95 | return False |
|---|
| 96 | |
|---|
| 97 | security.declareProtected(View,"accommodationIsPayed") |
|---|
| 98 | def accommodationIsPayed(self): |
|---|
| 99 | """is the accommodation payed""" |
|---|
| 100 | if self.hostel_fee_sc_pin != '': |
|---|
| 101 | return True |
|---|
| 102 | return False |
|---|
| 103 | |
|---|
| 104 | security.declareProtected(View,"isRegisteredForCurrentLevel") |
|---|
| 105 | def isRegisteredForCurrentLevel(self): |
|---|
| 106 | """is the student registered for the current level""" |
|---|
| 107 | for l in self.aq_parent.objectValues(): |
|---|
| 108 | if l.portal_type == 'StudyLevel': |
|---|
| 109 | return True |
|---|
| 110 | return False |
|---|
| 111 | |
|---|
| 112 | InitializeClass(Student) |
|---|
| 113 | |
|---|
| 114 | def addStudent(container, id, REQUEST=None, **kw): |
|---|
| 115 | """Add a Student.""" |
|---|
| 116 | ob = Student(id, **kw) |
|---|
| 117 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 118 | |
|---|
| 119 | ###) |
|---|
| 120 | |
|---|
| 121 | class StudentPersonal(CPSDocument): ###( |
|---|
| 122 | """ |
|---|
| 123 | WAeUP Student container for the various student data |
|---|
| 124 | """ |
|---|
| 125 | meta_type = 'StudentPersonal' |
|---|
| 126 | portal_type = meta_type |
|---|
| 127 | security = ClassSecurityInfo() |
|---|
| 128 | |
|---|
| 129 | security.declareProtected(View,"Title") |
|---|
| 130 | def Title(self): |
|---|
| 131 | """compose title""" |
|---|
| 132 | content = self.getContent() |
|---|
| 133 | return "Personal Data for %s %s" % (content.firstname,content.lastname) |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | InitializeClass(StudentPersonal) |
|---|
| 137 | |
|---|
| 138 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
|---|
| 139 | """Add a Students personal data.""" |
|---|
| 140 | ob = StudentPersonal(id, **kw) |
|---|
| 141 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 142 | |
|---|
| 143 | ###) |
|---|
| 144 | |
|---|
| 145 | class StudentEligibility(CPSDocument): ###( |
|---|
| 146 | """ |
|---|
| 147 | WAeUP Student container for the various student data |
|---|
| 148 | """ |
|---|
| 149 | meta_type = 'StudentEligibility' |
|---|
| 150 | portal_type = meta_type |
|---|
| 151 | security = ClassSecurityInfo() |
|---|
| 152 | |
|---|
| 153 | security.declareProtected(View,"Title") |
|---|
| 154 | def Title(self): |
|---|
| 155 | """compose title""" |
|---|
| 156 | return "Eligibility Data" |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | InitializeClass(StudentEligibility) |
|---|
| 160 | |
|---|
| 161 | def addStudentEligibility(container, id, REQUEST=None, **kw): |
|---|
| 162 | """Add a Students eligibility data.""" |
|---|
| 163 | ob = StudentEligibility(id, **kw) |
|---|
| 164 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 165 | |
|---|
| 166 | ###) |
|---|
| 167 | |
|---|
| 168 | class StudentDocuments(CPSDocument): ###( |
|---|
| 169 | """ |
|---|
| 170 | WAeUP Student container for the various student data |
|---|
| 171 | """ |
|---|
| 172 | meta_type = 'StudentDocuments' |
|---|
| 173 | portal_type = meta_type |
|---|
| 174 | security = ClassSecurityInfo() |
|---|
| 175 | |
|---|
| 176 | security.declareProtected(View,"Title") |
|---|
| 177 | def Title(self): |
|---|
| 178 | """compose title""" |
|---|
| 179 | content = self.getContent() |
|---|
| 180 | return "Scanned Documents" |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | InitializeClass(StudentDocuments) |
|---|
| 184 | |
|---|
| 185 | def addStudentDocuments(container, id, REQUEST=None, **kw): |
|---|
| 186 | """Add a Students documents""" |
|---|
| 187 | ob = StudentDocuments(id, **kw) |
|---|
| 188 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 189 | |
|---|
| 190 | ###) |
|---|
| 191 | |
|---|
| 192 | class Jamb(CPSDocument): ###( |
|---|
| 193 | """ |
|---|
| 194 | WAeUP Jamb containing the courses and students |
|---|
| 195 | """ |
|---|
| 196 | meta_type = 'Jamb' |
|---|
| 197 | portal_type = meta_type |
|---|
| 198 | security = ClassSecurityInfo() |
|---|
| 199 | |
|---|
| 200 | security.declareProtected(View,"Title") |
|---|
| 201 | def Title(self): |
|---|
| 202 | """compose title""" |
|---|
| 203 | content = self.getContent() |
|---|
| 204 | return "JAMB Data for %s %s" % (content.firstname,content.lastname) |
|---|
| 205 | |
|---|
| 206 | security.declareProtected(View,"setOwnership") |
|---|
| 207 | def setOwnership(self,member_id): |
|---|
| 208 | """set ownership""" |
|---|
| 209 | pm = getattr(self,'portal_membership') |
|---|
| 210 | member = pm.getMemberById(member_id) |
|---|
| 211 | self.changeOwnership(member) |
|---|
| 212 | |
|---|
| 213 | InitializeClass(Jamb) |
|---|
| 214 | |
|---|
| 215 | def addJamb(container, id, REQUEST=None, **kw): |
|---|
| 216 | """Add a Jamb.""" |
|---|
| 217 | ob = Jamb(id, **kw) |
|---|
| 218 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 219 | |
|---|
| 220 | ###) |
|---|
| 221 | |
|---|
| 222 | class StudyLevel(CPSDocument): ###( |
|---|
| 223 | """ |
|---|
| 224 | WAeUP StudyLevel containing the courses and students |
|---|
| 225 | """ |
|---|
| 226 | meta_type = 'StudyLevel' |
|---|
| 227 | portal_type = meta_type |
|---|
| 228 | security = ClassSecurityInfo() |
|---|
| 229 | |
|---|
| 230 | InitializeClass(StudyLevel) |
|---|
| 231 | |
|---|
| 232 | def addStudyLevel(container, id, REQUEST=None, **kw): |
|---|
| 233 | """Add a StudyLevel.""" |
|---|
| 234 | ob = StudyLevel(id, **kw) |
|---|
| 235 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 236 | |
|---|
| 237 | ###) |
|---|
| 238 | |
|---|
| 239 | class Semester(CPSDocument): ###( |
|---|
| 240 | """ |
|---|
| 241 | WAeUP Semester containing the courses and students |
|---|
| 242 | """ |
|---|
| 243 | meta_type = 'Semester' |
|---|
| 244 | portal_type = meta_type |
|---|
| 245 | security = ClassSecurityInfo() |
|---|
| 246 | |
|---|
| 247 | InitializeClass(Semester) |
|---|
| 248 | |
|---|
| 249 | def addSemester(container, id, REQUEST=None, **kw): |
|---|
| 250 | """Add a Semester.""" |
|---|
| 251 | ob = Semester(id, **kw) |
|---|
| 252 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 253 | |
|---|
| 254 | ###) |
|---|
| 255 | |
|---|