From ec15a652ff9732270c6bdac9d173503e5a9d940f Mon Sep 17 00:00:00 2001 From: Lex Date: Mon, 19 Feb 2024 16:12:18 +1000 Subject: [PATCH] Minor updates to docs and example --- docs/_static/styles.css | 2 ++ docs/conf.py | 35 ++++++++++++++++++++++++----------- docs/config.rst | 2 ++ examples/hello.py | 19 +++++++++++++++---- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/docs/_static/styles.css b/docs/_static/styles.css index 93db7784..6387b469 100644 --- a/docs/_static/styles.css +++ b/docs/_static/styles.css @@ -1,3 +1,5 @@ +@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400;1,700&family=Source+Code+Pro:ital,wght@0,400;0,700;1,400;1,700&display=swap'); + .padded { padding: 40px; } diff --git a/docs/conf.py b/docs/conf.py index 2e1acbee..97d33db2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -3,7 +3,9 @@ project = "Flask-Session" author = "Pallets Community Ecosystem" copyright = f"2014, {author}" -release = importlib.metadata.version("Flask-Session") +version = release = importlib.metadata.version("Flask-Session") + +# General -------------------------------------------------------------- extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx_favicon"] @@ -14,14 +16,9 @@ "flask-sqlalchemy": ("http://flask-sqlalchemy.palletsprojects.com/", None), } -html_theme = "furo" -html_static_path = ["_static"] -html_css_files = [ - "styles.css", - "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/fontawesome.min.css", - "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/solid.min.css", - "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/brands.min.css", -] + +# HTML ----------------------------------------------------------------- + favicons = [ {"rel": "icon", "href": "icon.svg", "type": "image/svg+xml"}, {"rel": "icon", "sizes": "16x16", "href": "favicon-16x16.png", "type": "image/png"}, @@ -50,16 +47,31 @@ "href": "safari-pinned-tab.svg", }, ] - - +html_copy_source = False +html_css_files = [ + "styles.css", + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/fontawesome.min.css", + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/solid.min.css", + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/brands.min.css", +] +html_domain_indices = False +html_static_path = ["_static"] +html_theme = "furo" html_theme_options = { + "source_repository": "https://github.com/pallets-eco/flask-session/", + "source_branch": "main", + "source_directory": "docs/", "light_logo": "logo/logo-light.png", "dark_logo": "logo/logo-dark.png", "light_css_variables": { + "font-stack": "'Atkinson Hyperlegible', sans-serif", + "font-stack--monospace": "'Source Code Pro', monospace", "color-brand-primary": "#39A9BE", "color-brand-content": "#39A9BE", }, "dark_css_variables": { + "font-stack": "'Atkinson Hyperlegible', sans-serif", + "font-stack--monospace": "'Source Code Pro', monospace", "color-brand-primary": "#39A9BE", "color-brand-content": "#39A9BE", }, @@ -86,3 +98,4 @@ }, ], } +html_use_index = False diff --git a/docs/config.rst b/docs/config.rst index 0e5b2c27..4f4c43b2 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -9,6 +9,8 @@ Configuration .. include:: config_security.rst +.. include:: config_exceptions.rst + .. include:: config_flask.rst .. include:: config_flask_session.rst diff --git a/examples/hello.py b/examples/hello.py index 07b3abd1..5aec16d6 100644 --- a/examples/hello.py +++ b/examples/hello.py @@ -1,11 +1,13 @@ from flask import Flask, session from flask_session import Session +from redis.exceptions import RedisError app = Flask(__name__) app.config.from_object(__name__) app.config.update( { "SESSION_TYPE": "redis", + "FLASK_ENV": "production", } ) Session(app) @@ -19,13 +21,22 @@ def set(): @app.route("/get/") def get(): - import time - - start_time = time.time() result = session.get("key", "not set") - print("get", (time.time() - start_time) * 1000) return result +@app.route("/delete/") +def delete(): + # del session["key"] + raise RedisError("test") + return "deleted" + + +@app.errorhandler(RedisError) +def handle_redis_error(error): + app.logger.error(f"Redis error encountered: {error}") + return "A problem occurred with our Redis service. Please try again later.", 500 + + if __name__ == "__main__": app.run(debug=True)