source: WAeUP_SRP/trunk/Students.py @ 362

Last change on this file since 362 was 362, checked in by joachim, 18 years ago

more us changes

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