Index: WAeUP_SRP/base/WAeUPTables.py
===================================================================
--- WAeUP_SRP/base/WAeUPTables.py	(revision 2972)
+++ WAeUP_SRP/base/WAeUPTables.py	(revision 2973)
@@ -205,5 +205,4 @@
         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 = []
@@ -215,5 +214,4 @@
                 fields.append(f)
         headline = ','.join(fields)
-        #open(export_file,"a").write(headline +'\n')
         out = open(export_file,"wb")
         out.write(headline +'\n')
@@ -221,5 +219,4 @@
         out = open(export_file,"a")
         csv_writer = csv.DictWriter(out,fields,)
-        #format = '"%(' + ')s","%('.join(fields) + ')s"'
         records = self()
         nr2export = len(records)
@@ -235,5 +232,4 @@
             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)
@@ -513,4 +509,5 @@
 class PinTable(WAeUPTable): ###(
     from ZODB.POSException import ConflictError
+    security = ClassSecurityInfo()
     meta_type = 'WAeUP Pin Tool'
     name = "portal_pins"
@@ -521,4 +518,78 @@
             name = self.name
         WAeUPTable.__init__(self, name)
+
+    security.declareProtected(ModifyPortalContent,"dumpAll")###(
+    def dumpAll(self,include_unused=None):
+        """dump all data in the table to a csv"""
+        member = self.portal_membership.getAuthenticatedMember()
+        logger = logging.getLogger('PinTable.dumpAll')
+        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
+        export_file = "%s/export/%s_%s.csv" % (i_home,self.__name__,current,)
+        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)
+        out = open(export_file,"wb")
+        out.write(headline +'\n')
+        out.close()
+        out = open(export_file,"a")
+        csv_writer = csv.DictWriter(out,fields,)
+        if include_unused is not None and str(member) not in ('admin','joachim'):
+            logger.info('%s tries to dump pintable with unused pins' % (member))
+            return
+        if include_unused is not None:
+            records = self()
+        else:
+            records = self.evalAdvancedQuery(~Eq('student',''))
+        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)
+            lines.append(d)
+            total += 1
+            if total and not total % chunk or total == len(records):
+                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)
+    ###)
+
 
 
