Ejemplo n.º 1
0
        def _link(pagenr, text):
            """
            Create a URL that links to another page
            """
            # Let the url_for() from webhelpers create a new link and set
            # the variable called 'link_var'. Example:
            # You are in '/foo/bar' (controller='foo', action='bar')
            # and you want to add a parameter 'pagenr'. Then you
            # call the navigator method with link_var='pagenr' and
            # the url_for() call will create a link '/foo/bar?pagenr=...'
            # with the respective page number added.
            # Further kwargs that are passed to the navigator will
            # also be added as URL parameters.
            arg_dict = {link_var:pagenr}
            arg_dict.update(kwargs)
            link_url = webhelpers.url_for(**arg_dict)
            if ajax_id:
                # Return an AJAX link that will update the HTML element
                # named by ajax_id.
                if framework == 'scriptaculous':
                    return webhelpers.link_to_remote(text, dict(update=ajax_id,
                        url=link_url))
                elif framework == 'jquery':
                    return webhelpers.link_to(text,
                        onclick="""$('#%s').load('%s'); return false""" % \
                        (ajax_id, link_url))
                else:
                    raise Exception, "Unsupported Javascript framework: %s" % \
                            framework

            else:
                # Return a normal a-href link that will call the same
                # controller/action with the link_var set to the new
                # page number.
                return webhelpers.link_to(text, link_url)
Ejemplo n.º 2
0
        def _pagerlink(pagenr, text):
            """
            Create a URL that links to another page using url_for()

            Parameters:
                
            pagenr
                Number of the page that the link points to

            text
                Text to be printed in the A-HREF tag
            """
            # Let the url_for() from webhelpers create a new link and set
            # the variable called 'link_var'. Example:
            # You are in '/foo/bar' (controller='foo', action='bar')
            # and you want to add a parameter 'pagenr'. Then you
            # call the navigator method with link_var='pagenr' and
            # the url_for() call will create a link '/foo/bar?pagenr=...'
            # with the respective page number added.
            link_params = {}
            link_params[link_var] = pagenr
            link_url = webhelpers.url_for(**link_params)
            if ajax_id:
                # Return an AJAX link that will update the HTML element
                # named by ajax_id.
                if framework == 'scriptaculous':
                    return webhelpers.link_to_remote(text, dict(update=ajax_id, url=link_url),
                        **link_attr)
                elif framework == 'jquery':
                    return webhelpers.link_to(text,
                        onclick="""$('#%s').load('%s'); return false""" % (ajax_id, link_url),
                            **link_attr)
                elif framework == 'yui2.3':
                    js = """
                        var callback = {
                            success: function(o) {
                                YAHOO.util.Dom.get('%s').innerHTML = o.responseText;
                             },
                            failure: function(o) {
                                alert('Failed to update the paginator.\\nPlease try again.');
                            }
                        }; 
                        sUrl = '%s';
                        var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null);
                        return false;
                    """ % (ajax_id, link_url)
                    return webhelpers.link_to(text, onclick=js, **link_attr)
                else:
                    raise Exception, "Unsupported Javascript framework: %s" % framework

            else:
                # Return a normal a-href link that will call the same
                # controller/action with the link_var set to the new
                # page number.
                return webhelpers.link_to(text, link_url, **link_attr)
Ejemplo n.º 3
0
def secure_link_to(text, url, **args):
    if '?' in url:
        separator = '&'
    else:
        separator = '?'

    url += '%sauthenticator=%s' % (separator, session_key())
    return link_to(text, url, **args)
Ejemplo n.º 4
0
        def _pagerlink(pagenr, text):
            """
            Create a URL that links to another page using url_for()

            Parameters:
                
            pagenr
                Number of the page that the link points to

            text
                Text to be printed in the A-HREF tag
            """
            # Let the url_for() from webhelpers create a new link and set
            # the variable called 'link_var'. Example:
            # You are in '/foo/bar' (controller='foo', action='bar')
            # and you want to add a parameter 'pagenr'. Then you
            # call the navigator method with link_var='pagenr' and
            # the url_for() call will create a link '/foo/bar?pagenr=...'
            # with the respective page number added.
            link_params = {}
            # Use the instance kwargs from Page.__init__ as URL parameters
            link_params.update(self.kwargs)
            # Add keyword arguments from pager() to the link as parameters
            link_params.update(kwargs)
            link_params[link_var] = pagenr
            # Create the URL to load a certain page
            link_url = webhelpers.url_for(**link_params)
            log.debug("link_url(**%r) => %r", link_params, link_url)
            # Create the URL to load the page area part of a certain page (AJAX updates)
            link_params[partial_var] = 1
            partial_url = webhelpers.url_for(**link_params)
            log.debug("partial_url(**%r) => %r", link_params, partial_url)
            if ajax_id:
                # Return an AJAX link that will update the HTML element
                # named by ajax_id.
                # Degrade gracefully if Javascript is not available by using
                # 'partial_url' in the onclick URLs while using 'link_url'
                # in the A-HREF URL.
                if framework == 'scriptaculous':
                    return webhelpers.link_to_remote(text, dict(update=ajax_id, url=partial_url,
                        before=javascript_before), href=link_url, **link_attr)
                elif framework == 'jquery':
                    return webhelpers.link_to(text, url=link_url,
                        onclick="""%s$('#%s').load('%s'); return false""" % \
                                (javascript_before, ajax_id, partial_url), **link_attr)
                elif framework == 'yui':
                    js = """%sYAHOO.util.Connect.asyncRequest('GET','%s',{
                        success:function(o){YAHOO.util.Dom.get('%s').innerHTML=o.responseText;}
                        },null); return false;""" % (javascript_before, partial_url, ajax_id)
                    return webhelpers.link_to(text, url=link_url, onclick=js, **link_attr)
                elif framework == 'extjs':
                    js = """%sExt.get('%s').load({url:'%s'}); return false;""" % (javascript_before, ajax_id, partial_url)
                    return webhelpers.link_to(text, url=link_url, onclick=js, **link_attr)
                else:
                    raise Exception, "Unsupported Javascript framework: %s" % framework

            else:
                # Return a normal a-href link that will call the same
                # controller/action with the link_var set to the new
                # page number.
                return webhelpers.link_to(text, link_url, **link_attr)