Index: WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- WAeUP_SRP/trunk/WAeUPTables.py	(revision 2188)
+++ WAeUP_SRP/trunk/WAeUPTables.py	(revision 2189)
@@ -90,4 +90,16 @@
 ###)
 
+    def record2dict(self,fields,record):
+        d = {}
+        for key in fields:
+            v = getattr(record, key, None)
+            if v:
+                if key == 'lga':
+                    v = self.portal_vocabularies.local_gov_areas.get(v)
+                d[key] = v
+            else:
+                d[key] = ''
+        return d
+    
     def addRecord(self, **data): ###(
         # The uid is the same as "bed".
@@ -166,4 +178,77 @@
 
 ###)
+
+    security.declareProtected(ModifyPortalContent,"dumpAll")###(
+    def dumpAll(self):
+        """dump all data in the table to a csv"""
+        member = self.portal_membership.getAuthenticatedMember()
+        logger = logging.getLogger('WAeUPTables.dump_%s' % self.__name__)
+        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
+        export_file = "%s/export/%s_%s.csv" % (i_home,self.__name__,current,)
+        print export_file
+        res_list = []
+        lines = []
+        if hasattr(self,"export_keys"):
+            fields = self.export_keys
+        else:
+            fields = []
+            for f in self.schema():
+                fields.append(f)
+        headline = ','.join(fields)
+        #open(export_file,"a").write(headline +'\n')
+        out = open(export_file,"wb")
+        out.write(headline +'\n')
+        out.close()
+        out = open(export_file,"a")
+        csv_writer = csv.DictWriter(out,fields,)
+        format = '"%(' + ')s","%('.join(fields) + ')s"'
+        records = self()
+        nr2export = len(records)
+        logger.info('%s starts dumping, %s records to export' % (member,nr2export))
+        chunk = 2000
+        total = 0
+        start = DateTime.DateTime().timeTime()
+        start_chunk = DateTime.DateTime().timeTime()
+        for record in records:
+            not_all = False
+            d = self.record2dict(fields,record)
+            #d['state'],d['lga'] = formatLGA(d['lga'],voc = self.portal_vocabularies.local_gov_areas)
+            #lines.append(format % d)
+            lines.append(d)
+            total += 1
+            if total and not total % chunk or total == len(records):
+                #open(export_file,"a").write('\n'.join(lines) +'\n')
+                csv_writer.writerows(lines)
+                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))
+        import os
+        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('URL1') + '?' + urlencode(args)
+        url = self.REQUEST.get('URL2')
+        return self.REQUEST.RESPONSE.redirect(url)
+    ###)
 
     security.declarePrivate("_import_old") ###(
@@ -473,9 +558,42 @@
     key = "reg_no"
     security = ClassSecurityInfo()
-
+    export_keys = (
+                   "reg_no",
+                   "status",
+                   "lastname",
+                   "sex",
+                   "date_of_birth",
+                   "lga",
+                   "email",
+                   "phone",
+                   "passport",
+                   "entry_mode",
+                   "pin",
+                   "screening_type",
+                   "registration_date",
+                   "testdate",
+                   "application_date",
+                   "screening_date",
+                   "faculty",
+                   "department",
+                   "course1",
+                   "course2",
+                   "course3",
+                   "eng_score",
+                   "subj1",
+                   "subj1score",
+                   "subj2",
+                   "subj2score",
+                   "subj3",
+                   "subj3score",
+                   "aggregate",
+                   "course_admitted",
+                   )
     def __init__(self,name=None):
         if name ==  None:
             name = self.name
         WAeUPTable.__init__(self, name)
+
+    
 
     security.declareProtected(ModifyPortalContent,"new_importCSV")###(
