Changeset 8986 for main/waeup.kofa/trunk
- Timestamp:
- 12 Jul 2012, 20:32:29 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/university/export.py
r8301 r8986 19 19 """ 20 20 import grok 21 from zope.securitypolicy.interfaces import IPrincipalRoleMap 21 22 from waeup.kofa.interfaces import ICSVExporter 22 23 from waeup.kofa.interfaces import MessageFactory as _ … … 30 31 31 32 #: Fieldnames considered by this exporter 32 fields = ('code', 'title', 'title_prefix' )33 fields = ('code', 'title', 'title_prefix', 'users_with_local_roles') 33 34 34 35 #: The title under which this exporter will be displayed 35 36 title = _(u'Faculties') 37 38 def mangle_value(self, value, name, context=None): 39 """Hook for mangling values in derived classes 40 """ 41 if name == 'users_with_local_roles': 42 value = [] 43 role_map = IPrincipalRoleMap(context) 44 for local_role, user_name, setting in role_map.getPrincipalsAndRoles(): 45 value.append({'user_name':user_name,'local_role':local_role}) 46 return super(FacultyExporter, self).mangle_value( 47 value, name, context) 36 48 37 49 def export(self, faculties, filepath=None): … … 61 73 62 74 #: Fieldnames considered by this exporter 63 fields = ('code', 'faculty_code', 'title', 'title_prefix') 75 fields = ('code', 'faculty_code', 'title', 'title_prefix', 76 'users_with_local_roles') 64 77 65 78 #: The title under which this exporter will be displayed … … 97 110 #: Fieldnames considered by this exporter 98 111 fields = ('code', 'faculty_code', 'department_code', 'title', 'credits', 99 'passmark', 'semester' )112 'passmark', 'semester', 'users_with_local_roles') 100 113 101 114 #: The title under which this exporter will be displayed … … 105 118 """Hook for mangling values in derived classes 106 119 """ 107 if name == 'faculty_code': 120 if name == 'users_with_local_roles': 121 value = [] 122 role_map = IPrincipalRoleMap(context) 123 for local_role, user_name, setting in role_map.getPrincipalsAndRoles(): 124 value.append({'user_name':user_name,'local_role':local_role}) 125 elif name == 'faculty_code': 108 126 try: 109 127 value = context.__parent__.__parent__.__parent__.code … … 140 158 fields = ('code', 'faculty_code', 'department_code', 'title', 'study_mode', 141 159 'start_level', 'end_level', 'application_category', 142 'school_fee_1', 'school_fee_2' )160 'school_fee_1', 'school_fee_2', 'users_with_local_roles') 143 161 144 162 #: The title under which this exporter will be displayed -
main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_export.py
r8920 r8986 22 22 from zope.component import queryUtility 23 23 from zope.interface.verify import verifyObject, verifyClass 24 from zope.securitypolicy.interfaces import IPrincipalRoleManager 24 25 from waeup.kofa.interfaces import ICSVExporter 25 from waeup.kofa.testing import KofaUnitTestLayer 26 from waeup.kofa.testing import KofaUnitTestLayer, FunctionalLayer 26 27 from waeup.kofa.university import ( 27 28 FacultiesContainer, Faculty, Department, Course, Certificate, … … 34 35 class FacultyExporterTest(unittest.TestCase): 35 36 36 layer = KofaUnitTestLayer37 layer = FunctionalLayer 37 38 38 39 def setUp(self): … … 66 67 self.assertEqual( 67 68 result, 68 'code,title,title_prefix \r\n'69 'F1,Faculty of Cheese,faculty \r\n'69 'code,title,title_prefix,users_with_local_roles\r\n' 70 'F1,Faculty of Cheese,faculty,[]\r\n' 70 71 ) 71 72 return … … 78 79 self.assertEqual( 79 80 result, 80 'code,title,title_prefix \r\n'81 'F1,Faculty of Cheese,faculty \r\n'81 'code,title,title_prefix,users_with_local_roles\r\n' 82 'F1,Faculty of Cheese,faculty,[]\r\n' 82 83 ) 83 84 return … … 96 97 self.assertEqual( 97 98 result, 98 'code,title,title_prefix \r\n'99 'F1,Faculty of Cheese,faculty \r\n'100 'F2,Centre of Onion,centre \r\n'99 'code,title,title_prefix,users_with_local_roles\r\n' 100 'F1,Faculty of Cheese,faculty,[]\r\n' 101 'F2,Centre of Onion,centre,[]\r\n' 101 102 ) 102 103 return … … 114 115 self.assertEqual( 115 116 result, 116 'code,title,title_prefix \r\n'117 'F1,Faculty of Cheese,faculty \r\n'118 'F2,Centre of Onion,centre \r\n'117 'code,title,title_prefix,users_with_local_roles\r\n' 118 'F1,Faculty of Cheese,faculty,[]\r\n' 119 'F2,Centre of Onion,centre,[]\r\n' 119 120 ) 120 121 return … … 123 124 # Tests for DepartmentExporter 124 125 125 layer = KofaUnitTestLayer126 layer = FunctionalLayer 126 127 127 128 def setUp(self): … … 141 142 self.fac1.addDepartment(self.dept2) 142 143 self.fac2.addDepartment(self.dept3) 144 role_manager = IPrincipalRoleManager(self.dept1) 145 role_manager.assignRoleToPrincipal(u'bobsrole', u'bob') 143 146 return 144 147 … … 167 170 self.assertEqual( 168 171 result, 169 'code,faculty_code,title,title_prefix\r\n' 170 'D1,F1,Department of Cheddar,department\r\n' 172 'code,faculty_code,title,title_prefix,users_with_local_roles\r\n' 173 'D1,F1,Department of Cheddar,department,' 174 '"[{\'user_name\': u\'bob\', \'local_role\': u\'bobsrole\'}]"\r\n' 171 175 ) 172 176 return … … 178 182 self.assertEqual( 179 183 result, 180 'code,faculty_code,title,title_prefix\r\n' 181 'D1,F1,Department of Cheddar,department\r\n' 182 'D2,F1,Institue of Gouda,institute\r\n' 184 'code,faculty_code,title,title_prefix,users_with_local_roles\r\n' 185 'D1,F1,Department of Cheddar,department,' 186 '"[{\'user_name\': u\'bob\', \'local_role\': u\'bobsrole\'}]"\r\n' 187 'D2,F1,Institue of Gouda,institute,[]\r\n' 183 188 ) 184 189 return … … 191 196 self.assertEqual( 192 197 result, 193 'code,faculty_code,title,title_prefix\r\n' 194 'D1,F1,Department of Cheddar,department\r\n' 195 'D2,F1,Institue of Gouda,institute\r\n' 196 'D3,F2,Department of Rings,department\r\n' 198 'code,faculty_code,title,title_prefix,users_with_local_roles\r\n' 199 'D1,F1,Department of Cheddar,department,' 200 '"[{\'user_name\': u\'bob\', \'local_role\': u\'bobsrole\'}]"\r\n' 201 'D2,F1,Institue of Gouda,institute,[]\r\n' 202 'D3,F2,Department of Rings,department,[]\r\n' 197 203 ) 198 204 return … … 204 210 self.assertEqual( 205 211 result, 206 'code,faculty_code,title,title_prefix\r\n' 207 'D1,F1,Department of Cheddar,department\r\n' 208 'D2,F1,Institue of Gouda,institute\r\n' 209 'D3,F2,Department of Rings,department\r\n' 212 'code,faculty_code,title,title_prefix,users_with_local_roles\r\n' 213 'D1,F1,Department of Cheddar,department,' 214 '"[{\'user_name\': u\'bob\', \'local_role\': u\'bobsrole\'}]"\r\n' 215 'D2,F1,Institue of Gouda,institute,[]\r\n' 216 'D3,F2,Department of Rings,department,[]\r\n' 210 217 ) 211 218 return … … 214 221 # Tests for CourseExporter 215 222 216 layer = KofaUnitTestLayer223 layer = FunctionalLayer 217 224 218 225 def setUp(self): … … 260 267 self.assertEqual( 261 268 result, 262 'code,faculty_code,department_code,title,credits,passmark,semester\r\n' 263 'C1,F1,D1,Cheese Basics,0,40,1\r\n' 269 'code,faculty_code,department_code,title,credits,' 270 'passmark,semester,users_with_local_roles\r\n' 271 'C1,F1,D1,Cheese Basics,0,40,1,[]\r\n' 264 272 ) 265 273 return … … 271 279 self.assertEqual( 272 280 result, 273 'code,faculty_code,department_code,title,credits,passmark,semester\r\n' 274 'C1,F1,D1,Cheese Basics,0,40,1\r\n' 275 'C2,F1,D1,Advanced Cheese Making,0,40,1\r\n' 281 'code,faculty_code,department_code,title,credits,passmark,' 282 'semester,users_with_local_roles\r\n' 283 'C1,F1,D1,Cheese Basics,0,40,1,[]\r\n' 284 'C2,F1,D1,Advanced Cheese Making,0,40,1,[]\r\n' 276 285 ) 277 286 return … … 284 293 self.assertEqual( 285 294 result, 286 'code,faculty_code,department_code,title,credits,passmark,semester\r\n' 287 'C1,F1,D1,Cheese Basics,0,40,1\r\n' 288 'C2,F1,D1,Advanced Cheese Making,0,40,1\r\n' 289 'C3,F1,D2,Selling Cheese,0,40,1\r\n' 295 'code,faculty_code,department_code,title,credits,passmark,' 296 'semester,users_with_local_roles\r\n' 297 'C1,F1,D1,Cheese Basics,0,40,1,[]\r\n' 298 'C2,F1,D1,Advanced Cheese Making,0,40,1,[]\r\n' 299 'C3,F1,D2,Selling Cheese,0,40,1,[]\r\n' 290 300 ) 291 301 return … … 297 307 self.assertEqual( 298 308 result, 299 'code,faculty_code,department_code,title,credits,passmark,semester\r\n' 300 'C1,F1,D1,Cheese Basics,0,40,1\r\n' 301 'C2,F1,D1,Advanced Cheese Making,0,40,1\r\n' 302 'C3,F1,D2,Selling Cheese,0,40,1\r\n' 309 'code,faculty_code,department_code,title,credits,passmark,' 310 'semester,users_with_local_roles\r\n' 311 'C1,F1,D1,Cheese Basics,0,40,1,[]\r\n' 312 'C2,F1,D1,Advanced Cheese Making,0,40,1,[]\r\n' 313 'C3,F1,D2,Selling Cheese,0,40,1,[]\r\n' 303 314 ) 304 315 return … … 307 318 # Tests for CertificateExporter 308 319 309 layer = KofaUnitTestLayer320 layer = FunctionalLayer 310 321 311 322 def setUp(self): … … 339 350 self.dept1.certificates.addCertificate(self.cert2) 340 351 self.dept2.certificates.addCertificate(self.cert3) 352 role_manager = IPrincipalRoleManager(self.cert1) 353 role_manager.assignRoleToPrincipal(u'bobsrole', u'bob') 341 354 return 342 355 … … 365 378 self.assertEqual( 366 379 result, 367 'code,faculty_code,department_code,title,study_mode,start_level,end_level,application_category,school_fee_1,school_fee_2\r\n' 368 'CERT1,F1,D1,Master of Cheese,ct_ft,100,300,basic,,\r\n' 380 'code,faculty_code,department_code,title,study_mode,start_level,' 381 'end_level,application_category,school_fee_1,' 382 'school_fee_2,users_with_local_roles\r\n' 383 'CERT1,F1,D1,Master of Cheese,ct_ft,100,300,basic,,,' 384 '"[{\'user_name\': u\'bob\', \'local_role\': u\'bobsrole\'}]"\r\n' 369 385 ) 370 386 return … … 376 392 self.assertEqual( 377 393 result, 378 'code,faculty_code,department_code,title,study_mode,start_level,end_level,application_category,school_fee_1,school_fee_2\r\n' 379 'CERT1,F1,D1,Master of Cheese,ct_ft,100,300,basic,,\r\n' 380 'CERT2,F1,D1,Master of Cheddar,ct_ft,400,700,cest,,\r\n' 394 'code,faculty_code,department_code,title,study_mode,start_level,' 395 'end_level,application_category,school_fee_1,' 396 'school_fee_2,users_with_local_roles\r\n' 397 'CERT1,F1,D1,Master of Cheese,ct_ft,100,300,basic,,,' 398 '"[{\'user_name\': u\'bob\', \'local_role\': u\'bobsrole\'}]"\r\n' 399 'CERT2,F1,D1,Master of Cheddar,ct_ft,400,700,cest,,,[]\r\n' 381 400 ) 382 401 return … … 389 408 self.assertEqual( 390 409 result, 391 'code,faculty_code,department_code,title,study_mode,start_level,end_level,application_category,school_fee_1,school_fee_2\r\n' 392 'CERT1,F1,D1,Master of Cheese,ct_ft,100,300,basic,,\r\n' 393 'CERT2,F1,D1,Master of Cheddar,ct_ft,400,700,cest,,\r\n' 394 'CERT3,F1,D2,Cert. of Rubbish,dp_pt,100,200,no,,\r\n' 410 'code,faculty_code,department_code,title,study_mode,start_level,' 411 'end_level,application_category,' 412 'school_fee_1,school_fee_2,users_with_local_roles\r\n' 413 'CERT1,F1,D1,Master of Cheese,ct_ft,100,300,basic,,,' 414 '"[{\'user_name\': u\'bob\', \'local_role\': u\'bobsrole\'}]"\r\n' 415 'CERT2,F1,D1,Master of Cheddar,ct_ft,400,700,cest,,,[]\r\n' 416 'CERT3,F1,D2,Cert. of Rubbish,dp_pt,100,200,no,,,[]\r\n' 395 417 ) 396 418 return … … 402 424 self.assertEqual( 403 425 result, 404 'code,faculty_code,department_code,title,study_mode,start_level,end_level,application_category,school_fee_1,school_fee_2\r\n' 405 'CERT1,F1,D1,Master of Cheese,ct_ft,100,300,basic,,\r\n' 406 'CERT2,F1,D1,Master of Cheddar,ct_ft,400,700,cest,,\r\n' 407 'CERT3,F1,D2,Cert. of Rubbish,dp_pt,100,200,no,,\r\n' 426 'code,faculty_code,department_code,title,study_mode,start_level,' 427 'end_level,application_category,' 428 'school_fee_1,school_fee_2,users_with_local_roles\r\n' 429 'CERT1,F1,D1,Master of Cheese,ct_ft,100,300,basic,,,' 430 '"[{\'user_name\': u\'bob\', \'local_role\': u\'bobsrole\'}]"\r\n' 431 'CERT2,F1,D1,Master of Cheddar,ct_ft,400,700,cest,,,[]\r\n' 432 'CERT3,F1,D2,Cert. of Rubbish,dp_pt,100,200,no,,,[]\r\n' 408 433 ) 409 434 return -
main/waeup.kofa/trunk/src/waeup/kofa/userscontainer.py
r8787 r8986 67 67 68 68 class UsersExporter(grok.GlobalUtility, ExporterBase): 69 """Exporter for faculties.69 """Exporter for user accounts. 70 70 """ 71 71 grok.implements(ICSVExporter) … … 82 82 """Treat location values special. 83 83 """ 84 84 85 85 if name == 'local_roles' and context is not None: 86 86 local_roles = context.getLocalRoles()
Note: See TracChangeset for help on using the changeset viewer.