コード例 #1
0
ファイル: views.py プロジェクト: pythonindia/funnel
def url_for(endpoint, **kw):
    """Overwriting url_for to retain query parameter section across links and redirects.
    """
    url = _url_for(endpoint, **kw)
    if 'section' in request.args:
        url += "?section=" + request.args['section']
    return url
コード例 #2
0
ファイル: core.py プロジェクト: occrp/ouija
def url_for(*a, **kw):
    """ Always generate external URLs. """
    try:
        kw['_external'] = True
        if app.config.get('PREFERRED_URL_SCHEME'):
            kw['_scheme'] = app.config.get('PREFERRED_URL_SCHEME')
        return _url_for(*a, **kw)
    except RuntimeError:
        return None
コード例 #3
0
ファイル: core.py プロジェクト: CivicVision/datahub
def url_for(endpoint, **kwargs):
    try:
        from flask import current_app
        if current_app.config.get('PREFERRED_URL_SCHEME'):
            kwargs['_scheme'] = current_app.config.get('PREFERRED_URL_SCHEME')
        url = _url_for(endpoint, _external=True, **kwargs)
        return url
    except:
        return None
コード例 #4
0
ファイル: util.py プロジェクト: MichelCordeiro/indico
def url_for(endpoint, *targets, **values):
    """Wrapper for Flask's url_for() function.

    Instead of an endpoint you can also pass an URLHandler - in this case **only** its _endpoint will be used.
    However, there is usually no need to do so. This is just so you can use it in places where sometimes a UH
    might be passed instead.

    The `target` argument allows you to pass some object having a `locator` property or `getLocator` method
    returning a dict. This should be used e.g. when generating an URL for an event since ``getLocator()``
    provides the ``{'confId': 123}`` dict instead of you having to pass ``confId=event.getId()`` as a kwarg.

    For details on Flask's url_for, please see its documentation.
    Anyway, the important arguments you can put in `values` besides actual arguments are:
    _external: if set to `True`, an absolute URL is generated
    _secure: if True/False, set _scheme to https/http if possible (only with _external)
    _scheme: a string specifying the desired URL scheme (only with _external) - use _secure if possible!
    _anchor: if provided this is added as #anchor to the URL.
    """

    if hasattr(endpoint, '_endpoint'):
        endpoint = endpoint._endpoint

    secure = values.pop('_secure', None)
    if secure is not None:
        from indico.core.config import Config
        if secure and Config.getInstance().getBaseSecureURL():
            values['_scheme'] = 'https'
        elif not secure:
            values['_scheme'] = 'http'

    if targets:
        locator = {}
        for target in targets:
            if target:  # don't fail on None or mako's Undefined
                locator.update(get_locator(target))
        intersection = set(locator.iterkeys()) & set(values.iterkeys())
        if intersection:
            raise ValueError('url_for kwargs collide with locator: %s' % ', '.join(intersection))
        values.update(locator)

    static_site_mode = bool(ContextManager.get('offlineMode'))
    values.setdefault('_external', static_site_mode)

    for key, value in values.iteritems():
        # Avoid =True and =False in the URL
        if isinstance(value, bool):
            values[key] = int(value)

    url = _url_for(endpoint, **values)
    if static_site_mode and not values['_external']:
        # for static sites we assume all relative urls need to be
        # mangled to a filename
        # we should really fine a better way to handle anything
        # related to offline site urls...
        from indico.modules.events.static.util import url_to_static_filename
        url = url_to_static_filename(url)
    return url
コード例 #5
0
ファイル: util.py プロジェクト: capile/indico
 def _redirect():
     # In case of POST we can't safely redirect since the method would switch to GET
     # and thus the request would most likely fail.
     if view_func and request.method == 'POST':
         return view_func(**request.view_args)
     # Ugly hack to get non-list arguments unless they are used multiple times.
     # This is necessary since passing a list for an URL path argument breaks things.
     args = dict((k, v[0] if len(v) == 1 else v) for k, v in request.args.iterlists())
     target = _url_for('%s.%s' % (blueprint.name, endpoint), **args)
     return redirect(target, 302 if app.debug else 301)
