Index: WAeUP_SRP/trunk/Students.py
===================================================================
--- WAeUP_SRP/trunk/Students.py	(revision 1938)
+++ WAeUP_SRP/trunk/Students.py	(revision 1939)
@@ -41,5 +41,5 @@
 ###)
 
-def response_write(response,s):
+def response_write(response,s): ###(
     response.setHeader('Content-type','text/html; charset=ISO-8859-15')
     while s.find('<') > -1:
@@ -49,4 +49,6 @@
         s = s.replace('>','&gt;')
     response.write("%s<br>\n" % s)
+
+###)
 
 def getInt(s): ###(
@@ -81,5 +83,5 @@
 ###)
 
-def checkJambNo(jnr):
+def checkJambNo(jnr): ###(
     try:
         if len(jnr) != 10:
@@ -92,4 +94,11 @@
     except:
         return False
+
+###)
+
+def formatLGA(lga):
+    if lga.find('_') > -1:
+        return "%s / %s" % (lga.split('_')[0].upper(),lga.split('_')[1].upper())
+    return lga
 
 class StudentsFolder(CPSDocument): ###(
@@ -885,4 +894,87 @@
     ###)
 
+    security.declareProtected(ModifyPortalContent,"exportStudents")###(
+    def exportStudents(self):
+        """export Studentsdata to a file"""
+        logger = logging.getLogger('Students.exportStudents')
+        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
+        students_folder = self.portal_url.getPortalObject().campus.students
+        export_file = "%s/export/students_%s.csv" % (i_home,current)
+        from Products.AdvancedQuery import Eq, Between, Le,In,MatchRegexp
+        aq_students = self.students_catalog.evalAdvancedQuery
+        toexport = {'students_catalog': ("id",
+                                         "matric_no",
+                                         "jamb_reg_no",
+                                         "review_state",
+                                         "sex",
+                                         "email",
+                                         "faculty",
+                                         "department",
+                                         "course",
+                                         "level",
+                                        ),
+                    'personal': ('firstname',
+                                 'middlename',
+                                 'lastname',
+                                 'perm_address',
+                                ),
+                    'clearance': ('state',
+                                  'lga',
+                                 )
+                  }
+        res_list = []
+        lines = []
+        fields = []
+        with_lga = False
+        for k in toexport.keys():
+            for f in toexport[k]:
+                if f == 'lga' :
+                    with_lga = True
+                fields.append(f)
+        headline = ','.join(fields)
+        open(export_file,"a").write(headline +'\n')
+        format = '"%(' + ')s","%('.join(fields) + ')s"'
+        query = In('review_state',('cleared_and_validated',
+                                'school_fee_paid',
+                                'courses_registered',
+                                'courses_validated'))
+        students = aq_students(query)
+        chunk = 100
+        total = 0
+        for student in students:
+            not_all = False
+            d = self.getFormattedStudentEntry(student)
+            for k in toexport.keys()[1:]:
+                try:
+                    object = getattr(getattr(students_folder,student.id),k)
+                    object_doc = object.getContent()
+                except:
+                    logger.info('%s %s record not found' % (student.id,k))
+                    not_all = True
+                    continue
+                for f in toexport[k]:
+                    d[f] = getattr(object_doc,f,'')
+            if not_all:
+                continue
+            if with_lga:
+                d['lga'] = formatLGA(d['lga'])
+            lines.append(format % d)
+            total += 1
+            if total and not total % chunk or total == len(students):
+                open(export_file,"a").write('\n'.join(lines) +'\n')
+                anz = len(lines)
+                logger.info("wrote %(anz)d to %(export_file)s" % vars())
+                lines = []
+        filename, extension = os.path.splitext(export_file)
+        os.system('zip %s %s' % (filename,export_file))
+        os.system('rm %s' % (export_file))
+        msg = "finished wrote %(total)d records to %(filename)s.zip" % vars()
+        logger.info(msg)
+        args = {'portal_status_message': msg}
+        #url = self.REQUEST.get('URL1') + '?' + urlencode(args)
+        url = self.REQUEST.get('URL1')
+        return self.REQUEST.RESPONSE.redirect(url)
+    ###)            
+
     security.declareProtected(ModifyPortalContent,"importResults")###(
     def importResults(self):
