Index: WAeUP_SRP/trunk/Students.py
===================================================================
--- WAeUP_SRP/trunk/Students.py	(revision 276)
+++ WAeUP_SRP/trunk/Students.py	(revision 361)
@@ -13,20 +13,89 @@
 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)
-#####)
+from Products.WAeUP_SRP.Academics import makeCertificateCode
+
+class StudentsFolder(CPSDocument): ###(
+    """
+    WAeUP container for the various WAeUP containers data
+    """
+    meta_type = 'Students Folder'
+    portal_type = meta_type
+    security = ClassSecurityInfo()
+
+    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###(
+    def loadFullTimeStudentsFromCSV(self):
+        """load Fulltime Studentdata from CSV values"""
+        #return
+        name = 'short_full_time'
+        no_import = False
+        logger = logging.getLogger('%s_import' % name)
+        logger.info('Start loading from %s.csv' % name)
+        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
+        try:
+            students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
+        except:
+            logger.error('Error reading %s.csv' % name)
+            return
+        l = self.portal_catalog({'meta_type': "Student"})
+        studs = {}
+        for s in l:
+            studs[s.id] = s.getObject()
+        l = self.portal_catalog({'meta_type': "Certificate"})
+        certs = {}
+        for c in l:
+            certs[s.id] = c.getObject()
+        for student in students:
+            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)
+            sid = student.get('MatricNo')
+            certcode = makeCertificateCode(student.get('CourseMajor'))
+            s = studs.get(sid,None)
+            if certcode not in certs.keys():
+                em = 'Certificate with ID %s %s not found' % (certcode, student.get('CourseMajor'))
+                if not no_import:
+                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
+                    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')
+                logger.info(em)
+                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)
+                continue
+            if s is None:
+                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
+                logger.info('Creating Student with ID %(MatricNo)s %(fullname)s' % faculty)
+                students_folder.invokeFactory('Student', sid)
+                s = getattr(self,sid)
+                s.invokeFactory('StudentPersonal','personal')
+                sp = getattr(self,sid)
+                d = {'Title': 'Personal Data'}
+                d['fullname'] = student.get('fullname')
+                d['firstname'] = student.get('FirstName')
+                d['middlename'] = student.get('MiddleName')
+                d['lastname'] = student.get('LastName')
+                d['former_surname'] = student.get('FormerSurname')
+                d['sex'] = student.get('Sex') == 'M'
+                d['nationality'] = student.get('Nationality')
+                d['state'] = student.get('State') 
+                d['lga'] = student.get('LGA') 
+                d['street'] = student.get('PermanentAddress')
+                d['city'] = student.get('PermanentAddressCity')
+                d['campus_address'] = student.get('CampusAddress')
+                d['phone'] = student.get('PhoneNumber')
+                d['email'] = student.get('EmailAddress')
+                f.getContent().edit(mapping=d)
+            else:
+                em = 'Faculty with ID %(MatricNo)s %(fullname)s already exists' % student
+                if not no_import:
+                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
+                    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')
+                logger.info(em)
+                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)
+        return self.students.folder_contents()
+    ###)
+
+InitializeClass(StudentsFolder)
+
+def addStudentsFolder(container, id, REQUEST=None, **kw):
+    """Add a Student."""
+    ob = StudentsFolder(id, **kw)
+    return CPSBase_adder(container, ob, REQUEST=REQUEST)
+###)
 
 class Student(CPSDocument): ###(
