Exemplo n.º 1
0
def _render_link_to_mp_or_user(user_id, context, request):
    """Render the linked name of a Member of Parliament (or the User)
    to the MP's (or the User's) "home" view.
    
    For use by forms in "view" mode.
    """
    try:
        mp = get_member_of_parliament(user_id)
        return mp.user.combined_name
        #!+BUSINESS(mb, feb-2013) is deprecated - how to render
        # bicameral installation
        #return zope.formlib.widget.renderElement("a",
        #    contents=mp.user.combined_name,
        #    href="/workspace/members/obj-%s/" % (mp.membership_id))
    except NoResultFound:
        # not a member of parliament
        #
        # Note that self.context is the field.property instance, while
        # self.context.context is the actual model instance with a "user"
        # relation/attribute -- BUT the user instance here may not
        # necessarily be the "right" user instance e.g. for case of
        # UserDelegation, the user we would want would be the one given by
        # the "delegation" attribute. So, we can only retrieve by user_id...
        user = get_user(user_id)
        if IAdminSectionLayer.providedBy(request):
            # for now, only if admin, we link into the admin view...
            return zope.formlib.widget.renderElement(
                "a",
                contents=user.combined_name,
                href="/admin/content/users/obj-%s/" % (user_id))
        else:
            # !+user_directory_listing_view(mr, aug-2012) link to a canonical
            # directory listing page for the user (when that is available).
            # Just the display text (no directory page to link to as yet).
            return user.combined_name
Exemplo n.º 2
0
def _render_link_to_mp_or_user(user_id, context, request):
    """Render the linked name of a Member of Parliament (or the User)
    to the MP's (or the User's) "home" view.
    
    For use by forms in "view" mode.
    """
    try:
        mp = get_member_of_chamber(user_id)
        return mp.user.combined_name
        #!+BUSINESS(mb, feb-2013) is deprecated - how to render
        # bicameral installation
        #return zope.formlib.widget.renderElement("a",
        #    contents=mp.user.combined_name,
        #    href="/workspace/members/obj-%s/" % (mp.member_id))
    except NoResultFound:
        # not a member of chamber 
        #
        # Note that self.context is the field.property instance, while 
        # self.context.context is the actual model instance with a "user" 
        # relation/attribute -- BUT the user instance here may not 
        # necessarily be the "right" user instance e.g. for case of 
        # UserDelegation, the user we would want would be the one given by 
        # the "delegation" attribute. So, we can only retrieve by user_id...
        user = get_user(user_id)
        if IAdminSectionLayer.providedBy(request):
            # for now, only if admin, we link into the admin view...
            return zope.formlib.widget.renderElement("a",
                contents=user.combined_name,
                href="/admin/content/users/obj-%s/" % (user_id))
        else:
            # !+user_directory_listing_view(mr, aug-2012) link to a canonical
            # directory listing page for the user (when that is available).
            # Just the display text (no directory page to link to as yet).
            return user.combined_name
Exemplo n.º 3
0
 def members_container_url(self):
     # !+traversal(murithi, mar-2010) ideally no urls should be
     # hardcoded here. absoluteURL should work for memberships or
     # members of groups [ to improve on getting urls of children ]
     if IAdminSectionLayer.providedBy(self.request):
         trusted = removeSecurityProxy(self.context)
         m_container = trusted.__parent__.__parent__.parliamentmembers
         return url.absoluteURL(m_container, self.request)
     return "/members/current"
Exemplo n.º 4
0
 def build_member_url(self, member):
     if IAdminSectionLayer.providedBy(self.request):
         return super(PoliticalGroupMembersViewlet,
                      self).build_member_url(member)
     session = Session()
     mpkls = domain.MemberOfParliament
     member_url = "%s/obj-%d/" % (
         self.members_container_url, session.query(mpkls).filter(
             mpkls.user_id == member.user_id).one().membership_id)
     return member_url
