Changeset 6163 for main


Ignore:
Timestamp:
20 May 2011, 12:01:50 (14 years ago)
Author:
uli
Message:

Move get_users_with_local_roles and shorten it.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r6161 r6163  
    3636    IWAeUPXMLImporter, IWAeUPXMLExporter, IBatchProcessor,
    3737    ILocalRolesAssignable)
     38from waeup.sirp.permissions import get_users_with_local_roles
    3839from waeup.sirp.university.catalog import search
    3940from waeup.sirp.university.vocabularies import course_levels
     
    5152    view.redirect(view.url(view.context, u'@@manage')+'#tab-%s' % tab)
    5253    return
    53 
    54 def get_users_with_local_roles(view):
    55     role_manager = IPrincipalRoleManager(view.context)
    56     role_map = IPrincipalRoleMap(view.context)
    57     for item in role_map.getPrincipalsAndRoles():
    58         local_role = item[0]
    59         user_name = item[1]
    60         setting = item[2]
    61         user = grok.getSite()['users'].get(user_name,None)
    62         roles_dict = view.context.local_roles
    63         local_role_title = roles_dict[local_role]
    64         if user:
    65             yield(dict(user_name=user_name, user_title=user.description,
    66                 local_role=local_role, local_role_title=local_role_title,
    67                 setting=setting))
    68         else:
    69             yield(dict(user_name=user_name, user_title=user_name,
    70                 local_role=local_role, local_role_title=local_role_title,
    71                 setting=setting))
    7254
    7355def del_local_roles(view, tab, **data):
     
    10271009
    10281010    def getUsersWithLocalRoles(self):
    1029         return get_users_with_local_roles(self)
     1011        return get_users_with_local_roles(self.context)
    10301012
    10311013    # ToDo: Show warning message before deletion
     
    11901172        super(DepartmentManageFormPage, self).update()
    11911173        return
    1192        
     1174
    11931175    def getLocalRoles(self):
    11941176        roles = ILocalRolesAssignable(self.context)
     
    12011183            url = self.url(val)
    12021184            yield(dict(url=url, name=key, val=val))
    1203            
     1185
    12041186    def getUsersWithLocalRoles(self):
    1205         return get_users_with_local_roles(self)
     1187        return get_users_with_local_roles(self.context)
    12061188
    12071189    @grok.action('Save')
  • main/waeup.sirp/trunk/src/waeup/sirp/permissions.py

    r6162 r6163  
    22from zope.component import getUtilitiesFor
    33from zope.interface import Interface
    4 from zope.securitypolicy.interfaces import IRole
     4from zope.securitypolicy.interfaces import IRole, IPrincipalRoleMap
    55from waeup.sirp.interfaces import ILocalRolesAssignable
    66
     
    136136                name=name,
    137137                title=role.title,
    138                 description =role.description)
     138                description=role.description)
    139139            for name, role in self._roles]
    140140
     
    143143        """
    144144        return [name for name, role in self._roles]
     145
     146def get_users_with_local_roles(context):
     147    """Get a list of dicts representing the local roles set for `context`.
     148
     149    Each dict returns `user_name`, `user_title`, `local_role`,
     150    `local_role_title`, and `setting` for each entry in the local
     151    roles map of the `context` object.
     152    """
     153    role_map = IPrincipalRoleMap(context)
     154    for local_role, user_name, setting in role_map.getPrincipalsAndRoles():
     155        user = grok.getSite()['users'].get(user_name,None)
     156        user_title = getattr(user, 'description', user_name)
     157        local_role_title = getRoles()[local_role].title
     158        yield dict(user_name = user_name,
     159                   user_title = user_title,
     160                   local_role = local_role,
     161                   local_role_title = local_role_title,
     162                   setting = setting)
Note: See TracChangeset for help on using the changeset viewer.