예제 #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
예제 #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
예제 #3
0
def _determine_related_user(context, user_attr_name="owner"):
    """Get the user instance that is the value of the {user_attr_name} attribute.
    
    The context may be newly created, not yet flushed to db (so may have 
    "owner_id" set but "owner" not yet updated).
    """
    user = getattr(context, user_attr_name)
    # context not yet flushed may have "X_id" set but "X" not yet updated
    if user is None:
        # !+ some contexts define an "X" but not an "X_id"!
        user_id_attr_name = "%s_id" % (user_attr_name)
        if hasattr(context, user_id_attr_name):
            user = get_user(getattr(context, user_id_attr_name))
    assert user, "User (as %r on %s) may not be None" % (user_attr_name, context)
    return user
예제 #4
0
def _determine_related_user(context, user_attr_name="owner"):
    """Get the user instance that is the value of the {user_attr_name} attribute.
    
    The context may be newly created, not yet flushed to db (so may have 
    "owner_id" set but "owner" not yet updated).
    """
    user = getattr(context, user_attr_name)
    # context not yet flushed may have "X_id" set but "X" not yet updated
    if user is None:
        # !+ some contexts define an "X" but not an "X_id"!
        user_id_attr_name = "%s_id" % (user_attr_name)
        if hasattr(context, user_id_attr_name):
            user = get_user(getattr(context, user_id_attr_name))
    assert user, "User (as %r on %s) may not be None" % (user_attr_name,
                                                         context)
    return user