Exemplo n.º 5
0
 def build_member_url(self, member):
     if IAdminSectionLayer.providedBy(self.request):
         return super(PoliticalGroupMembersViewlet, self).build_member_url(
             member
         )
     session = Session()
     mpkls = domain.MemberOfParliament
     member_url = "%s/obj-%d/" % (self.members_container_url, 
         session.query(mpkls).filter(mpkls.user_id == member.user_id).one(
         ).membership_id
     )
     return member_url
Exemplo n.º 6
0
 def getter(item_user, formatter):
     related_user = _get_related_user(item_user, related_user_attribute_name)
     request = common.get_request()
     # !+ replace with: bungeni.ui.widgets._render_link_to_mp_or_user ?
     if IAdminSectionLayer.providedBy(request):
         # under admin, we link to the natural "view" of the schema relation
         parent = item_user
         while parent and not IAlchemistContainer.providedBy(parent):
             parent = removeSecurityProxy(parent.__parent__)
         item_user.__parent__ = parent
         href = url.absoluteURL(item_user, request)
     else:
         return related_user.combined_name
     return zope.formlib.widget.renderElement("a",
         contents=related_user.combined_name,  # User.combined_name derived property
         href=href
     )
Exemplo n.º 7
0
 def getter(item_user, formatter):
     related_user = _get_related_user(item_user,
                                      related_user_attribute_name)
     request = common.get_request()
     # !+ replace with: bungeni.ui.widgets._render_link_to_mp_or_user ?
     if IAdminSectionLayer.providedBy(request):
         # under admin, we link to the natural "view" of the schema relation
         parent = item_user
         while parent and not IAlchemistContainer.providedBy(parent):
             parent = removeSecurityProxy(parent.__parent__)
         item_user.__parent__ = parent
         href = url.absoluteURL(item_user, request)
     else:
         return related_user.combined_name
     return zope.formlib.widget.renderElement(
         "a",
         contents=related_user.
         combined_name,  # User.combined_name derived property
         href=href)
Exemplo n.º 8
0
 def getter(item_user, formatter):
     related_user = _get_related_user(item_user, related_user_attribute_name)
     request = common.get_request()
     # !+ replace with: bungeni.ui.widgets._render_link_to_mp_or_user ?
     if IAdminSectionLayer.providedBy(request):
         # under admin, we link to the natural "view" of the schema relation
         parent = item_user
         while parent and not IAlchemistContainer.providedBy(parent):
             parent = removeSecurityProxy(parent.__parent__)
         item_user.__parent__ = parent
         href = url.absoluteURL(item_user, request)
     else:
         #!+BUSINESS(mb, feb-2013) is deprecated
         # else we link direct to the MP's "public" view
         # mp = get_member_of_parliament(related_user.user_id)
         # href = "/members/current/obj-%s/" % (mp.membership_id)
         return related_user.combined_name
     return zope.formlib.widget.renderElement(
         "a", contents=related_user.combined_name, href=href  # User.combined_name derived property
     )
Exemplo n.º 9
0
 def getter(item_user, formatter):
     related_user = _get_related_user(item_user, related_user_attribute_name)
     request = common.get_request()
     # !+ replace with: bungeni.ui.widgets._render_link_to_mp_or_user ?
     if IAdminSectionLayer.providedBy(request):
         # under admin, we link to the natural "view" of the schema relation
         parent = item_user
         while parent and not IAlchemistContainer.providedBy(parent):
             parent = removeSecurityProxy(parent.__parent__)
         item_user.__parent__ = parent
         href = url.absoluteURL(item_user, request)
     else:
         #!+BUSINESS(mb, feb-2013) is deprecated
         # else we link direct to the MP's "public" view
         #mp = get_member_of_parliament(related_user.user_id)
         #href = "/members/current/obj-%s/" % (mp.membership_id)
         return related_user.combined_name
     return zope.formlib.widget.renderElement("a",
         contents=related_user.combined_name,  # User.combined_name derived property
         href=href
     )