Index: /WAeUP_SRP/base/Students.py
===================================================================
--- /WAeUP_SRP/base/Students.py	(revision 3452)
+++ /WAeUP_SRP/base/Students.py	(revision 3453)
@@ -284,4 +284,120 @@
     ###)
 
+    security.declareProtected(ModifyPortalContent,"exportStudents")###(
+    def exportStudents(self):
+        """export Studentsdata to a file"""
+        member = self.portal_membership.getAuthenticatedMember()
+        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",
+                                         "name",
+                                         #"review_state",
+                                         #"entry_session",
+                                         #"session",
+                                         #"entry_mode",
+                                         #"mode",
+                                         #"verdict",
+                                         #"sex",
+                                         #"email",
+                                         #"phone",
+                                         #"faculty",
+                                         #"department",
+                                         #"course",
+                                         #"level",
+                                        ),
+                    #'personal': ('firstname',
+                    #             'middlename',
+                    #             'lastname',
+                    #             'perm_address',
+                    #             ),
+                    'clearance': (#'state',  # is not an attribute of clearance but is needed for splitting lga
+                                  #'lga',
+                                  'birthday',
+                                 )
+                  }
+        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).replace('level','current_level')
+        open(export_file,"a").write(headline +'\n')
+        format = '"%(' + ')s","%('.join(fields) + ')s"'
+        #query = In('review_state',('cleared_and_validated',
+        #                        'clearance_requested',
+        #                        'school_fee_paid',
+        #                        'courses_registered',
+        #                        'courses_validated'))
+        #query = In('review_state',('clearance_requested'))
+        #students = aq_students(query)
+        students = aq_students
+        nr2export = len(students)
+        logger.info('%s starts exportStudents, %s student records to export' % (member,nr2export))
+        chunk = 1000
+        total = 0
+        start = DateTime.DateTime().timeTime()
+        start_chunk = DateTime.DateTime().timeTime()
+        for student in students:
+            not_all = False
+            d = self.getFormattedStudentEntry(student)
+            student_obj = getattr(students_folder,student.id)
+            for k in toexport.keys()[1:]:
+                try:
+                    object = getattr(student_obj,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['state'],d['lga'] = formatLGA(d['lga'],voc = self.portal_vocabularies.local_gov_areas)
+            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  total written %(total)d" % vars())
+                end_chunk = DateTime.DateTime().timeTime()
+                duration = end_chunk-start_chunk
+                per_record = duration/anz
+                till_now = end_chunk - start
+                avarage_per_record = till_now/total
+                estimated_end = DateTime.DateTime(start + avarage_per_record * nr2export)
+                estimated_end = estimated_end.strftime("%H:%M:%S")
+                logger.info('%(duration)4.1f, %(per_record)4.3f,end %(estimated_end)s' % vars())
+                start_chunk = DateTime.DateTime().timeTime()
+                lines = []
+        end = DateTime.DateTime().timeTime()
+        logger.info('total time %6.2f m' % ((end-start)/60))
+        filename, extension = os.path.splitext(export_file)
+        from subprocess import call
+        msg = "wrote %(total)d records to %(export_file)s" % vars()
+        try:
+            retcode = call('gzip %s' % (export_file),shell=True)
+            if retcode == 0:
+                msg = "wrote %(total)d records to %(export_file)s.gz" % vars()
+        except OSError, e:
+            retcode = -99
+            logger.info("zip failed with %s" % e)
+        logger.info(msg)
+        args = {'portal_status_message': msg}
+        url = self.REQUEST.get('URL2')
+        return self.REQUEST.RESPONSE.redirect(url)
+    ###)
 
     security.declareProtected(ModifyPortalContent,"dumpStudentsCatalog")###(