コード例 #6
0
ファイル: urls.py プロジェクト: wonderpl/dolly-web
def url_for(*args, **kwargs):
    kwargs.setdefault('_external', True)
    url = _url_for(*args, **kwargs)
    # Ensure urls on secure domain use https:
    secure_subdomain = current_app.config.get('SECURE_SUBDOMAIN')
    if secure_subdomain and url.startswith('http://' + secure_subdomain + '.'):
        url = 'https://' + url[7:]
    # Ensure http-only domain don't get https protocol
    if any(url.startswith('https://' + domain + '/') for domain in http_only_domains if domain):
        url = 'http://' + url[8:]
    tracking_params = getattr(g, '_tracking_params', None)
    if tracking_params:
        url += '?' + urlencode(tracking_params)
    return url
コード例 #7
0
ファイル: utility.py プロジェクト: xsnippet/xsnippet
def abs_url_for(name, **kwargs):
    """
        Return absolute url for some view.

        Warning! This function works only with correct ``SERVER_NAME``
        value in configuration file.

        Example: ``SERVER_NAME = 'www.xsnippet.org'``
    """

    return "http://{0}{1}".format(
        current_app.config["SERVER_NAME"],
        _url_for(name, **kwargs)
    )
コード例 #8
0
ファイル: util.py プロジェクト: belokop/indico_bare
 def _redirect(**view_args):
     # In case of POST we can't safely redirect since the method would switch to GET
     # and thus the request would most likely fail.
     if view_func and request.method == 'POST':
         return view_func(**view_args)
     # Ugly hack to get non-list arguments unless they are used multiple times.
     # This is necessary since passing a list for an URL path argument breaks things.
     view_args.update((k, v[0] if len(v) == 1 else v) for k, v in request.args.iterlists())
     if view_args_conv is not None:
         for oldkey, newkey in view_args_conv.iteritems():
             view_args[newkey] = view_args.pop(oldkey, None)
     try:
         target = _url_for('%s.%s' % (blueprint.name, endpoint), **view_args)
     except BuildError:
         raise NotFound
     return redirect(target, 302 if app.debug else 301)
コード例 #9
0
ファイル: helpers.py プロジェクト: insynchq/paano
def url_for(*args, **kwargs):
    """
    Override Flask's `url_for` to retain `lang` and `platform` params
    across requests
    """

    selected_lang = kwargs.get('lang', request.args.get('lang'))
    if selected_lang not in (None, DEFAULT_LANG):
        kwargs['lang'] = selected_lang

    selected_platform = kwargs.get('platform', request.args.get('platform'))
    if selected_platform == 'general':
        selected_platform = g.detected_platform
    if selected_platform not in (None, g.detected_platform):
        kwargs['platform'] = selected_platform

    return _url_for(*args, **kwargs)
コード例 #10
0
  def url_for(self, *args, **kwargs):
    if self.use_local or not args[0].endswith('static'):
      return _url_for(*args, **kwargs)

    # Normalize path
    path = kwargs.pop('filename').strip('/')

    # Get headers info
    is_gzip = (
      'gzip' in request.headers.get('Accept-Encoding', '') and
      not self._is_image(path)
    )

    # Get compiled path
    compiled_path = self._compiled_paths[self._key(path, is_gzip)]

    return self._build_url(compiled_path, **kwargs)
コード例 #11
0
ファイル: util.py プロジェクト: indico/indico
def url_for(endpoint, *targets, **values):
    """Wrapper for Flask's url_for() function.

    The `target` argument allows you to pass some object having a `locator` property returning a dict.

    For details on Flask's url_for, please see its documentation.
    The important special arguments you can put in `values` are:

    _external: if set to `True`, an absolute URL is generated
    _scheme: a string specifying the desired URL scheme (only with _external) - use _secure if possible!
    _anchor: if provided this is added as #anchor to the URL.
    """

    if targets:
        locator = {}
        for target in targets:
            if target:  # don't fail on None or mako's Undefined
                locator.update(get_locator(target))
        intersection = set(locator.iterkeys()) & set(values.iterkeys())
        if intersection:
            raise ValueError('url_for kwargs collide with locator: %s' % ', '.join(intersection))
        values.update(locator)

    for key, value in values.iteritems():
        # Avoid =True and =False in the URL
        if isinstance(value, bool):
            values[key] = int(value)

    url = _url_for(endpoint, **values)
    if g.get('static_site') and 'custom_manifests' in g and not values.get('_external'):
        # for static sites we assume all relative urls need to be
        # mangled to a filename
        # we should really fine a better way to handle anything
        # related to offline site urls...
        from indico.modules.events.static.util import url_to_static_filename
        url = url_to_static_filename(endpoint, url)
        # mark asset as used so that generator can include it
        g.used_url_for_assets.add(url)
    return url
