Changeset 8452 for main/waeup.kofa/trunk/src/waeup/kofa/students
- Timestamp:
- 15 May 2012, 15:24:11 (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/student.py
r8448 r8452 189 189 Returns the name of folder in which files for a particular student 190 190 should be stored. This is a relative path, relative to any general 191 students folder. 192 193 For instance ``K1000000`` will give ``01000/K1000000`` and 194 ``KM123456`` will result in ``00123/KM123456``. 191 students folder with 5 zero-padded digits (except when student_id 192 is overlong). 193 194 We normally map 1,000 different student ids into one single 195 path. For instance ``K1000000`` will give ``01000/K1000000``, 196 ``K1234567`` will give ``0123/K1234567`` and ``K12345678`` will 197 result in ``1234/K12345678``. 198 199 For lower numbers < 10**6 we return the same path for up to 10,000 200 student_ids. So for instance ``KM123456`` will result in 201 ``00120/KM123456`` (there will be no path starting with 202 ``00123``). 203 204 Works also with overlong number: here the leading zeros will be 205 missing but ``K123456789`` will give reliably 206 ``12345/K123456789`` as expected. 195 207 """ 196 208 # remove all non numeric characters and turn this into an int. 197 209 num = int(RE_STUDID_NON_NUM.sub('', student_id)) 198 # store max. of 1000 studs per folder 199 folder_name = u'%05d' % (num / 1000) 210 if num < 10**6: 211 # store max. of 10000 studs per folder and correct num for 5 digits 212 num = num / 10000 * 10 213 else: 214 # store max. of 1000 studs per folder 215 num = num / 1000 216 # format folder name to have 5 zero-padded digits 217 folder_name = u'%05d' % num 200 218 folder_name = os.path.join(folder_name, student_id) 201 219 return folder_name -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py
r8448 r8452 49 49 path_from_studid('K1000000'), u'01000/K1000000') 50 50 self.assertEqual( 51 path_from_studid('KM123456'), u'00123/KM123456') 51 path_from_studid('K1234567'), u'01234/K1234567') 52 self.assertEqual( 53 path_from_studid('K12345678'), u'12345/K12345678') 54 # The algorithm works also for overlong numbers, just to be 55 # sure. 56 self.assertEqual( 57 path_from_studid('K123456789'), u'123456/K123456789') 58 # low numbers (< 10**6) are treated special: they get max. of 59 # 10,000 entries. That's mainly because of old students 60 # migrated into our portal. 61 self.assertEqual( 62 path_from_studid('KM123456'), u'00120/KM123456') 52 63 return 53 64
Note: See TracChangeset for help on using the changeset viewer.