Changeset 1878


Ignore:
Timestamp:
11 Jun 2007, 18:20:17 (17 years ago)
Author:
joachim
Message:

new speed improved version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Extensions/SetupDemoDB.py

    r1877 r1878  
    2222"""
    2323import random
     24import transaction
     25import logging
     26logger = logging.getLogger('Extension.removeStudents')
    2427
    2528def removeStudents(self):
     
    3235    stdir = context.portal_directories.students
    3336    students_catalog = context.students_catalog
     37    students = context.portal_url.getPortalObject().campus.students
     38    step = 10
    3439    all = students_catalog()
    35     sample = random.sample(all,len(all) - 1000)
    36     #import pdb;pdb.set_trace()
    37     for s in sample:
    38         if s.matric_no:
    39             context.deleteStudentByMatricNo(s.matric_no)
    40         elif s.jamb_reg_no:
    41             context.deleteStudentByRegNo(s.jamb_reg_no)
     40    todel = (len(all)/10)
     41    sample = random.sample(all,todel)
     42    logger.info("starting to delete %d students" % todel)
     43    for i in range(0,len(sample),step):
     44        ids = [b.id  for b in sample[i:i + step]]
     45        logger.info("deleting students %s" % (ids))
     46        for sid in ids:
     47            if hasattr(stdir, sid):
     48                stdir.deleteEntry(sid)
     49        try:
     50            students.manage_delObjects(ids)
     51        except:
     52            logger.info("erro deleting %s" % (ids))
     53        logger.info("deleted %d students %s" % (step,ids))
     54        transaction.commit()
Note: See TracChangeset for help on using the changeset viewer.