| 1 | #-*- mode: python; mode: fold -*- |
|---|
| 2 | from Globals import InitializeClass |
|---|
| 3 | from AccessControl import ClassSecurityInfo |
|---|
| 4 | from AccessControl.SecurityManagement import newSecurityManager |
|---|
| 5 | |
|---|
| 6 | from Products.CMFCore.utils import UniqueObject, getToolByName |
|---|
| 7 | from Products.CMFCore.permissions import View |
|---|
| 8 | from Products.CMFCore.permissions import ModifyPortalContent |
|---|
| 9 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
|---|
| 10 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
|---|
| 11 | from Products.CPSDocument.CPSDocument import CPSDocument |
|---|
| 12 | from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
|---|
| 13 | from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser |
|---|
| 14 | class StudentsFolder(BaseBTreeFolder): ###( |
|---|
| 15 | """ |
|---|
| 16 | WAeUP container for the various WAeUP containers data |
|---|
| 17 | """ |
|---|
| 18 | meta_type = 'Students Folder' |
|---|
| 19 | portal_type = meta_type |
|---|
| 20 | security = ClassSecurityInfo() |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | InitializeClass(StudentsFolder) |
|---|
| 24 | |
|---|
| 25 | def addStudentsFolder(container, id, REQUEST=None, **kw): |
|---|
| 26 | """Add a Student.""" |
|---|
| 27 | ob = StudentsFolder(id, **kw) |
|---|
| 28 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 29 | ###) |
|---|
| 30 | |
|---|
| 31 | student_fti = { ###( |
|---|
| 32 | 'title': 'WAeUP Student', |
|---|
| 33 | 'description': '', |
|---|
| 34 | 'content_icon': 'student.gif', |
|---|
| 35 | 'content_meta_type': 'Student', |
|---|
| 36 | 'factory': 'addStudent', |
|---|
| 37 | 'immediate_view': 'cpsdocument_view', |
|---|
| 38 | 'global_allow': True, |
|---|
| 39 | 'filter_content_types': True, |
|---|
| 40 | 'allowed_content_types': ('Jamb','StudentPersonal'), |
|---|
| 41 | 'allow_discussion': False, |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | ###) |
|---|
| 45 | |
|---|
| 46 | class Student(CPSDocument): ###( |
|---|
| 47 | """ |
|---|
| 48 | WAeUP Student container for the various student data |
|---|
| 49 | """ |
|---|
| 50 | meta_type = 'Student' |
|---|
| 51 | portal_type = meta_type |
|---|
| 52 | security = ClassSecurityInfo() |
|---|
| 53 | |
|---|
| 54 | security.declareProtected(View,"Title") |
|---|
| 55 | def Title(self): |
|---|
| 56 | """compose title""" |
|---|
| 57 | reg_nr = self.getId()[1:] |
|---|
| 58 | data = getattr(self,'PERSONAL',None) |
|---|
| 59 | if data is None: |
|---|
| 60 | data = getattr(self,'JAMB',None) |
|---|
| 61 | if data: |
|---|
| 62 | content = data.getContent() |
|---|
| 63 | return "%s %s" % (content.firstname,content.lastname) |
|---|
| 64 | return self.title |
|---|
| 65 | |
|---|
| 66 | def Description(self): |
|---|
| 67 | """compose description""" |
|---|
| 68 | data = getattr(self,'PERSONAL',None) |
|---|
| 69 | if data is None: |
|---|
| 70 | return "none" |
|---|
| 71 | if data: |
|---|
| 72 | content = data.getContent() |
|---|
| 73 | return "%s" % (content.description) |
|---|
| 74 | return self.description |
|---|
| 75 | |
|---|
| 76 | security.declareProtected(View,"setScratchCardData") |
|---|
| 77 | def setScratchCardData(self,ident,ds): |
|---|
| 78 | """set this data """ |
|---|
| 79 | dict = {'%s_sc_pin' % ident : ds.get('sc_pin'), |
|---|
| 80 | '%s_sc_id' % ident : ds.get('sc_id'), |
|---|
| 81 | '%s_sc_value' % ident : ds.get('sc_value'), |
|---|
| 82 | '%s_date' % ident : ds.get('sc_date'), |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | old_user = self.portal_membership.getAuthenticatedMember() |
|---|
| 86 | if self.portal_membership.isAnonymousUser(): |
|---|
| 87 | tmp_user = CPSUnrestrictedUser('s%(jamb_id)s' % ds, '', |
|---|
| 88 | ['StudentManager'], '') |
|---|
| 89 | tmp_user = tmp_user.__of__(self.acl_users) |
|---|
| 90 | newSecurityManager(None, tmp_user) |
|---|
| 91 | #print str(dict) |
|---|
| 92 | self.edit(mapping=dict) |
|---|
| 93 | newSecurityManager(None, old_user) |
|---|
| 94 | |
|---|
| 95 | security.declareProtected(View,"memberIsOwner") |
|---|
| 96 | def memberIsOwner(self): |
|---|
| 97 | """is the current user the owner""" |
|---|
| 98 | member = self.portal_membership.getAuthenticatedMember() |
|---|
| 99 | #print member, self.getId(),self.aq_parent.getId() |
|---|
| 100 | if self.aq_parent.getId() == str(member): |
|---|
| 101 | return True |
|---|
| 102 | return False |
|---|
| 103 | |
|---|
| 104 | security.declareProtected(View,"accommodationIsBooked") |
|---|
| 105 | def accommodationIsBooked(self): |
|---|
| 106 | """is the accommodation booked""" |
|---|
| 107 | if self.accommodation_sc_pin != '': |
|---|
| 108 | return True |
|---|
| 109 | return False |
|---|
| 110 | |
|---|
| 111 | security.declareProtected(View,"accommodationIsPayed") |
|---|
| 112 | def accommodationIsPayed(self): |
|---|
| 113 | """is the accommodation payed""" |
|---|
| 114 | if self.hostel_fee_sc_pin != '': |
|---|
| 115 | return True |
|---|
| 116 | return False |
|---|
| 117 | |
|---|
| 118 | security.declareProtected(View,"isRegisteredForCurrentLevel") |
|---|
| 119 | def isRegisteredForCurrentLevel(self): |
|---|
| 120 | """is the student registered for the current level""" |
|---|
| 121 | for l in self.aq_parent.objectValues(): |
|---|
| 122 | if l.portal_type == 'StudyLevel': |
|---|
| 123 | return True |
|---|
| 124 | return False |
|---|
| 125 | |
|---|
| 126 | InitializeClass(Student) |
|---|
| 127 | |
|---|
| 128 | def addStudent(container, id, REQUEST=None, **kw): |
|---|
| 129 | """Add a Student.""" |
|---|
| 130 | ob = Student(id, **kw) |
|---|
| 131 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 132 | |
|---|
| 133 | ###) |
|---|
| 134 | |
|---|
| 135 | studentpersonal_fti = { ###( |
|---|
| 136 | 'title': 'WAeUP StudentPersonal', |
|---|
| 137 | 'description': '', |
|---|
| 138 | 'content_icon': 'student.gif', |
|---|
| 139 | 'content_meta_type': 'StudentPersonal', |
|---|
| 140 | 'factory': 'addStudent', |
|---|
| 141 | 'immediate_view': 'student_personal_index_html', |
|---|
| 142 | 'global_allow': True, |
|---|
| 143 | 'filter_content_types': True, |
|---|
| 144 | 'allowed_content_types': (), |
|---|
| 145 | 'allow_discussion': False, |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | ###) |
|---|
| 149 | |
|---|
| 150 | class StudentPersonal(CPSDocument): ###( |
|---|
| 151 | """ |
|---|
| 152 | WAeUP Student container for the various student data |
|---|
| 153 | """ |
|---|
| 154 | meta_type = 'StudentPersonal' |
|---|
| 155 | portal_type = meta_type |
|---|
| 156 | security = ClassSecurityInfo() |
|---|
| 157 | |
|---|
| 158 | security.declareProtected(View,"Title") |
|---|
| 159 | def Title(self): |
|---|
| 160 | """compose title""" |
|---|
| 161 | content = self.getContent() |
|---|
| 162 | return "Personal Data for %s %s" % (content.firstname,content.lastname) |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | InitializeClass(StudentPersonal) |
|---|
| 166 | |
|---|
| 167 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
|---|
| 168 | """Add a Students personal data.""" |
|---|
| 169 | ob = StudentPersonal(id, **kw) |
|---|
| 170 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 171 | |
|---|
| 172 | ###) |
|---|
| 173 | |
|---|
| 174 | studenteligibility_fti = { ###( |
|---|
| 175 | 'title': 'WAeUP StudentEligibility', |
|---|
| 176 | 'description': '', |
|---|
| 177 | 'content_icon': 'student.gif', |
|---|
| 178 | 'content_meta_type': 'StudentEligibility', |
|---|
| 179 | 'factory': 'addStudent', |
|---|
| 180 | 'immediate_view': 'student_eligibility_index_html', |
|---|
| 181 | 'global_allow': True, |
|---|
| 182 | 'filter_content_types': True, |
|---|
| 183 | 'allowed_content_types': (), |
|---|
| 184 | 'allow_discussion': False, |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | ###) |
|---|
| 188 | |
|---|
| 189 | class StudentEligibility(CPSDocument): ###( |
|---|
| 190 | """ |
|---|
| 191 | WAeUP Student container for the various student data |
|---|
| 192 | """ |
|---|
| 193 | meta_type = 'StudentEligibility' |
|---|
| 194 | portal_type = meta_type |
|---|
| 195 | security = ClassSecurityInfo() |
|---|
| 196 | |
|---|
| 197 | security.declareProtected(View,"Title") |
|---|
| 198 | def Title(self): |
|---|
| 199 | """compose title""" |
|---|
| 200 | return "Eligibility Data" |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | InitializeClass(StudentEligibility) |
|---|
| 204 | |
|---|
| 205 | def addStudentEligibility(container, id, REQUEST=None, **kw): |
|---|
| 206 | """Add a Students eligibility data.""" |
|---|
| 207 | ob = StudentEligibility(id, **kw) |
|---|
| 208 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 209 | |
|---|
| 210 | ###) |
|---|
| 211 | |
|---|
| 212 | studentdocuments_fti = { ###( |
|---|
| 213 | 'title': 'WAeUP StudentDocuments', |
|---|
| 214 | 'description': '', |
|---|
| 215 | 'content_icon': 'student.gif', |
|---|
| 216 | 'content_meta_type': 'StudentDocuments', |
|---|
| 217 | 'factory': 'addStudent', |
|---|
| 218 | 'immediate_view': 'temporary_view_all', |
|---|
| 219 | 'global_allow': True, |
|---|
| 220 | 'filter_content_types': True, |
|---|
| 221 | 'allowed_content_types': (), |
|---|
| 222 | 'allow_discussion': False, |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | ###) |
|---|
| 226 | |
|---|
| 227 | class StudentDocuments(CPSDocument): ###( |
|---|
| 228 | """ |
|---|
| 229 | WAeUP Student container for the various student data |
|---|
| 230 | """ |
|---|
| 231 | meta_type = 'StudentDocuments' |
|---|
| 232 | portal_type = meta_type |
|---|
| 233 | security = ClassSecurityInfo() |
|---|
| 234 | |
|---|
| 235 | security.declareProtected(View,"Title") |
|---|
| 236 | def Title(self): |
|---|
| 237 | """compose title""" |
|---|
| 238 | content = self.getContent() |
|---|
| 239 | return "Scanned Documents" |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | InitializeClass(StudentDocuments) |
|---|
| 243 | |
|---|
| 244 | def addStudentDocuments(container, id, REQUEST=None, **kw): |
|---|
| 245 | """Add a Students documents""" |
|---|
| 246 | ob = StudentDocuments(id, **kw) |
|---|
| 247 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 248 | |
|---|
| 249 | ###) |
|---|
| 250 | |
|---|
| 251 | jamb_fti = { ###( |
|---|
| 252 | 'title': 'WAeUP Jamb', |
|---|
| 253 | 'description': '', |
|---|
| 254 | 'content_icon': '', |
|---|
| 255 | 'content_meta_type': 'Jamb', |
|---|
| 256 | 'factory': 'addJamb', |
|---|
| 257 | 'immediate_view': 'cpsdocument_view', |
|---|
| 258 | 'global_allow': True, |
|---|
| 259 | 'filter_content_types': True, |
|---|
| 260 | 'allowed_content_types': ('Course',), |
|---|
| 261 | 'allow_discussion': False, |
|---|
| 262 | } |
|---|
| 263 | ###) |
|---|
| 264 | |
|---|
| 265 | class Jamb(CPSDocument): ###( |
|---|
| 266 | """ |
|---|
| 267 | WAeUP Jamb containing the courses and students |
|---|
| 268 | """ |
|---|
| 269 | meta_type = 'Jamb' |
|---|
| 270 | portal_type = meta_type |
|---|
| 271 | security = ClassSecurityInfo() |
|---|
| 272 | |
|---|
| 273 | security.declareProtected(View,"Title") |
|---|
| 274 | def Title(self): |
|---|
| 275 | """compose title""" |
|---|
| 276 | content = self.getContent() |
|---|
| 277 | return "JAMB Data for %s %s" % (content.firstname,content.lastname) |
|---|
| 278 | |
|---|
| 279 | security.declareProtected(View,"setOwnership") |
|---|
| 280 | def setOwnership(self,member_id): |
|---|
| 281 | """set ownership""" |
|---|
| 282 | pm = getattr(self,'portal_membership') |
|---|
| 283 | member = pm.getMemberById(member_id) |
|---|
| 284 | self.changeOwnership(member) |
|---|
| 285 | |
|---|
| 286 | InitializeClass(Jamb) |
|---|
| 287 | |
|---|
| 288 | def addJamb(container, id, REQUEST=None, **kw): |
|---|
| 289 | """Add a Jamb.""" |
|---|
| 290 | ob = Jamb(id, **kw) |
|---|
| 291 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 292 | ###) |
|---|
| 293 | |
|---|
| 294 | study_level_fti = { ###( |
|---|
| 295 | 'title': 'WAeUP StudyLevel', |
|---|
| 296 | 'description': '', |
|---|
| 297 | 'content_icon': '', |
|---|
| 298 | 'content_meta_type': 'StudyLevel', |
|---|
| 299 | 'factory': 'addStudyLevel', |
|---|
| 300 | 'immediate_view': 'cpsdocument_view', |
|---|
| 301 | 'global_allow': True, |
|---|
| 302 | 'filter_content_types': True, |
|---|
| 303 | 'allowed_content_types': ('Course',), |
|---|
| 304 | 'allow_discussion': False, |
|---|
| 305 | } |
|---|
| 306 | ###) |
|---|
| 307 | |
|---|
| 308 | class StudyLevel(CPSDocument): ###( |
|---|
| 309 | """ |
|---|
| 310 | WAeUP StudyLevel containing the courses and students |
|---|
| 311 | """ |
|---|
| 312 | meta_type = 'StudyLevel' |
|---|
| 313 | portal_type = meta_type |
|---|
| 314 | security = ClassSecurityInfo() |
|---|
| 315 | |
|---|
| 316 | InitializeClass(StudyLevel) |
|---|
| 317 | |
|---|
| 318 | def addStudyLevel(container, id, REQUEST=None, **kw): |
|---|
| 319 | """Add a StudyLevel.""" |
|---|
| 320 | ob = StudyLevel(id, **kw) |
|---|
| 321 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 322 | ###) |
|---|
| 323 | |
|---|
| 324 | semester_fti = { ###( |
|---|
| 325 | 'title': 'WAeUP Semester', |
|---|
| 326 | 'description': '', |
|---|
| 327 | 'content_icon': '', |
|---|
| 328 | 'content_meta_type': 'Semester', |
|---|
| 329 | 'factory': 'addSemester', |
|---|
| 330 | 'immediate_view': 'cpsdocument_view', |
|---|
| 331 | 'global_allow': True, |
|---|
| 332 | 'filter_content_types': True, |
|---|
| 333 | 'allowed_content_types': ('Course',), |
|---|
| 334 | 'allow_discussion': False, |
|---|
| 335 | } |
|---|
| 336 | ###) |
|---|
| 337 | |
|---|
| 338 | class Semester(CPSDocument): ###( |
|---|
| 339 | """ |
|---|
| 340 | WAeUP Semester containing the courses and students |
|---|
| 341 | """ |
|---|
| 342 | meta_type = 'Semester' |
|---|
| 343 | portal_type = meta_type |
|---|
| 344 | security = ClassSecurityInfo() |
|---|
| 345 | |
|---|
| 346 | InitializeClass(Semester) |
|---|
| 347 | |
|---|
| 348 | def addSemester(container, id, REQUEST=None, **kw): |
|---|
| 349 | """Add a Semester.""" |
|---|
| 350 | ob = Semester(id, **kw) |
|---|
| 351 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 352 | ###) |
|---|
| 353 | |
|---|