Changeset 8410 for main/waeup.kofa/trunk/src/waeup/kofa/students
- Timestamp:
- 10 May 2012, 16:37:07 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/container.py
r7811 r8410 20 20 """ 21 21 import grok 22 from thread import allocate_lock 23 from transaction import commit 24 from zope.component import getUtility 22 25 from waeup.kofa.students.interfaces import ( 23 IStudentsContainer, IStudent) 26 IStudentsContainer, IStudent, IStudentsUtils) 27 from waeup.kofa.utils.helpers import attrs_to_fields 24 28 from waeup.kofa.utils.logger import Logger 29 30 lock = allocate_lock() # a lock object to lock threads. 25 31 26 32 class StudentsContainer(grok.Container, Logger): … … 30 36 31 37 grok.implements(IStudentsContainer) 38 39 _curr_stud_id = 10 ** 6 40 41 @property 42 def unique_student_id(self): 43 """A unique student id. 44 45 The student id returned is guaranteed to be unique. It 46 consists of some prefix (normally a single letter) followed by 47 a number with at least 7 digits. 48 49 Once a student id was issued, it won't be issued again. 50 51 Obtaining a student id is currently not thread-safe but can be 52 made easily by enabling commented lines. 53 """ 54 prefix = getUtility(IStudentsUtils).STUDENT_ID_PREFIX 55 56 # lock.acquire() # lock data 57 new_id = u'%s%s' % (prefix, self._curr_stud_id) 58 self._curr_stud_id += 1 59 # self._p_changed = True 60 # commit() 61 # lock.release() # end of lock 62 return new_id 32 63 33 64 def archive(self, id=None): … … 55 86 ob_class, target, comment)) 56 87 return 88 89 StudentsContainer = attrs_to_fields(StudentsContainer) -
main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
r8307 r8410 95 95 return tag1 + u'%s</font>' % text 96 96 97 def generate_student_id(students,letter): 98 if letter == '?': 99 letter= r().choice('ABCDEFGHKLMNPQRSTUVWXY') 100 sid = u"%c%d" % (letter,r().randint(99999,1000000)) 101 while sid in students.keys(): 102 sid = u"%c%d" % (letter,r().randint(99999,1000000)) 103 return sid 97 def generate_student_id(students, letter='?'): 98 students = grok.getSite()['students'] 99 new_id = students.unique_student_id 100 return new_id 104 101 105 102 def set_up_widgets(view, ignore_request=False): … … 393 390 SEPARATORS_DICT = { 394 391 } 392 393 #: A prefix used when generating new student ids. Each student id will 394 #: start with this string. The default is 'K' for ``Kofa``. 395 STUDENT_ID_PREFIX = u'K'
Note: See TracChangeset for help on using the changeset viewer.