- Timestamp:
- 24 Nov 2011, 11:31:04 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r7184 r7186 37 37 ISessionConfiguration, ISessionConfigurationAdd, academic_sessions_vocab, 38 38 IPasswordValidator) 39 from waeup.sirp.permissions import get_users_with_local_roles, get AllRoles39 from waeup.sirp.permissions import get_users_with_local_roles, get_all_roles 40 40 from waeup.sirp.university.catalog import search 41 41 from waeup.sirp.university.vocabularies import course_levels … … 266 266 site_url = self.url(grok.getSite()) 267 267 for local_role in local_roles.keys(): 268 role_title = dict(get AllRoles())[local_role].title268 role_title = dict(get_all_roles())[local_role].title 269 269 objects_string = '' 270 270 for object in local_roles[local_role]: … … 279 279 site_roles_string = '' 280 280 for site_role in site_roles: 281 role_title = dict(get AllRoles())[site_role].title281 role_title = dict(get_all_roles())[site_role].title 282 282 site_roles_string += '%s <br />' % role_title 283 283 return site_roles_string … … 385 385 local_roles_userfriendly = {} 386 386 for local_role in local_roles: 387 role_title = dict(get AllRoles())[local_role].title387 role_title = dict(get_all_roles())[local_role].title 388 388 local_roles_userfriendly[role_title] = local_roles[local_role] 389 389 return local_roles_userfriendly … … 394 394 site_roles_userfriendly = [] 395 395 for site_role in site_roles: 396 role_title = dict(get AllRoles())[site_role].title396 role_title = dict(get_all_roles())[site_role].title 397 397 site_roles_userfriendly.append(role_title) 398 398 return site_roles_userfriendly -
main/waeup.sirp/trunk/src/waeup/sirp/datacenter.py
r7137 r7186 12 12 from waeup.sirp.interfaces import (IDataCenter, IDataCenterFile, 13 13 IDataCenterStorageMovedEvent) 14 from waeup.sirp.utils.helpers import copy FileSystemTree14 from waeup.sirp.utils.helpers import copy_filesystem_tree 15 15 from waeup.sirp.utils.logger import Logger 16 16 … … 80 80 if move is True: 81 81 82 not_copied = copy FileSystemTree(self.storage, path,82 not_copied = copy_filesystem_tree(self.storage, path, 83 83 overwrite=overwrite) 84 84 self.storage = path -
main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py
r7178 r7186 81 81 def getValues(self): 82 82 # late import: in interfaces we should not import local modules 83 from waeup.sirp.permissions import get WAeUPRoleNames84 return get WAeUPRoleNames()83 from waeup.sirp.permissions import get_waeup_role_names 84 return get_waeup_role_names() 85 85 86 86 def getTitle(self, value): 87 87 # late import: in interfaces we should not import local modules 88 from waeup.sirp.permissions import get AllRoles89 roles = dict(get AllRoles())88 from waeup.sirp.permissions import get_all_roles 89 roles = dict(get_all_roles()) 90 90 if value in roles.keys(): 91 91 title = roles[value].title -
main/waeup.sirp/trunk/src/waeup/sirp/permissions.py
r7185 r7186 97 97 'waeup.viewHostels', 'waeup.manageHostels') 98 98 99 def get AllRoles():99 def get_all_roles(): 100 100 """Return a list of tuples ``<ROLE-NAME>, <ROLE>``. 101 101 """ 102 102 return getUtilitiesFor(IRole) 103 103 104 def get WAeUPRoles(also_local=False):104 def get_waeup_roles(also_local=False): 105 105 """Get all WAeUP roles. 106 106 … … 114 114 Returns a generator of the found roles. 115 115 """ 116 for name, item in get AllRoles():116 for name, item in get_all_roles(): 117 117 if not name.startswith('waeup.'): 118 118 # Ignore non-WAeUP roles... … … 123 123 yield item 124 124 125 def get WAeUPRoleNames():125 def get_waeup_role_names(): 126 126 """Get the ids of all WAeUP roles. 127 127 128 See :func:`get WAeUPRoles` for what a 'WAeUPRole' is.128 See :func:`get_waeup_roles` for what a 'WAeUPRole' is. 129 129 130 130 This function returns a sorted list of WAeUP role names. 131 131 """ 132 return sorted([x.id for x in get WAeUPRoles()])132 return sorted([x.id for x in get_waeup_roles()]) 133 133 134 134 class LocalRolesAssignable(grok.Adapter): … … 160 160 self.context = context 161 161 role_ids = getattr(context, 'local_roles', self._roles) 162 self._roles = [(name, role) for name, role in get AllRoles()162 self._roles = [(name, role) for name, role in get_all_roles() 163 163 if name in role_ids] 164 164 return … … 191 191 user = grok.getSite()['users'].get(user_name,None) 192 192 user_title = getattr(user, 'description', user_name) 193 local_role_title = dict(get AllRoles())[local_role].title193 local_role_title = dict(get_all_roles())[local_role].title 194 194 yield dict(user_name = user_name, 195 195 user_title = user_title, -
main/waeup.sirp/trunk/src/waeup/sirp/permissions.txt
r7185 r7186 13 13 roles. 14 14 15 :func:`get AllRoles`16 ------------------- 15 :func:`get_all_roles` 16 --------------------- 17 17 18 18 Gives us all roles defined in a WAeUP SIRP portal. We get tuples of … … 24 24 with the ZCA (a string) and ``<ROLE>`` is the real role object. 25 25 26 >>> from waeup.sirp.permissions import get AllRoles27 >>> get AllRoles()26 >>> from waeup.sirp.permissions import get_all_roles 27 >>> get_all_roles() 28 28 <generator object...at 0x...> 29 29 30 >>> sorted(list(get AllRoles()))30 >>> sorted(list(get_all_roles())) 31 31 [(u'waeup.ACManager', <waeup.sirp.permissions.ACManager object at 0x...] 32 32 33 :func:`get WAeUPRoles`34 --------------------- 33 :func:`get_waeup_roles` 34 ----------------------- 35 35 36 36 Gives us all roles, except the WAeUP specific roles. We can get a list 37 37 with or without local roles: 38 38 39 >>> from waeup.sirp.permissions import get WAeUPRoles40 >>> len(list(get WAeUPRoles()))39 >>> from waeup.sirp.permissions import get_waeup_roles 40 >>> len(list(get_waeup_roles())) 41 41 10 42 42 43 >>> len(list(get WAeUPRoles(also_local=True)))43 >>> len(list(get_waeup_roles(also_local=True))) 44 44 16 45 45 46 46 47 :func:`get RoleNames`48 -------------------- 47 :func:`get_waeup_role_names` 48 ---------------------------- 49 49 50 50 We can get all role names defined in a WAeUP portal (except 'local' 51 51 roles that are meant not to be assigned globally): 52 52 53 >>> from waeup.sirp.permissions import get WAeUPRoleNames54 >>> list(get WAeUPRoleNames())53 >>> from waeup.sirp.permissions import get_waeup_role_names 54 >>> list(get_waeup_role_names()) 55 55 [u'waeup.ACManager', u'waeup.AcademicsOfficer', 56 56 u'waeup.AccommodationOfficer', u'waeup.Applicant', -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7184 r7186 737 737 self.request) 738 738 students_utils = getUtility(IStudentsUtils) 739 return students_utils.render _pdf(739 return students_utils.renderPDF( 740 740 self,'Course Registration', 'course_registration.pdf', 741 741 self.context.getStudent, studentview) … … 1022 1022 return 1023 1023 students_utils = getUtility(IStudentsUtils) 1024 pay_details = students_utils.get _payment_details(1024 pay_details = students_utils.getPaymentDetails( 1025 1025 p_category,student) 1026 1026 if pay_details['error']: … … 1177 1177 self.request) 1178 1178 students_utils = getUtility(IStudentsUtils) 1179 return students_utils.render _pdf(self,'Payment', 'payment_receipt.pdf',1179 return students_utils.renderPDF(self,'Payment', 'payment_receipt.pdf', 1180 1180 self.context.getStudent, studentview) 1181 1181 … … 1289 1289 student = self.context.getStudent() 1290 1290 students_utils = getUtility(IStudentsUtils) 1291 acc_details = students_utils.get _accommodation_details(student)1291 acc_details = students_utils.getAccommodationDetails(student) 1292 1292 if not student.state in acc_details['allowed_states']: 1293 1293 self.flash("You are in the wrong registration state.") … … 1327 1327 if available_beds: 1328 1328 students_utils = getUtility(IStudentsUtils) 1329 bed = students_utils.select _bed(available_beds)1329 bed = students_utils.selectBed(available_beds) 1330 1330 bed.bookBed(student.student_id) 1331 1331 else: … … 1409 1409 self.request) 1410 1410 students_utils = getUtility(IStudentsUtils) 1411 return students_utils.render _pdf(1411 return students_utils.renderPDF( 1412 1412 self,'Bed Allocation', 'bed_allocation.pdf', 1413 1413 self.context.getStudent, studentview) … … 1434 1434 student = self.context.getStudent() 1435 1435 students_utils = getUtility(IStudentsUtils) 1436 acc_details = students_utils.get _accommodation_details(student)1436 acc_details = students_utils.getAccommodationDetails(student) 1437 1437 if self.context.bed != None and \ 1438 1438 'reserved' in self.context.bed.bed_type: … … 1462 1462 if available_beds: 1463 1463 students_utils = getUtility(IStudentsUtils) 1464 new_bed = students_utils.select _bed(available_beds)1464 new_bed = students_utils.selectBed(available_beds) 1465 1465 new_bed.bookBed(student.student_id) 1466 1466 else: … … 1719 1719 1720 1720 @grok.action('Save and request clearance') 1721 def request clearance(self, **data):1721 def requestClearance(self, **data): 1722 1722 self.applyData(self.context, **data) 1723 1723 self.context._p_changed = True … … 1964 1964 1965 1965 @grok.action('Register course list') 1966 def register_courses(self, **data):1966 def RegisterCourses(self, **data): 1967 1967 state = IWorkflowState(self.context.getStudent()).getState() 1968 1968 IWorkflowInfo(self.context.getStudent()).fireTransition('register_courses') -
main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py
r7150 r7186 30 30 31 31 """ 32 def get _payment_details(category, student):32 def getPaymentDetails(category, student): 33 33 """Get the payment dates of a student for the payment category 34 34 specified. … … 36 36 """ 37 37 38 def get _accommodation_details(student):38 def getAccommodation_details(student): 39 39 """Determine the accommodation dates of a student. 40 40 41 41 """ 42 42 43 def select _bed(available_beds):43 def selectBed(available_beds): 44 44 """Select a bed from a list of available beds. 45 45 … … 48 48 """ 49 49 50 def render _pdf(view, subject='', filename='slip.pdf',):50 def renderPDF(view, subject='', filename='slip.pdf',): 51 51 """Render pdf slips for various pages. 52 52 -
main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py
r7150 r7186 35 35 return 36 36 37 def set UpWidgets(view, ignore_request=False):37 def set_up_widgets(view, ignore_request=False): 38 38 view.adapters = {} 39 39 view.widgets = setUpEditWidgets( … … 44 44 45 45 def render_student_data(student, studentview): 46 set UpWidgets(studentview, ignore_request=True)46 set_up_widgets(studentview, ignore_request=True) 47 47 data = [] 48 48 style = getSampleStyleSheet() … … 63 63 grok.implements(IStudentsUtils) 64 64 65 def get _payment_details(self,category, student):65 def getPaymentDetails(self,category, student): 66 66 d = {} 67 67 d['p_item'] = u'' … … 85 85 d['amount'] = academic_session.clearance_fee 86 86 elif category == 'bed_allocation': 87 d['p_item'] = self.get _accommodation_details(student)['bt']87 d['p_item'] = self.getAccommodationDetails(student)['bt'] 88 88 d['amount'] = academic_session.booking_fee 89 89 return d 90 90 91 def get _accommodation_details(self, student):91 def getAccommodationDetails(self, student): 92 92 d = {} 93 93 d['error'] = u'' … … 117 117 # In the standard configuration we select the first bed found, 118 118 # but can also randomize the selection if we like. 119 def select _bed(self, available_beds):119 def selectBed(self, available_beds): 120 120 return available_beds[0] 121 121 122 def render _pdf(self, view, subject='', filename='slip.pdf',122 def renderPDF(self, view, subject='', filename='slip.pdf', 123 123 student=None, studentview=None): 124 124 # (0,0),(-1,-1) = whole table … … 153 153 story.append(studenttable) 154 154 story.append(Spacer(1, 18)) 155 set UpWidgets(view)155 set_up_widgets(view) 156 156 data = [] 157 157 for widget in view.widgets: -
main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.py
r7175 r7186 19 19 BUFSIZE = 8 * 1024 20 20 21 def remove FileOrDirectory(filepath):21 def remove_file_or_directory(filepath): 22 22 """Remove a file or directory. 23 23 … … 35 35 return 36 36 37 def copy FileSystemTree(src, dst, overwrite=False, del_old=False):37 def copy_filesystem_tree(src, dst, overwrite=False, del_old=False): 38 38 """Copy contents of directory src to directory dst. 39 39 … … 68 68 if os.path.exists(itemdst): 69 69 if overwrite is True: 70 remove FileOrDirectory(itemdst)70 remove_file_or_directory(itemdst) 71 71 else: 72 72 not_copied.append(item) … … 78 78 shutil.copy2(itemsrc, itemdst) 79 79 if del_old: 80 remove FileOrDirectory(itemsrc)80 remove_file_or_directory(itemsrc) 81 81 return not_copied 82 82 83 83 84 def get InnerHTMLPart(html_code):84 def get_inner_HTML_part(html_code): 85 85 """Return the 'inner' part of a complete HTML snippet. 86 86 … … 95 95 96 96 >>> doc = '<html><form>My Form</form>Outside the form</html>' 97 >>> get InnerHTMLPart(doc)97 >>> get_inner_HTML_part(doc) 98 98 '<form>My Form</form>' 99 99 … … 101 101 102 102 >>> doc = '<html><body>My Body</body>Trailing Trash</html>' 103 >>> get InnerHTMLPart(doc)103 >>> get_inner_HTML_part(doc) 104 104 'My Body' 105 105 … … 107 107 108 108 >>> doc = '<html>without body nor form</html>' 109 >>> get InnerHTMLPart(doc)109 >>> get_inner_HTML_part(doc) 110 110 '<html>without body nor form</html>' 111 111 … … 309 309 if warning_msgs == '': 310 310 warning_msgs = None 311 result = get InnerHTMLPart(fulldoc).strip()311 result = get_inner_HTML_part(fulldoc).strip() 312 312 if not isinstance(result, unicode): 313 313 result = result.decode('utf-8') -
main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.txt
r5140 r7186 8 8 .. :doctest: 9 9 10 :func:`remove FileOrDirectory`11 ============================= 12 13 .. function:: remove FileOrDirectory(path)10 :func:`remove_file_or_directory` 11 ================================ 12 13 .. function:: remove_file_or_directory(path) 14 14 15 15 Removes a file or directory given by a path. We can remove files: 16 16 17 17 >>> import os 18 >>> from waeup.sirp.utils.helpers import remove FileOrDirectory18 >>> from waeup.sirp.utils.helpers import remove_file_or_directory 19 19 >>> open('blah', 'wb').write('nonsense') 20 20 >>> 'blah' in os.listdir('.') 21 21 True 22 22 23 >>> remove FileOrDirectory('blah')23 >>> remove_file_or_directory('blah') 24 24 >>> 'blah' in os.listdir('.') 25 25 False … … 31 31 True 32 32 33 >>> remove FileOrDirectory('blah')33 >>> remove_file_or_directory('blah') 34 34 >>> 'blah' in os.listdir('.') 35 35 False 36 36 37 37 38 :func:`copy FileSystemTree`39 ========================== 40 41 .. function:: c opyFileSystemTree(src_path, dst_path[, overwrite=False[, del_old=False]])38 :func:`copy_filesystem_tree` 39 ============================ 40 41 .. function:: ccopy_filesystem_tree(src_path, dst_path[, overwrite=False[, del_old=False]]) 42 42 43 43 Copies the contents of an (existing) directory to another … … 67 67 >>> open(os.path.join('src', 'blah'), 'wb').write('nonsense') 68 68 69 >>> from waeup.sirp.utils.helpers import copy FileSystemTree70 >>> result = copy FileSystemTree('src', 'dst')69 >>> from waeup.sirp.utils.helpers import copy_filesystem_tree 70 >>> result = copy_filesystem_tree('src', 'dst') 71 71 72 72 As a result we get a list of non-copied files: … … 83 83 84 84 >>> open(os.path.join('src', '.blah'), 'wb').write('nonsense') 85 >>> result = copy FileSystemTree('src', 'dst')85 >>> result = copy_filesystem_tree('src', 'dst') 86 86 >>> '.blah' in os.listdir('dst') 87 87 False … … 100 100 101 101 >>> open(os.path.join('src', 'blah'), 'wb').write('newnonsense') 102 >>> result = copy FileSystemTree('src', 'dst')102 >>> result = copy_filesystem_tree('src', 'dst') 103 103 >>> open(os.path.join('dst', 'blah'), 'rb').read() 104 104 'nonsense' … … 113 113 overwritten: 114 114 115 >>> result = copy FileSystemTree('src', 'dst', overwrite=True)115 >>> result = copy_filesystem_tree('src', 'dst', overwrite=True) 116 116 >>> open(os.path.join('dst', 'blah'), 'rb').read() 117 117 'newnonsense' … … 129 129 ... 'dst', 'mydir', 'blah'), 'wb').write('dstblah') 130 130 131 >>> result = copy FileSystemTree('src', 'dst', overwrite=True)131 >>> result = copy_filesystem_tree('src', 'dst', overwrite=True) 132 132 >>> open(os.path.join('dst', 'mydir', 'blah'), 'rb').read() 133 133 'srcblah' … … 140 140 removed from the src dir. Default is `False`. 141 141 142 >>> result = copy FileSystemTree('src', 'dst', overwrite=True,142 >>> result = copy_filesystem_tree('src', 'dst', overwrite=True, 143 143 ... del_old=True) 144 144 >>> os.listdir('src') … … 151 151 Clean up: 152 152 153 >>> remove FileOrDirectory('src')154 >>> remove FileOrDirectory('dst')155 156 157 :func:`get InnerHTMLPart()`158 ========================== 159 160 .. function:: get InnerHTMLPart(html_code)153 >>> remove_file_or_directory('src') 154 >>> remove_file_or_directory('dst') 155 156 157 :func:`get_inner_HTML_part()` 158 ============================= 159 160 .. function:: get_inner_HTML_part(html_code) 161 161 162 162 Get the 'inner' part out of a piece of HTML code. … … 172 172 returned with all preceeding/following stuff stripped: 173 173 174 >>> from waeup.sirp.utils.helpers import get InnerHTMLPart175 >>> print get InnerHTMLPart("""<html>174 >>> from waeup.sirp.utils.helpers import get_inner_HTML_part 175 >>> print get_inner_HTML_part("""<html> 176 176 ... <head> 177 177 ... </head> … … 198 198 If there is no ``<form>`` part, try to find any ``<body>`` part: 199 199 200 >>> print get InnerHTMLPart("""<html>200 >>> print get_inner_HTML_part("""<html> 201 201 ... <head> 202 202 ... </head> … … 213 213 If there is also no ``<body>`` tag, we return the input as-is: 214 214 215 >>> print get InnerHTMLPart("""<div>215 >>> print get_inner_HTML_part("""<div> 216 216 ... <div>Some content</div> 217 217 ... </div> -
main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_helpers.py
r7137 r7186 54 54 55 55 def test_handle_not_existing_path(self): 56 result = helpers.remove FileOrDirectory(self.non_file)56 result = helpers.remove_file_or_directory(self.non_file) 57 57 self.assertTrue(result is None) 58 58 return 59 59 60 60 def test_handle_dir(self): 61 helpers.remove FileOrDirectory(self.dirpath)61 helpers.remove_file_or_directory(self.dirpath) 62 62 self.assertFalse( 63 63 os.path.exists(self.dirpath) … … 66 66 67 67 def test_handle_file(self): 68 helpers.remove FileOrDirectory(self.filepath)68 helpers.remove_file_or_directory(self.filepath) 69 69 self.assertFalse( 70 70 os.path.exists(self.filepath) … … 73 73 74 74 class CopyFileSystemTreeTestCase(unittest.TestCase): 75 # Test edge cases of copy FileSystemTree().75 # Test edge cases of copy_filesystem_tree(). 76 76 # 77 77 # This is a typical case of tests not written as doctest as it is … … 94 94 95 95 def test_source_and_dst_existing(self): 96 helpers.copy FileSystemTree(self.existing_src, self.existing_dst)96 helpers.copy_filesystem_tree(self.existing_src, self.existing_dst) 97 97 self.assertTrue( 98 98 os.path.exists( … … 105 105 self.assertRaises( 106 106 ValueError, 107 helpers.copy FileSystemTree,107 helpers.copy_filesystem_tree, 108 108 self.not_existing_dir, 109 109 self.existing_dst … … 114 114 self.assertRaises( 115 115 ValueError, 116 helpers.copy FileSystemTree,116 helpers.copy_filesystem_tree, 117 117 self.existing_src, 118 118 self.not_existing_dir … … 123 123 self.assertRaises( 124 124 ValueError, 125 helpers.copy FileSystemTree,125 helpers.copy_filesystem_tree, 126 126 self.filepath, 127 127 self.existing_dst … … 132 132 self.assertRaises( 133 133 ValueError, 134 helpers.copy FileSystemTree,134 helpers.copy_filesystem_tree, 135 135 self.existing_src, 136 136 self.filepath
Note: See TracChangeset for help on using the changeset viewer.