def set_cookie(request, name, value): """Sets a cookie and redirects to cookie list.""" r = app.make_response(redirect(url_for('view_cookies'))) r.set_cookie(key=name, value=value, secure=secure_cookie(request)) return r
def test_redirect(url, code): kwargs = {'url': url} if code: kwargs['code'] = code response = redirect(**kwargs) assert response.status_code == (code or 302) assert response.headers['location'] == url
def set_cookie(request, name, value): """Sets a cookie and redirects to cookie list.""" r = app.make_response(redirect(url_for('view_cookies'))) r.set_cookie(key=name, value=value, secure=secure_cookie(request)) return r
def test_redirect(url, code): kwargs = {'url': url} if code: kwargs['code'] = code response = redirect(**kwargs) assert response.status_code == (code or 302) assert response.headers['location'] == url
def add_entry(request): if not request.session.get('logged_in'): app.abort(401) entry = Entry(title=request.form['title'], content=request.form['content']) db_session.insert(entry) db_session.commit() return redirect(app.url_for('show_entries'))
def absolute_redirect_n_times(request, n): """302 Redirects n times.""" n = int(n) assert n > 0 if n == 1: return redirect(app.url_for('view_get', _request=request, _external=True)) return _redirect(request, 'absolute', n, True)
def absolute_redirect_n_times(request, n): """302 Redirects n times.""" n = int(n) assert n > 0 if n == 1: return redirect( app.url_for('view_get', _request=request, _external=True)) return _redirect(request, 'absolute', n, True)
def set_cookies(request): """Sets cookie(s) as provided by the query string and redirects to cookie list. """ cookies = dict(request.args.items()) r = app.make_response(redirect(url_for('view_cookies'))) for key, value in cookies.items(): r.set_cookie(key=key, value=value, secure=secure_cookie(request)) return r
def delete_cookies(request): """Deletes cookie(s) as provided by the query string and redirects to cookie list. """ cookies = dict(request.args.items()) r = app.make_response(redirect(url_for('view_cookies'))) for key, value in cookies.items(): r.delete_cookie(key=key) return r
def set_cookies(request): """Sets cookie(s) as provided by the query string and redirects to cookie list. """ cookies = dict(request.args.items()) r = app.make_response(redirect(url_for('view_cookies'))) for key, value in cookies.items(): r.set_cookie(key=key, value=value, secure=secure_cookie(request)) return r
def delete_cookies(request): """Deletes cookie(s) as provided by the query string and redirects to cookie list. """ cookies = dict(request.args.items()) r = app.make_response(redirect(url_for('view_cookies'))) for key, value in cookies.items(): r.delete_cookie(key=key) return r
def login(request): error = None if request.method == 'POST': if request.form['username'] != USERNAME: error = 'Invalid username' elif request.form['password'] != PASSWORD: error = 'Invalid password' else: request.session['logged_in'] = True return redirect(app.url_for('show_entries')) return app.render_template('login.html', error=error, session=request.session)
def redirect_n_times(request, n): """302 Redirects n times.""" n = int(n) assert n > 0 absolute = request.args.get('absolute', 'false').lower() == 'true' if n == 1: return redirect( app.url_for('view_get', _request=request, _external=absolute)) if absolute: return _redirect(request, 'absolute', n, True) else: return _redirect(request, 'relative', n, False)
def redirect_n_times(request, n): """302 Redirects n times.""" n = int(n) assert n > 0 absolute = request.args.get('absolute', 'false').lower() == 'true' if n == 1: return redirect(app.url_for('view_get', _request=request, _external=absolute)) if absolute: return _redirect(request, 'absolute', n, True) else: return _redirect(request, 'relative', n, False)
def links(request, n): """Redirect to first links page.""" n = int(n) return redirect(url_for('link_page', n=n, offset=0))
def logout(request): request.session.pop('logged_in', None) return redirect(app.url_for('show_entries'))
def _redirect(request, kind, n, external): return redirect( url_for('{0}_redirect_n_times'.format(kind), n=n - 1, _external=external, _request=request))
def links(request, n): """Redirect to first links page.""" n = int(n) return redirect(url_for('link_page', n=n, offset=0))
def _redirect(request, kind, n, external): return redirect(url_for('{0}_redirect_n_times'.format(kind), n=n - 1, _external=external, _request=request))