Ignore:
Timestamp:
23 Nov 2011, 07:19:16 (13 years ago)
Author:
Henrik Bettermann
Message:

Define get_user_account in helpers and use it.

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

Legend:

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

    r7172 r7175  
    33import grok
    44
    5 from zope.component import getMultiAdapter, queryAdapter, getUtility
     5from zope.component import getMultiAdapter, queryAdapter
    66from zope.interface import Interface
    77from zope.location.interfaces import ISite
    88from zope.traversing.browser import absoluteURL
    9 from zope.pluggableauth.interfaces import IAuthenticatorPlugin
    109from waeup.sirp.browser.pages import (
    1110    UniversityPage, FacultyContainerPage, DatacenterPage, FacultyPage,
     
    1716                                   IWAeUPXMLImporter, IDataCenter)
    1817from waeup.sirp.browser.layout import WAeUPPage
     18from waeup.sirp.utils.helpers import get_user_account
    1919
    2020grok.templatedir('templates')
     
    339339    icon = ''
    340340
    341     def getUserAccount(self):
    342         """Return local user account.
    343         """
    344         principal_id = self.request.principal.id
    345         authenticator = getUtility(IAuthenticatorPlugin, name='users')
    346         account = authenticator.getAccount(principal_id)
    347         return account
    348 
    349341    @property
    350342    def url(self):
    351         account_object = self.getUserAccount()
     343        account_object = get_user_account(self.request)
    352344        if account_object:
    353             return absoluteURL(account_object, self.request)
     345            return self.view.url(account_object)
    354346        return
    355347
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.py

    r7137 r7175  
    88from cStringIO import StringIO
    99from docutils.core import publish_string
     10from zope.component import getUtility
    1011from zope.component.interfaces import IFactory
    1112from zope.interface import implementedBy
     
    1415from zope.security.interfaces import NoInteraction
    1516from zope.security.management import getInteraction
     17from zope.pluggableauth.interfaces import IAuthenticatorPlugin
    1618
    1719BUFSIZE = 8 * 1024
     
    451453    file_like_obj.seek(0, 2) # seek to last position in file
    452454    return file_like_obj.tell()
     455
     456def get_user_account(request):
     457    """Return local user account.
     458    """
     459    principal_id = request.principal.id
     460    authenticator = getUtility(IAuthenticatorPlugin, name='users')
     461    account = authenticator.getAccount(principal_id)
     462    return account
     463
Note: See TracChangeset for help on using the changeset viewer.