Changeset 8986 for main/waeup.kofa/trunk


Ignore:
Timestamp:
12 Jul 2012, 20:32:29 (12 years ago)
Author:
Henrik Bettermann
Message:

Export users with locale roles in faculties, departments, courses and certificates.

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  
    1919"""
    2020import grok
     21from zope.securitypolicy.interfaces import IPrincipalRoleMap
    2122from waeup.kofa.interfaces import ICSVExporter
    2223from waeup.kofa.interfaces import MessageFactory as _
     
    3031
    3132    #: Fieldnames considered by this exporter
    32     fields = ('code', 'title', 'title_prefix')
     33    fields = ('code', 'title', 'title_prefix', 'users_with_local_roles')
    3334
    3435    #: The title under which this exporter will be displayed
    3536    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)
    3648
    3749    def export(self, faculties, filepath=None):
     
    6173
    6274    #: 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')
    6477
    6578    #: The title under which this exporter will be displayed
     
    97110    #: Fieldnames considered by this exporter
    98111    fields = ('code', 'faculty_code', 'department_code', 'title', 'credits',
    99               'passmark', 'semester')
     112              'passmark', 'semester', 'users_with_local_roles')
    100113
    101114    #: The title under which this exporter will be displayed
     
    105118        """Hook for mangling values in derived classes
    106119        """
    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':
    108126            try:
    109127                value = context.__parent__.__parent__.__parent__.code
     
    140158    fields = ('code', 'faculty_code', 'department_code', 'title', 'study_mode',
    141159              'start_level', 'end_level', 'application_category',
    142               'school_fee_1', 'school_fee_2')
     160              'school_fee_1', 'school_fee_2', 'users_with_local_roles')
    143161
    144162    #: The title under which this exporter will be displayed
  • main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_export.py

    r8920 r8986  
    2222from zope.component import queryUtility
    2323from zope.interface.verify import verifyObject, verifyClass
     24from zope.securitypolicy.interfaces import IPrincipalRoleManager
    2425from waeup.kofa.interfaces import ICSVExporter
    25 from waeup.kofa.testing import KofaUnitTestLayer
     26from waeup.kofa.testing import KofaUnitTestLayer, FunctionalLayer
    2627from waeup.kofa.university import (
    2728    FacultiesContainer, Faculty, Department, Course, Certificate,
     
    3435class FacultyExporterTest(unittest.TestCase):
    3536
    36     layer = KofaUnitTestLayer
     37    layer = FunctionalLayer
    3738
    3839    def setUp(self):
     
    6667        self.assertEqual(
    6768            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'
    7071            )
    7172        return
     
    7879        self.assertEqual(
    7980            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'
    8283            )
    8384        return
     
    9697        self.assertEqual(
    9798            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'
    101102            )
    102103        return
     
    114115        self.assertEqual(
    115116            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'
    119120            )
    120121        return
     
    123124    # Tests for DepartmentExporter
    124125
    125     layer = KofaUnitTestLayer
     126    layer = FunctionalLayer
    126127
    127128    def setUp(self):
     
    141142        self.fac1.addDepartment(self.dept2)
    142143        self.fac2.addDepartment(self.dept3)
     144        role_manager = IPrincipalRoleManager(self.dept1)
     145        role_manager.assignRoleToPrincipal(u'bobsrole', u'bob')
    143146        return
    144147
     
    167170        self.assertEqual(
    168171            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'
    171175            )
    172176        return
     
    178182        self.assertEqual(
    179183            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'
    183188            )
    184189        return
     
    191196        self.assertEqual(
    192197            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'
    197203            )
    198204        return
     
    204210        self.assertEqual(
    205211            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'
    210217            )
    211218        return
     
    214221    # Tests for CourseExporter
    215222
    216     layer = KofaUnitTestLayer
     223    layer = FunctionalLayer
    217224
    218225    def setUp(self):
     
    260267        self.assertEqual(
    261268            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'
    264272            )
    265273        return
     
    271279        self.assertEqual(
    272280            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'
    276285            )
    277286        return
     
    284293        self.assertEqual(
    285294            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'
    290300            )
    291301        return
     
    297307        self.assertEqual(
    298308            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'
    303314            )
    304315        return
     
    307318    # Tests for CertificateExporter
    308319
    309     layer = KofaUnitTestLayer
     320    layer = FunctionalLayer
    310321
    311322    def setUp(self):
     
    339350        self.dept1.certificates.addCertificate(self.cert2)
    340351        self.dept2.certificates.addCertificate(self.cert3)
     352        role_manager = IPrincipalRoleManager(self.cert1)
     353        role_manager.assignRoleToPrincipal(u'bobsrole', u'bob')
    341354        return
    342355
     
    365378        self.assertEqual(
    366379            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'
    369385            )
    370386        return
     
    376392        self.assertEqual(
    377393            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'
    381400            )
    382401        return
     
    389408        self.assertEqual(
    390409            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'
    395417            )
    396418        return
     
    402424        self.assertEqual(
    403425            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'
    408433            )
    409434        return
  • main/waeup.kofa/trunk/src/waeup/kofa/userscontainer.py

    r8787 r8986  
    6767
    6868class UsersExporter(grok.GlobalUtility, ExporterBase):
    69     """Exporter for faculties.
     69    """Exporter for user accounts.
    7070    """
    7171    grok.implements(ICSVExporter)
     
    8282        """Treat location values special.
    8383        """
    84        
     84
    8585        if name == 'local_roles' and context is not None:
    8686            local_roles = context.getLocalRoles()
Note: See TracChangeset for help on using the changeset viewer.