Python werkzeug.utils.redirect() Examples
The following are 30
code examples of werkzeug.utils.redirect().
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
werkzeug.utils
, or try the search function
.
Example #1
Source File: routing.py From cloud-playground with Apache License 2.0 | 6 votes |
def make_redirect_url(self, path_info, query_args=None, domain_part=None): """Creates a redirect URL. :internal: """ suffix = '' if query_args: suffix = '?' + self.encode_query_args(query_args) return str('%s://%s/%s%s' % ( self.url_scheme, self.get_host(domain_part), posixpath.join(self.script_name[:-1].lstrip('/'), url_quote(path_info.lstrip('/'), self.map.charset, safe='/:|+')), suffix ))
Example #2
Source File: routing.py From jbox with MIT License | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #3
Source File: flask_pyoidc.py From Flask-pyoidc with Apache License 2.0 | 6 votes |
def _logout(self): logger.debug('user logout') try: session = UserSession(flask.session) except UninitialisedSession as e: logger.info('user was already logged out, doing nothing') return None id_token_jwt = session.id_token_jwt client = self.clients[session.current_provider] session.clear() if client.provider_end_session_endpoint: flask.session['end_session_state'] = rndstr() end_session_request = EndSessionRequest(id_token_hint=id_token_jwt, post_logout_redirect_uri=self._get_post_logout_redirect_uri(client), state=flask.session['end_session_state']) logger.debug('send endsession request: %s', end_session_request.to_json()) return redirect(end_session_request.request(client.provider_end_session_endpoint), 303) return None
Example #4
Source File: flask_pyoidc.py From Flask-pyoidc with Apache License 2.0 | 6 votes |
def _authenticate(self, client, interactive=True): if not client.is_registered(): self._register_client(client) flask.session['destination'] = flask.request.url flask.session['state'] = rndstr() flask.session['nonce'] = rndstr() # Use silent authentication for session refresh # This will not show login prompt to the user extra_auth_params = {} if not interactive: extra_auth_params['prompt'] = 'none' login_url = client.authentication_request(flask.session['state'], flask.session['nonce'], extra_auth_params) auth_params = dict(parse_qsl(login_url.split('?')[1])) flask.session['fragment_encoded_response'] = AuthResponseHandler.expect_fragment_encoded_response(auth_params) return redirect(login_url)
Example #5
Source File: routing.py From lambda-packs with MIT License | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #6
Source File: routing.py From RSSNewsGAE with Apache License 2.0 | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #7
Source File: map.py From contextualise with MIT License | 6 votes |
def delete(map_identifier): topic_store = get_topic_store() topic_map = topic_store.get_topic_map(map_identifier, current_user.id) if topic_map is None: abort(404) if not topic_map.owner: abort(403) if request.method == "POST": # Remove map from topic store topic_store.delete_topic_map(map_identifier, current_user.id) # Delete the map's directory topic_map_directory = os.path.join(bp.root_path, RESOURCES_DIRECTORY, str(map_identifier)) if os.path.isdir(topic_map_directory): shutil.rmtree(topic_map_directory) flash("Map successfully deleted.", "success") return redirect(url_for("map.index")) return render_template("map/delete.html", topic_map=topic_map)
Example #8
Source File: storage.py From indico-plugins with MIT License | 6 votes |
def send_file(self, file_id, content_type, filename, inline=True): if self.proxy_downloads == ProxyDownloadsMode.local: return send_file(filename, self.open(file_id), content_type, inline=inline) try: bucket, id_ = self._parse_file_id(file_id) content_disp = 'inline' if inline else 'attachment' h = Headers() h.add('Content-Disposition', content_disp, filename=filename) url = self.client.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': id_, 'ResponseContentDisposition': h.get('Content-Disposition'), 'ResponseContentType': content_type}, ExpiresIn=120) response = redirect(url) if self.proxy_downloads == ProxyDownloadsMode.nginx: # nginx can proxy the request to S3 to avoid exposing the redirect and # bucket URL to the end user (since it is quite ugly and temporary) response.headers['X-Accel-Redirect'] = '/.xsf/s3/' + url.replace('://', '/', 1) return response except Exception as e: raise StorageError('Could not send file "{}": {}'.format(file_id, e)), None, sys.exc_info()[2]
Example #9
Source File: routing.py From Financial-Portfolio-Flask with MIT License | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #10
Source File: routing.py From Flask-P2P with MIT License | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #11
Source File: routing.py From planespotter with MIT License | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #12
Source File: base.py From betterlifepsi with MIT License | 6 votes |
def delete_view(self): """ Delete model view. Only POST method is allowed. Whether the model could be deleted is decided by model """ from flask_admin.helpers import get_redirect_target return_url = get_redirect_target() or self.get_url('.index_view') form = self.delete_form() if self.validate_form(form): # id is InputRequired() model_id = form.id.data model = self.get_one(model_id) if model is not None and not model.can_delete(): flash(gettext('You are not allowed to delete this object')) return redirect(return_url) return super(ModelViewWithAccess, self).delete_view()
Example #13
Source File: routing.py From pyRevit with GNU General Public License v3.0 | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #14
Source File: routing.py From PhonePi_SampleServer with MIT License | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #15
Source File: routing.py From cloud-playground with Apache License 2.0 | 6 votes |
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoint]: # every rule that comes after this one, including ourself # has a lower priority for the defaults. We order the ones # with the highest priority up for building. if r is rule: break if r.provides_defaults_for(rule) and \ r.suitable_for(values, method): values.update(r.defaults) domain_part, path = r.build(values) return self.make_redirect_url( path, query_args, domain_part=domain_part)
Example #16
Source File: dingtalk.py From odoo-dingtalk with GNU Lesser General Public License v3.0 | 5 votes |
def home(self): corpid = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_corpid') corpsecret = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_corpsecret') agentid = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_agentid') if not corpid or not corpsecret: return redirect('/') dt = DingTalkClient(corpid,corpsecret) now = int(time.time()); dt.get_access_token() ticket= dt.get_jsapi_ticket() noncestr = 'dingtalk' _logger.info(http.request.httprequest.url) sign = dt.sign(ticket,noncestr,now,http.request.httprequest.url) _logger.info(ticket) config = { 'nonceStr': noncestr, 'agentId' : agentid, 'timeStamp':now, 'corpId':corpid, 'signature' :sign } _logger.info(config) return http.request.render('dingtalk.home',config)
Example #17
Source File: routing.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def make_redirect_url(self, path_info, query_args=None, domain_part=None): """Creates a redirect URL. :internal: """ suffix = '' if query_args: suffix = '?' + self.encode_query_args(query_args) return str('%s://%s/%s%s' % ( self.url_scheme or 'http', self.get_host(domain_part), posixpath.join(self.script_name[:-1].lstrip('/'), path_info.lstrip('/')), suffix ))
Example #18
Source File: routing.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def bind(self, server_name, script_name=None, subdomain=None, url_scheme='http', default_method='GET', path_info=None, query_args=None): """Return a new :class:`MapAdapter` with the details specified to the call. Note that `script_name` will default to ``'/'`` if not further specified or `None`. The `server_name` at least is a requirement because the HTTP RFC requires absolute URLs for redirects and so all redirect exceptions raised by Werkzeug will contain the full canonical URL. If no path_info is passed to :meth:`match` it will use the default path info passed to bind. While this doesn't really make sense for manual bind calls, it's useful if you bind a map to a WSGI environment which already contains the path info. `subdomain` will default to the `default_subdomain` for this map if no defined. If there is no `default_subdomain` you cannot use the subdomain feature. .. versionadded:: 0.7 `query_args` added .. versionadded:: 0.8 `query_args` can now also be a string. """ server_name = server_name.lower() if self.host_matching: if subdomain is not None: raise RuntimeError('host matching enabled and a ' 'subdomain was provided') elif subdomain is None: subdomain = self.default_subdomain if script_name is None: script_name = '/' try: server_name = _encode_idna(server_name) except UnicodeError: raise BadHost() return MapAdapter(self, server_name, script_name, subdomain, url_scheme, path_info, default_method, query_args)
Example #19
Source File: routing.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def get_response(self, environ): return redirect(self.new_url, self.code)
Example #20
Source File: routing.py From jbox with MIT License | 5 votes |
def get_response(self, environ): return redirect(self.new_url, self.code)
Example #21
Source File: routing.py From PhonePi_SampleServer with MIT License | 5 votes |
def make_redirect_url(self, path_info, query_args=None, domain_part=None): """Creates a redirect URL. :internal: """ suffix = '' if query_args: suffix = '?' + self.encode_query_args(query_args) return str('%s://%s/%s%s' % ( self.url_scheme or 'http', self.get_host(domain_part), posixpath.join(self.script_name[:-1].lstrip('/'), path_info.lstrip('/')), suffix ))
Example #22
Source File: base.py From betterlifepsi with MIT License | 5 votes |
def details_view(self): """ Details model view with model specific can_view_details support. Whether the model detail could be viewed will be decided by model """ model, return_url = self.get_model_return_url() if model is not None and not model.can_view_details(): flash(gettext('You are not allowed to view detail of this object')) return redirect(return_url) return super(ModelViewWithAccess, self).details_view()
Example #23
Source File: base.py From betterlifepsi with MIT License | 5 votes |
def edit_view(self): """ Edit model view with model specific can_edit support Whether the model could be edit will be decided by model. """ model, return_url = self.get_model_return_url() if model is not None and not model.can_edit(): flash(gettext('You are not allowed to edit this object')) return redirect(return_url) return super(ModelViewWithAccess, self).edit_view()
Example #24
Source File: base.py From betterlifepsi with MIT License | 5 votes |
def _handle_view(self, name, **kwargs): """ Override builtin _handle_view in order to redirect users when a view is not accessible. """ if not self.is_accessible(): if current_user.is_authenticated: # permission denied abort(403) else: # login return redirect(url_for('security.login', next=request.url))
Example #25
Source File: index.py From betterlifepsi with MIT License | 5 votes |
def index(self): if not current_user.is_authenticated: return redirect(url_for_security('login')) return self.render('dashboard.html')
Example #26
Source File: webserver.py From nichtparasoup with MIT License | 5 votes |
def on_root(self, _: Request) -> Response: # relative-path is valid via https://tools.ietf.org/html/rfc3986#section-4.2 forward = redirect(self._STATIC_INDEX, code=302, Response=Response) # to prevent extensive (reverse proxy) header parsing, it is kept as a relative-path forward.autocorrect_location_header = False return forward
Example #27
Source File: routing.py From planespotter with MIT License | 5 votes |
def make_redirect_url(self, path_info, query_args=None, domain_part=None): """Creates a redirect URL. :internal: """ suffix = '' if query_args: suffix = '?' + self.encode_query_args(query_args) return str('%s://%s/%s%s' % ( self.url_scheme or 'http', self.get_host(domain_part), posixpath.join(self.script_name[:-1].lstrip('/'), path_info.lstrip('/')), suffix ))
Example #28
Source File: routing.py From jbox with MIT License | 5 votes |
def match(self, path): """Check if the rule matches a given path. Path is a string in the form ``"subdomain|/path(method)"`` and is assembled by the map. If the map is doing host matching the subdomain part will be the host instead. If the rule matches a dict with the converted values is returned, otherwise the return value is `None`. :internal: """ if not self.build_only: m = self._regex.search(path) if m is not None: groups = m.groupdict() # we have a folder like part of the url without a trailing # slash and strict slashes enabled. raise an exception that # tells the map to redirect to the same url but with a # trailing slash if self.strict_slashes and not self.is_leaf and \ not groups.pop('__suffix__'): raise RequestSlash() # if we are not in strict slashes mode we have to remove # a __suffix__ elif not self.strict_slashes: del groups['__suffix__'] result = {} for name, value in iteritems(groups): try: value = self._converters[name].to_python(value) except ValidationError: return result[str(name)] = value if self.defaults: result.update(self.defaults) if self.alias and self.map.redirect_defaults: raise RequestAliasRedirect(result) return result
Example #29
Source File: routing.py From planespotter with MIT License | 5 votes |
def bind(self, server_name, script_name=None, subdomain=None, url_scheme='http', default_method='GET', path_info=None, query_args=None): """Return a new :class:`MapAdapter` with the details specified to the call. Note that `script_name` will default to ``'/'`` if not further specified or `None`. The `server_name` at least is a requirement because the HTTP RFC requires absolute URLs for redirects and so all redirect exceptions raised by Werkzeug will contain the full canonical URL. If no path_info is passed to :meth:`match` it will use the default path info passed to bind. While this doesn't really make sense for manual bind calls, it's useful if you bind a map to a WSGI environment which already contains the path info. `subdomain` will default to the `default_subdomain` for this map if no defined. If there is no `default_subdomain` you cannot use the subdomain feature. .. versionadded:: 0.7 `query_args` added .. versionadded:: 0.8 `query_args` can now also be a string. """ server_name = server_name.lower() if self.host_matching: if subdomain is not None: raise RuntimeError('host matching enabled and a ' 'subdomain was provided') elif subdomain is None: subdomain = self.default_subdomain if script_name is None: script_name = '/' try: server_name = _encode_idna(server_name) except UnicodeError: raise BadHost() return MapAdapter(self, server_name, script_name, subdomain, url_scheme, path_info, default_method, query_args)
Example #30
Source File: dingtalk.py From odoo-dingtalk with GNU Lesser General Public License v3.0 | 5 votes |
def admin(self, **kw): code = kw.get('code'); if code: corpid = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_corpid') sso_secret = request.env['ir.values'].sudo().get_default('dingtalk.config.settings', 'dingtalk_sso_secret') if not corpid or not sso_secret: return redirect('/') dt = DingTalkClient(corpid,sso_secret) info = dt.get_sso_userinfo(code) _logger.info(info) return json.dumps(info) else: return redirect('/')