Changeset 8448 for main/waeup.kofa/trunk/src
- Timestamp:
- 14 May 2012, 14:29:02 (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
r8411 r8448 20 20 """ 21 21 import os 22 import re 22 23 import shutil 23 24 import grok … … 40 41 from waeup.kofa.students.utils import generate_student_id 41 42 from waeup.kofa.utils.helpers import attrs_to_fields, now, copy_filesystem_tree 43 44 RE_STUDID_NON_NUM = re.compile('[^\d]+') 42 45 43 46 class Student(grok.Container): … … 179 182 return 180 183 184 def path_from_studid(student_id): 185 """Convert a student_id into a predictable relative folder path. 186 187 Used for storing files. 188 189 Returns the name of folder in which files for a particular student 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``. 195 """ 196 # remove all non numeric characters and turn this into an int. 197 num = int(RE_STUDID_NON_NUM.sub('', student_id)) 198 # store max. of 1000 studs per folder 199 folder_name = u'%05d' % (num / 1000) 200 folder_name = os.path.join(folder_name, student_id) 201 return folder_name 202 181 203 def move_student_files(student, del_dir): 182 204 """Move files belonging to `student` to `del_dir`. … … 192 214 193 215 src = getUtility(IExtFileStore).root 194 src = os.path.join(src, 'students', stud_id[0], stud_id) 195 196 dst = os.path.join(del_dir, 'media', 'students', stud_id[0], stud_id) 216 src = os.path.join(src, 'students', path_from_studid(stud_id)) 217 218 dst = os.path.join( 219 del_dir, 'media', 'students', path_from_studid(stud_id)) 197 220 198 221 if not os.path.isdir(src): … … 336 359 basename, ext = os.path.splitext(attr) 337 360 stud_id = self.context.student_id 338 marked_filename = '__%s__%s/%s /%s_%s%s' % (339 STUDENT_FILE_STORE_NAME, stud_id[0], stud_id, basename,361 marked_filename = '__%s__%s/%s_%s%s' % ( 362 STUDENT_FILE_STORE_NAME, path_from_studid(stud_id), basename, 340 363 stud_id, ext) 341 364 return marked_filename -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py
r8403 r8448 20 20 import os 21 21 import re 22 import unittest 22 23 from cStringIO import StringIO 23 24 from datetime import tzinfo … … 28 29 from waeup.kofa.students.export import EXPORTER_NAMES 29 30 from waeup.kofa.students.student import ( 30 Student, StudentFactory, handle_student_removed )31 Student, StudentFactory, handle_student_removed, path_from_studid) 31 32 from waeup.kofa.students.studycourse import StudentStudyCourse 32 33 from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket … … 39 40 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 40 41 from waeup.kofa.university.department import Department 42 43 class HelperTests(unittest.TestCase): 44 # Tests for helper functions in student module. 45 46 def test_path_from_studid(self): 47 # make sure we get predictable paths from student ids. 48 self.assertEqual( 49 path_from_studid('K1000000'), u'01000/K1000000') 50 self.assertEqual( 51 path_from_studid('KM123456'), u'00123/KM123456') 52 return 41 53 42 54 class StudentTest(FunctionalTestCase): … … 121 133 del_dir = self.app['datacenter'].deleted_path 122 134 del_img_path = os.path.join( 123 del_dir, 'media', 'students', ' A', 'A111111',135 del_dir, 'media', 'students', '00111', 'A111111', 124 136 'passport_A111111.jpg') 125 137
Note: See TracChangeset for help on using the changeset viewer.