How to use the werkzeug.utils.redirect function in Werkzeug

To help you get started, we’ve selected a few Werkzeug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github odoo / odoo / addons / web / common / dispatch.py View on Github external
def dispatch(self, environ, start_response):
        """
        Performs the actual WSGI dispatching for the application, may be
        wrapped during the initialization of the object.

        Call the object directly.
        """
        request = werkzeug.wrappers.Request(environ)
        request.parameter_storage_class = werkzeug.datastructures.ImmutableDict

        if request.path == '/':
            return werkzeug.utils.redirect(
                self.root(dict(request.args, debug='')), 301)(
                    environ, start_response)
        elif request.path == '/mobile':
            return werkzeug.utils.redirect(
                '/web_mobile/static/src/web_mobile.html', 301)(
                environ, start_response)

        handler = self.find_handler(*(request.path.split('/')[1:]))

        if not handler:
            response = werkzeug.exceptions.NotFound()
        else:
            with http.session(request, self.session_storage, self.session_cookie) as session:
                result = handler(
                    request, self.config)

                if isinstance(result, basestring):
                    response = werkzeug.wrappers.Response(
                        result, headers=[('Content-Type', 'text/html; charset=utf-8'),
                                         ('Content-Length', len(result))])
github craws / OpenAtlas / openatlas / views / file.py View on Github external
def file_add(id_: int, class_name: str) -> Union[str, Response]:
    file = Entity.get_by_id(id_)
    if request.method == 'POST':
        if request.form['checkbox_values']:
            file.link_string('P67', request.form['checkbox_values'])
        return redirect(url_for('entity_view', id_=file.id) + '#tab-' + class_name)
    form = build_table_form(class_name, file.get_linked_entities('P67'))
    return render_template('file/add.html', entity=file, class_name=class_name, form=form)
github crosspop / asuka / asuka / web.py View on Github external
def decorated(request, *args, **kwargs):
        github_login = request.session.get('github_login')
        if github_login:
            request.context.github_login = github_login
            return function(request, *args, **kwargs)
        url = request.build_url('authorize', back=request.url, _external=True)
        return redirect(url)
    return decorated
github DocMarty84 / koozic / addons / web / controllers / main.py View on Github external
def web_client(self, s_action=None, **kw):
        ensure_db()
        if not request.session.uid:
            return werkzeug.utils.redirect('/web/login', 303)
        if kw.get('redirect'):
            return werkzeug.utils.redirect(kw.get('redirect'), 303)

        request.uid = request.session.uid
        try:
            context = request.env['ir.http'].webclient_rendering_context()
            response = request.render('web.webclient_bootstrap', qcontext=context)
            response.headers['X-Frame-Options'] = 'DENY'
            return response
        except AccessError:
            return werkzeug.utils.redirect('/web/login?error=access')
github craws / OpenAtlas / openatlas / views / admin.py View on Github external
def admin_check_link_duplicates(delete: Optional[str] = None) -> Union[str, Response]:
    if delete:
        delete_count = str(Link.delete_link_duplicates())
        logger.log('info', 'admin', 'Deleted duplicate links: ' + delete_count)
        flash(_('deleted links') + ': ' + delete_count, 'info')
        return redirect(url_for('admin_check_link_duplicates'))
    table = Table(['domain', 'range', 'property_code', 'description', 'type_id', 'begin_from',
                   'begin_to', 'begin_comment', 'end_from', 'end_to', 'end_comment', 'count'])
    for result in Link.check_link_duplicates():
        table.rows.append([link(Entity.get_by_id(result.domain_id)),
                           link(Entity.get_by_id(result.range_id)),
                           link(g.properties[result.property_code]),
                           result.description,
                           link(g.nodes[result.type_id]) if result.type_id else '',
                           format_date(result.begin_from),
                           format_date(result.begin_to),
                           result.begin_comment,
                           format_date(result.end_from),
                           format_date(result.end_to),
                           result.end_comment,
                           result.count])
    duplicates = False
github flectra-hq / flectra / addons / web / controllers / main.py View on Github external
url_redirect = url_redirect.replace(query=query_string)
        request.session.db = db
        abort_and_redirect(url_redirect)

    # if db not provided, use the session one
    if not db and request.session.db and http.db_filter([request.session.db]):
        db = request.session.db

    # if no database provided and no database in session, use monodb
    if not db:
        db = db_monodb(request.httprequest)

    # if no db can be found til here, send to the database selector
    # the database selector will redirect to database manager if needed
    if not db:
        werkzeug.exceptions.abort(werkzeug.utils.redirect(redirect, 303))

    # always switch the session to the computed db
    if db != request.session.db:
        request.session.logout()
        abort_and_redirect(request.httprequest.url)

    request.session.db = db
github AwesomeFoodCoops / odoo-production / odoo / addons / mail / controllers / main.py View on Github external
def _redirect_to_messaging(cls):
        messaging_action = request.env['mail.thread']._get_inbox_action_xml_id()
        url = '/web#%s' % url_encode({'action': messaging_action})
        return werkzeug.utils.redirect(url)
github matoous / newz / news / controllers / comments.py View on Github external
:return:
    """
    if comment.link.archived:
        abort(405)

    report_form = ReportForm()
    if report_form.validate():
        report = report_form.result()
        report.user_id = current_user.id
        report.feed_id = comment.link.feed.id

        comment.reports().save(report)
        comment.incr("reported", 1)

        flash("Thanks for your feedback!")
        return redirect(comment.link.route)

    return render_template(
        "report.html", thing=comment, feed=comment.link.feed, report_form=report_form
    )
github odoo / odoo / addons / survey / controllers / main.py View on Github external
survey_sudo, answer_sudo = access_data['survey_sudo'], access_data['answer_sudo']
        if not answer_sudo:
            # attempts to 'retry' without having tried first
            return werkzeug.utils.redirect("/")

        try:
            retry_answer_sudo = survey_sudo._create_answer(
                user=request.env.user,
                partner=answer_sudo.partner_id,
                email=answer_sudo.email,
                invite_token=answer_sudo.invite_token,
                **self._prepare_retry_additional_values(answer_sudo)
            )
        except:
            return werkzeug.utils.redirect("/")
        return request.redirect('/survey/start/%s?%s' % (survey_sudo.access_token, keep_query('*', answer_token=retry_answer_sudo.token)))