Changeset 6749 for main/waeup.sirp


Ignore:
Timestamp:
13 Sep 2011, 15:46:34 (13 years ago)
Author:
Henrik Bettermann
Message:

Avoid overkill during batch creation of students.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/student.py

    r6704 r6749  
    1919import grok
    2020from grok import index
    21 from zope.component.interfaces import IFactory, ComponentLookupError
     21from zope.component.interfaces import IFactory
    2222from zope.interface import implementedBy
    2323from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
     
    4040        super(Student, self).__init__()
    4141        IWorkflowInfo(self).fireTransition('create')
    42         # The catalog doesn't exist in unit tests
     42        # The site doesn't exist in unit tests
    4343        try:
    44             self.student_id = generate_student_id('?')
    45         except ComponentLookupError:
     44            students = grok.getSite()['students']
     45            self.student_id = generate_student_id(students,'?')
     46        except TypeError:
    4647            self.student_id = u'Z654321'
    4748        self.password = None
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r6742 r6749  
    33
    44from random import SystemRandom as r
    5 from waeup.sirp.students.catalog import search
    65
    7 def generate_student_id(letter):
    8     # XXX: using catalog search here might be overkill?
     6def generate_student_id(students,letter):
    97    if letter == '?':
    108        letter= r().choice('ABCDEFGHKLMNPQRSTUVWXY')
    119    sid = u"%c%d" % (letter,r().randint(99999,1000000))
    12     while search(query=sid,searchtype='student_id'):
     10    while sid in students.keys():
    1311        sid = u"%c%d" % (letter,r().randint(99999,1000000))
    1412    return sid
Note: See TracChangeset for help on using the changeset viewer.