Python flask.helpers.url_for() Examples

The following are 8 code examples of flask.helpers.url_for(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask.helpers , or try the search function .
Example #1
Source File: flask_pyoidc.py    From Flask-pyoidc with Apache License 2.0 5 votes vote down vote up
def _get_url_for_logout_view(self):
        return url_for(self._logout_view.__name__, _external=True) if self._logout_view else None 
Example #2
Source File: renderers.py    From puncover with MIT License 5 votes vote down vote up
def url_for(self, endpoint, **values):
        result = url_for(endpoint, **values)
        href = Href(result)
        # pass along any query parameters
        # this is kind of hacky as it replaces any existing parameters
        return href(request.args) 
Example #3
Source File: renderers.py    From puncover with MIT License 5 votes vote down vote up
def url_for_symbol(self, value):
        if value[collector.TYPE] in [collector.TYPE_FUNCTION]:
            return self.url_for("path", path=self.collector.qualified_symbol_name(value))

        # file or folder
        path = value.get(collector.PATH, None)
        return self.url_for("path", path=path) if path else "" 
Example #4
Source File: renderers.py    From puncover with MIT License 5 votes vote down vote up
def dispatch_request(self, symbol_name=None):
        symbol = self.collector.symbol(symbol_name, qualified=False)
        if not symbol:
            abort(404)

        return redirect(self.url_for("path", path=self.collector.qualified_symbol_name(symbol))) 
Example #5
Source File: common.py    From git-webhook with MIT License 5 votes vote down vote up
def github_authorized(oauth_token):
    if oauth_token is None:
        flash("Authorization failed.")
        return redirect(url_for('index'))

    session['oauth_token'] = oauth_token

    me = github.get('user')
    user_id = me['login']

    # is user exist
    user = User.query.get(user_id)

    if user is None:
        # not exist, add
        user = User(id=user_id)

    # update github user information
    user.last_login = DateUtil.now_datetime()
    user.name = me.get('name', user_id)
    user.location = me.get('location', '')
    user.avatar = me.get('avatar_url', '')

    user.save()

    RequestUtil.login_user(user.dict())

    return redirect(url_for('index')) 
Example #6
Source File: common.py    From git-webhook with MIT License 5 votes vote down vote up
def logout():
    RequestUtil.logout()
    return redirect(url_for('index')) 
Example #7
Source File: app.py    From pyop with Apache License 2.0 5 votes vote down vote up
def init_oidc_provider(app):
    with app.app_context():
        issuer = url_for('oidc_provider.index')[:-1]
        authentication_endpoint = url_for('oidc_provider.authentication_endpoint')
        jwks_uri = url_for('oidc_provider.jwks_uri')
        token_endpoint = url_for('oidc_provider.token_endpoint')
        userinfo_endpoint = url_for('oidc_provider.userinfo_endpoint')
        registration_endpoint = url_for('oidc_provider.registration_endpoint')
        end_session_endpoint = url_for('oidc_provider.end_session_endpoint')

    configuration_information = {
        'issuer': issuer,
        'authorization_endpoint': authentication_endpoint,
        'jwks_uri': jwks_uri,
        'token_endpoint': token_endpoint,
        'userinfo_endpoint': userinfo_endpoint,
        'registration_endpoint': registration_endpoint,
        'end_session_endpoint': end_session_endpoint,
        'scopes_supported': ['openid', 'profile'],
        'response_types_supported': ['code', 'code id_token', 'code token', 'code id_token token'],  # code and hybrid
        'response_modes_supported': ['query', 'fragment'],
        'grant_types_supported': ['authorization_code', 'implicit'],
        'subject_types_supported': ['pairwise'],
        'token_endpoint_auth_methods_supported': ['client_secret_basic'],
        'claims_parameter_supported': True
    }

    userinfo_db = Userinfo(app.users)
    signing_key = RSAKey(key=rsa_load('signing_key.pem'), alg='RS256')
    provider = Provider(signing_key, configuration_information,
                        AuthorizationState(HashBasedSubjectIdentifierFactory(app.config['SUBJECT_ID_HASH_SALT'])),
                        {}, userinfo_db)

    return provider 
Example #8
Source File: views.py    From edwin with Apache License 2.0 4 votes vote down vote up
def raw_svgs():
    chart = pygal.Line(legend_at_bottom=True, legend_box_size=18)

    # =======================================
    # Declare the location of svg.jquery.js and pygal-tooltips.js in server side.
    # =======================================
    # It must be declare in server side, not html file
    # if not declare in server, by default it will load the two js files located in http://kozea.github.com/pygal.js. And it will slow down the page loading

    # 1, It works, load local js files
    SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
    chart.js = [os.path.join(SITE_ROOT, "static/js/", "svg.jquery.js"),
                os.path.join(SITE_ROOT, "static/js/", "pygal-tooltips.js")]

    # 2.a, It Works, but it is ugly because it use local absolute http url
    # chart.js =['http://127.0.0.1:5000/static/js/svg.jquery.js',
    #     'http://127.0.0.1:5000/static/js/pygal-tooltips.js']

    # 2.b, works, use local CDN absolute http url
    # chart.js =['http://another_server/pygal-tooltips.js',
    #     'http://another_server/svg.jquery.js']

    # 3, Does not work, error raised at visiting, IOError: [Errno 2] No such file
    # chart.js = [url_for('static', filename='js/svg.jquery.js'),
    #            url_for('static', filename='js/pygal-tooltips.js')]

    # disable xml root node
    chart.disable_xml_declaration = True
    chart.title = 'Browser usage evolution (in %)'
    chart.width = 2000
    chart.height = 2000
    chart.x_labels = map(str, range(2002, 2013))
    chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
    chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
    chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
    chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])

    svg_xml = chart.render()
    svg_xml = '<svg  style="width:2000px" ' + svg_xml[4:]
    svg_xml1 = svg_xml[:100]
    response = make_response(render_template('test_svg.html', title=svg_xml1, svg_xml=svg_xml))
    # response.headers['Content-Type']='image/svg+xml' 不能设置Content-Type为svg模式
    return response