source: WAeUP_SRP/trunk/Students.py @ 395

Last change on this file since 395 was 395, checked in by joachim, 20 years ago

import Students now checks for empty levels and dupplicate MatricelNr?.

  • Property svn:keywords set to Id
File size: 16.1 KB
RevLine 
[57]1#-*- mode: python; mode: fold -*-
[200]2# $Id: Students.py 395 2006-08-20 12:29:10Z joachim $
[45]3from Globals import InitializeClass
4from AccessControl import ClassSecurityInfo
[164]5from AccessControl.SecurityManagement import newSecurityManager
[45]6
[47]7from Products.CMFCore.utils import UniqueObject, getToolByName
[45]8from Products.CMFCore.permissions import View
9from Products.CMFCore.permissions import ModifyPortalContent
[154]10from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
11#from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument
12from Products.CPSDocument.CPSDocument import CPSDocument
13from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder
[164]14from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser
[361]15from Products.WAeUP_SRP.Academics import makeCertificateCode
[362]16import logging
17import csv,re
18import Globals
19p_home = Globals.package_home(globals())
20i_home = Globals.INSTANCE_HOME
[154]21
[361]22class StudentsFolder(CPSDocument): ###(
23    """
24    WAeUP container for the various WAeUP containers data
25    """
[362]26    meta_type = 'StudentsFolder'
[361]27    portal_type = meta_type
28    security = ClassSecurityInfo()
[154]29
[361]30    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###(
31    def loadFullTimeStudentsFromCSV(self):
32        """load Fulltime Studentdata from CSV values"""
33        #return
34        name = 'short_full_time'
35        no_import = False
[395]36        if not no_import:
37            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
38            no_import.write('"MatricNo","EntryRegNo","CurrentSession","StudentLevel","fullname","FirstName","MiddleName","Lastname","FormerSurname","Sex","Nationality","State","LGA","PermanentAddress","PermanentAddressCity","CampusAddress","PhoneNumber","Emailaddress","Mode","CourseMajor","Faculty","Dept"\n')
[361]39        logger = logging.getLogger('%s_import' % name)
40        logger.info('Start loading from %s.csv' % name)
41        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
42        try:
43            students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
44        except:
45            logger.error('Error reading %s.csv' % name)
46            return
47        l = self.portal_catalog({'meta_type': "Student"})
48        studs = {}
49        for s in l:
50            studs[s.id] = s.getObject()
51        l = self.portal_catalog({'meta_type': "Certificate"})
52        certs = {}
[395]53        students_added = []
[361]54        for c in l:
[362]55            certs[c.id] = c.getObject()
[361]56        for student in students:
[393]57            logger.info('processing "%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
[361]58            sid = student.get('MatricNo')
59            certcode = makeCertificateCode(student.get('CourseMajor'))
[395]60            if sid in students_added:
61                em = 'Student with ID %(MatricNo)s %(fullname)s already exists in this import\n' % student
62                logger.info(em)
63                no_import.write(em)
64                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
65                continue
[361]66            s = studs.get(sid,None)
67            if certcode not in certs.keys():
[393]68                em = 'Certificate with ID %s %s not found\n' % (certcode, student.get('CourseMajor'))
[361]69                logger.info(em)
[393]70                no_import.write(em)
71                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
[361]72                continue
[395]73            level = student.get('StudentLevel')
74            try:
75                int(level)
76            except:
77                em = 'Student with ID %(MatricNo)s StudentLevel is empty\n' % student
78                logger.info(em)
79                no_import.write(em)
80                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
81                continue
[361]82            if s is None:
83                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
[362]84                logger.info('Creating Student with ID %(MatricNo)s %(fullname)s' % student)
[361]85                students_folder.invokeFactory('Student', sid)
86                s = getattr(self,sid)
[395]87                students_added.append(sid)
[361]88                s.invokeFactory('StudentPersonal','personal')
[362]89                sp = s.personal
[361]90                d = {'Title': 'Personal Data'}
[362]91                d['matricel_no'] = student.get('MatricNo')
92                d['entry_reg_no'] = student.get('EntryRegNo')
[361]93                d['fullname'] = student.get('fullname')
94                d['firstname'] = student.get('FirstName')
95                d['middlename'] = student.get('MiddleName')
[362]96                d['lastname'] = student.get('Lastname')
[361]97                d['former_surname'] = student.get('FormerSurname')
[362]98                d['sex'] = student.get('Sex') == 'F'
[361]99                d['nationality'] = student.get('Nationality')
[382]100                d['state'] = student.get('State')
101                d['lga'] = student.get('LGA')
[361]102                d['street'] = student.get('PermanentAddress')
103                d['city'] = student.get('PermanentAddressCity')
104                d['campus_address'] = student.get('CampusAddress')
105                d['phone'] = student.get('PhoneNumber')
[362]106                d['email'] = student.get('Emailaddress')
107                sp.getContent().edit(mapping=d)
108                #
109                # Study Course
110                #
111                s.invokeFactory('StudentStudyCourse','study_course')
112                sc = s.study_course
113                d = {}
114                d['matricel_no'] = student.get('MatricNo')
115                d['entry_reg_no'] = student.get('EntryRegNo')
116                d['faculty'] = student.get('Faculty')
117                d['department'] = student.get('Dept')
118                d['course_major'] = certcode
119                css = student.get('CurrentSession') or '2004-2005'
120                cs = int(css.split('-')[0]) - 2000
121                cl = int(student.get('StudentLevel'))/100
122                d['entry_session'] = "200%s" % (cs - cl)
123                sc.getContent().edit(mapping=d)
[364]124                #
125                # Level
126                #
127                l = getattr(sc,level,None)
128                if l is None:
129                    #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
130                    logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student)
131                    sc.invokeFactory('StudyLevel', level)
132                    l = getattr(sc, level)
133                    certificate = certs[certcode]
134                    cert_level = getattr(certificate,level,None)
135                    if cert_level is None:
136                        logger.info('Level %(level)s not in %(certcode)s' % vars())
137                    l.getContent().edit(mapping={'Title': "Level %s" % level})
138                    l.invokeFactory('Semester','first')
139                    l.invokeFactory('Semester','second')
140                    first_s = getattr(l,'first')
141                    first_s.getContent().edit(mapping={'Title': 'First Semester'})
142                    second_s = getattr(l,'second')
143                    second_s.getContent().edit(mapping={'Title': 'Second Semester'})
[361]144            else:
[393]145                em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student
[361]146                logger.info(em)
[393]147                no_import.write(em)
148                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
149        return self.students.academics_contents()
[361]150    ###)
[382]151
[364]152    security.declareProtected(View,"Title")
153    def Title(self):
154        """compose title"""
[382]155        return "Student Section"
[361]156
157InitializeClass(StudentsFolder)
158
159def addStudentsFolder(container, id, REQUEST=None, **kw):
160    """Add a Student."""
161    ob = StudentsFolder(id, **kw)
162    return CPSBase_adder(container, ob, REQUEST=REQUEST)
163###)
164
[57]165class Student(CPSDocument): ###(
166    """
[154]167    WAeUP Student container for the various student data
[57]168    """
169    meta_type = 'Student'
170    portal_type = meta_type
171    security = ClassSecurityInfo()
[154]172
[152]173    security.declareProtected(View,"Title")
174    def Title(self):
175        """compose title"""
[153]176        reg_nr = self.getId()[1:]
[362]177        data = getattr(self,'personal',None)
[152]178        if data is None:
[362]179            data = getattr(self,'jamb',None)
[152]180        if data:
181            content = data.getContent()
182            return "%s %s" % (content.firstname,content.lastname)
183        return self.title
[154]184
185    def Description(self):
186        """compose description"""
[170]187        data = getattr(self,'PERSONAL',None)
188        if data is None:
[191]189            return "none"
[154]190        if data:
[191]191            content = data.getContent()
192            return "%s" % (content.description)
[154]193        return self.description
194
[164]195    security.declareProtected(View,"setScratchCardData")
196    def setScratchCardData(self,ident,ds):
197        """set this data """
198        dict = {'%s_sc_pin' % ident : ds.get('sc_pin'),
199                '%s_sc_id' % ident : ds.get('sc_id'),
200                '%s_sc_value' % ident : ds.get('sc_value'),
[166]201                '%s_date' % ident : ds.get('sc_date'),
[164]202                }
[170]203
[173]204        old_user = self.portal_membership.getAuthenticatedMember()
[166]205        if self.portal_membership.isAnonymousUser():
206            tmp_user = CPSUnrestrictedUser('s%(jamb_id)s' % ds, '',
[164]207                                       ['StudentManager'], '')
[166]208            tmp_user = tmp_user.__of__(self.acl_users)
209            newSecurityManager(None, tmp_user)
210        #print str(dict)
[164]211        self.edit(mapping=dict)
[173]212        newSecurityManager(None, old_user)
[164]213
214    security.declareProtected(View,"memberIsOwner")
215    def memberIsOwner(self):
216        """is the current user the owner"""
217        member = self.portal_membership.getAuthenticatedMember()
218        #print member, self.getId(),self.aq_parent.getId()
219        if self.aq_parent.getId() == str(member):
220            return True
221        return False
222
[166]223    security.declareProtected(View,"accommodationIsBooked")
224    def accommodationIsBooked(self):
225        """is the accommodation booked"""
226        if self.accommodation_sc_pin != '':
227            return True
228        return False
229
230    security.declareProtected(View,"accommodationIsPayed")
231    def accommodationIsPayed(self):
232        """is the accommodation payed"""
[168]233        if self.hostel_fee_sc_pin != '':
[166]234            return True
235        return False
236
237    security.declareProtected(View,"isRegisteredForCurrentLevel")
238    def isRegisteredForCurrentLevel(self):
239        """is the student registered for the current level"""
240        for l in  self.aq_parent.objectValues():
241            if l.portal_type == 'StudyLevel':
242                return True
243        return False
244
[57]245InitializeClass(Student)
246
247def addStudent(container, id, REQUEST=None, **kw):
248    """Add a Student."""
249    ob = Student(id, **kw)
250    return CPSBase_adder(container, ob, REQUEST=REQUEST)
251
252###)
[91]253
[89]254class StudentPersonal(CPSDocument): ###(
255    """
[154]256    WAeUP Student container for the various student data
[89]257    """
258    meta_type = 'StudentPersonal'
259    portal_type = meta_type
260    security = ClassSecurityInfo()
[152]261
262    security.declareProtected(View,"Title")
263    def Title(self):
264        """compose title"""
265        content = self.getContent()
[364]266        #return "Personal Data for %s %s" % (content.firstname,content.lastname)
267        return "Personal Data"
[152]268
[154]269
[89]270InitializeClass(StudentPersonal)
271
272def addStudentPersonal(container, id, REQUEST=None, **kw):
273    """Add a Students personal data."""
274    ob = StudentPersonal(id, **kw)
275    return CPSBase_adder(container, ob, REQUEST=REQUEST)
276
277###)
278
[362]279class StudentStudyCourse(CPSDocument): ###(
280    """
281    WAeUP Student container for the various student data
282    """
283    meta_type = 'StudentStudyCourse'
284    portal_type = meta_type
285    security = ClassSecurityInfo()
286
[364]287    security.declareProtected(View,"Title")
288    def Title(self):
289        """compose title"""
290        content = self.getContent()
[382]291        return "Course Major"
[362]292
293
294InitializeClass(StudentStudyCourse)
295
296def addStudentStudyCourse(container, id, REQUEST=None, **kw):
297    """Add a Students personal data."""
298    ob = StudentStudyCourse(id, **kw)
299    return CPSBase_adder(container, ob, REQUEST=REQUEST)
300
301###)
302
[179]303class StudentEligibility(CPSDocument): ###(
304    """
305    WAeUP Student container for the various student data
306    """
307    meta_type = 'StudentEligibility'
308    portal_type = meta_type
309    security = ClassSecurityInfo()
310
[181]311    security.declareProtected(View,"Title")
312    def Title(self):
313        """compose title"""
314        return "Eligibility Data"
[179]315
[181]316
[179]317InitializeClass(StudentEligibility)
318
319def addStudentEligibility(container, id, REQUEST=None, **kw):
320    """Add a Students eligibility data."""
321    ob = StudentEligibility(id, **kw)
322    return CPSBase_adder(container, ob, REQUEST=REQUEST)
323
324###)
[181]325
[166]326class StudentDocuments(CPSDocument): ###(
327    """
328    WAeUP Student container for the various student data
329    """
330    meta_type = 'StudentDocuments'
331    portal_type = meta_type
332    security = ClassSecurityInfo()
333
334    security.declareProtected(View,"Title")
335    def Title(self):
336        """compose title"""
337        content = self.getContent()
338        return "Scanned Documents"
339
340
341InitializeClass(StudentDocuments)
342
343def addStudentDocuments(container, id, REQUEST=None, **kw):
344    """Add a Students documents"""
345    ob = StudentDocuments(id, **kw)
346    return CPSBase_adder(container, ob, REQUEST=REQUEST)
347
348###)
349
[89]350class Jamb(CPSDocument): ###(
351    """
352    WAeUP Jamb containing the courses and students
353    """
354    meta_type = 'Jamb'
355    portal_type = meta_type
356    security = ClassSecurityInfo()
[154]357
[152]358    security.declareProtected(View,"Title")
359    def Title(self):
360        """compose title"""
361        content = self.getContent()
362        return "JAMB Data for %s %s" % (content.firstname,content.lastname)
363
364    security.declareProtected(View,"setOwnership")
365    def setOwnership(self,member_id):
366        """set ownership"""
367        pm = getattr(self,'portal_membership')
368        member = pm.getMemberById(member_id)
369        self.changeOwnership(member)
370
[89]371InitializeClass(Jamb)
372
373def addJamb(container, id, REQUEST=None, **kw):
374    """Add a Jamb."""
375    ob = Jamb(id, **kw)
376    return CPSBase_adder(container, ob, REQUEST=REQUEST)
377
[139]378###)
379
380class StudyLevel(CPSDocument): ###(
381    """
382    WAeUP StudyLevel containing the courses and students
383    """
384    meta_type = 'StudyLevel'
385    portal_type = meta_type
386    security = ClassSecurityInfo()
[154]387
[139]388InitializeClass(StudyLevel)
389
390def addStudyLevel(container, id, REQUEST=None, **kw):
391    """Add a StudyLevel."""
392    ob = StudyLevel(id, **kw)
393    return CPSBase_adder(container, ob, REQUEST=REQUEST)
394
395###)
396
397class Semester(CPSDocument): ###(
398    """
399    WAeUP Semester containing the courses and students
400    """
401    meta_type = 'Semester'
402    portal_type = meta_type
403    security = ClassSecurityInfo()
[154]404
[139]405InitializeClass(Semester)
406
407def addSemester(container, id, REQUEST=None, **kw):
408    """Add a Semester."""
409    ob = Semester(id, **kw)
410    return CPSBase_adder(container, ob, REQUEST=REQUEST)
[200]411
[139]412###)
413
Note: See TracBrowser for help on using the repository browser.