コード例 #12
0
ファイル: util.py プロジェクト: capile/indico
def url_for(endpoint, target=None, **values):
    """Wrapper for Flask's url_for() function.

    Instead of an endpoint you can also pass an URLHandler - in this case **only** its _endpoint will be used.
    However, there is usually no need to do so. This is just so you can use it in places where sometimes a UH
    might be passed instead.

    The `target` argument allows you to pass some object having a `getLocator` method returning a dict. This
    should be used e.g. when generating an URL for an event since `getLocator()` provides the `{'confId': 123}`
    dict instead of you having to pass `confId=event.getId()` as a kwarg.

    For details on Flask's url_for, please see its documentation.
    Anyway, the important arguments you can put in `values` besides actual arguments are:
    _external: if set to `True`, an absolute URL is generated
    _secure: if True/False, set _scheme to https/http if possible (only with _external)
    _scheme: a string specifying the desired URL scheme (only with _external) - use _secure if possible!
    _anchor: if provided this is added as #anchor to the URL.
    """

    if hasattr(endpoint, '_endpoint'):
        endpoint = endpoint._endpoint

    secure = values.pop('_secure', None)
    if secure is not None:
        from indico.core.config import Config
        if secure and Config.getInstance().getBaseSecureURL():
            values['_scheme'] = 'https'
        elif not secure:
            values['_scheme'] = 'http'

    if target is not None:
        locator = target.getLocator()
        intersection = set(locator.iterkeys()) & set(values.iterkeys())
        if intersection:
            raise ValueError('url_for kwargs collide with locator: %s' % ', '.join(intersection))
        values.update(locator)

    return _url_for(endpoint, **values)
コード例 #13
0
ファイル: _common.py プロジェクト: hdooley/memegen
def route(*args, **kwargs):
    """Unquoted version of Flask's `url_for`."""
    return unquote(_url_for(*args, **kwargs))
コード例 #14
0
ファイル: util.py プロジェクト: pferreir/indico-backup
 def _redirect(**kwargs):
     return redirect(_url_for(endpoint, **kwargs), code=code)
コード例 #15
0
ファイル: util.py プロジェクト: indico/indico
 def _redirect(**kwargs):
     params = dict(request.args.to_dict(), **kwargs)
     return redirect(_url_for(endpoint, **params), code=code)
コード例 #16
0
ファイル: core.py プロジェクト: nimblemachine/grano
def url_for(*a, **kw):
    return _url_for(*a, _external=True, **kw)
コード例 #17
0
ファイル: core.py プロジェクト: martinwoitzik/storyweb
def url_for(*a, **kw):
    kw['_external'] = True
    return _url_for(*a, **kw)
コード例 #18
0
def url_for(*a, **kw):
    return _url_for(*a, _external=True, **kw)
コード例 #19
0
 def _redirect(**kwargs):
     return redirect(_url_for(endpoint, **kwargs), code=code)
コード例 #20
0
def url_for(*a, **kw):
    try:
        kw['_external'] = True
        return _url_for(*a, **kw)
    except RuntimeError:
        return None
コード例 #21
0
ファイル: _common.py プロジェクト: cacology/memegen
def url_for(*args, **kwargs):
    """Unquoted version of Flask's `url_for`."""
    return unquote(_url_for(*args, **kwargs))
コード例 #22
0
def url_for(*a, **kw):
    try:
        return _url_for(*a, _external=True, **kw)
    except RuntimeError:
        return None
コード例 #23
0
def url_for(*args, **kwargs):
    return _url_for(*args, __prefix=make_prefix(), **kwargs)
コード例 #24
0
ファイル: core.py プロジェクト: clkao/grano
def url_for(*a, **kw):
    try:
        return _url_for(*a, _external=True, **kw)
    except RuntimeError:
        return None
コード例 #25
0
 def _redirect(**kwargs):
     params = dict(request.args.to_dict(), **kwargs)
     return redirect(_url_for(endpoint, **params), code=code)
コード例 #26
0
ファイル: core.py プロジェクト: arc64/datawi.re
def url_for(*a, **kw):
    try:
        kw['_external'] = True
        return _url_for(*a, **kw)
    except RuntimeError:
        return None
コード例 #27
0
ファイル: utils.py プロジェクト: freshy969/findex-gui
def dirty_url_for():
    """dirty flask.url_for() monkey patch."""
    from findex_gui.web import app
    flask.url_for = lambda *args, **kwargs: "%s%s" % (app.config[
        "APPLICATION_ROOT"][:-1], _url_for(*args, **kwargs))