From 22a2ad8e86fc6e725acf9980891e1cbba162b3b6 Mon Sep 17 00:00:00 2001 From: Roosh S Date: Mon, 22 Jun 2020 18:16:10 +0500 Subject: [PATCH 1/2] added secret key for db --- configs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs.py b/configs.py index abc31f8e..1edf3e49 100644 --- a/configs.py +++ b/configs.py @@ -45,6 +45,8 @@ class Config: SQLALCHEMY_DATABASE_URI = f"postgresql://{pg_user}:{pg_pw}@{pg_host}:5432/{pg_db}" + SECRET_KEY = os.urandom(24) + ALGOLIA_APP_ID = algolia_app_id ALGOLIA_API_KEY = algolia_api_key INDEX_NAME = index_name From 2db3a6a9120528b0ed948d106d64eac7fb4ade68 Mon Sep 17 00:00:00 2001 From: Roosh S Date: Mon, 22 Jun 2020 18:48:44 +0500 Subject: [PATCH 2/2] added flask-admin --- app/admin.py | 14 +++++++++++++ poetry.lock | 53 +++++++++++++++++++++++++++++++++++++++++++------- pyproject.toml | 1 + run.py | 3 ++- 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 app/admin.py diff --git a/app/admin.py b/app/admin.py new file mode 100644 index 00000000..8a6bc567 --- /dev/null +++ b/app/admin.py @@ -0,0 +1,14 @@ +from flask_admin import Admin +from flask_admin.contrib.sqla import ModelView + +from app import db, app +from .models import Resource, Category, Language + + +def run_flask_admin(): + admin = Admin(app) + admin.add_view(ModelView(Resource, db.session)) + admin.add_view(ModelView(Category, db.session)) + admin.add_view(ModelView(Language, db.session)) + +# end diff --git a/poetry.lock b/poetry.lock index 03b1b245..a3d2c5ee 100644 --- a/poetry.lock +++ b/poetry.lock @@ -66,7 +66,7 @@ description = "Python package for providing Mozilla's CA Bundle." name = "certifi" optional = false python-versions = "*" -version = "2020.4.5.2" +version = "2020.6.20" [[package]] category = "main" @@ -170,6 +170,22 @@ dev = ["pytest", "coverage", "tox", "sphinx", "pallets-sphinx-themes", "sphinxco docs = ["sphinx", "pallets-sphinx-themes", "sphinxcontrib-log-cabinet", "sphinx-issues"] dotenv = ["python-dotenv"] +[[package]] +category = "main" +description = "Simple and extensible admin interface framework for Flask" +name = "flask-admin" +optional = false +python-versions = "*" +version = "1.5.6" + +[package.dependencies] +Flask = ">=0.7" +wtforms = "*" + +[package.extras] +aws = ["boto"] +azure = ["azure-storage-blob"] + [[package]] category = "main" description = "A Flask extension adding a decorator for CORS support" @@ -626,7 +642,7 @@ description = "Manage dynamic plugins for Python applications" name = "stevedore" optional = false python-versions = ">=3.6" -version = "2.0.0" +version = "2.0.1" [package.dependencies] pbr = ">=2.0.0,<2.1.0 || >2.1.0" @@ -672,6 +688,22 @@ version = "1.0.1" dev = ["pytest", "pytest-timeout", "coverage", "tox", "sphinx", "pallets-sphinx-themes", "sphinx-issues"] watchdog = ["watchdog"] +[[package]] +category = "main" +description = "A flexible forms validation and rendering library for Python web development." +name = "wtforms" +optional = false +python-versions = "*" +version = "2.3.1" + +[package.dependencies] +MarkupSafe = "*" + +[package.extras] +email = ["email-validator"] +ipaddress = ["ipaddress"] +locale = ["Babel (>=1.3)"] + [[package]] category = "main" description = "Backport of pathlib-compatible object wrapper for zip files" @@ -686,7 +718,7 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] testing = ["jaraco.itertools", "func-timeout"] [metadata] -content-hash = "d41009e836c6736fbd9a91f600aec3abcfb55aaa5091af8f09f62c6c16c5aab7" +content-hash = "d283d796e99e96ef776e688cc07b2be14d32cef57ce642c1aa20d09bce21c299" python-versions = "^3.7" [metadata.files] @@ -710,8 +742,8 @@ bandit = [ {file = "bandit-1.5.1.tar.gz", hash = "sha256:9413facfe9de1e1bd291d525c784e1beb1a55c9916b51dae12979af63a69ba4c"}, ] certifi = [ - {file = "certifi-2020.4.5.2-py2.py3-none-any.whl", hash = "sha256:9cd41137dc19af6a5e03b630eefe7d1f458d964d406342dd3edf625839b944cc"}, - {file = "certifi-2020.4.5.2.tar.gz", hash = "sha256:5ad7e9a056d25ffa5082862e36f119f7f7cec6457fa07ee2f8c339814b80c9b1"}, + {file = "certifi-2020.6.20-py2.py3-none-any.whl", hash = "sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41"}, + {file = "certifi-2020.6.20.tar.gz", hash = "sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3"}, ] cffi = [ {file = "cffi-1.14.0-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:1cae98a7054b5c9391eb3249b86e0e99ab1e02bb0cc0575da191aedadbdf4384"}, @@ -817,6 +849,9 @@ flask = [ {file = "Flask-1.1.2-py2.py3-none-any.whl", hash = "sha256:8a4fdd8936eba2512e9c85df320a37e694c93945b33ef33c89946a340a238557"}, {file = "Flask-1.1.2.tar.gz", hash = "sha256:4efa1ae2d7c9865af48986de8aeb8504bf32c7f3d6fdc9353d34b21f4b127060"}, ] +flask-admin = [ + {file = "Flask-Admin-1.5.6.tar.gz", hash = "sha256:68c761d8582d59b1f7702013e944a7ad11d7659a72f3006b89b68b0bd8df61b8"}, +] flask-cors = [ {file = "Flask-Cors-3.0.8.tar.gz", hash = "sha256:72170423eb4612f0847318afff8c247b38bd516b7737adfc10d1c2cdbb382d16"}, {file = "Flask_Cors-3.0.8-py2.py3-none-any.whl", hash = "sha256:f4d97201660e6bbcff2d89d082b5b6d31abee04b1b3003ee073a6fd25ad1d69a"}, @@ -1066,8 +1101,8 @@ sqlalchemy-utils = [ {file = "SQLAlchemy-Utils-0.36.6.tar.gz", hash = "sha256:7a7fab14bed80df065412bbf71a0a9b0bfeb4b7c111c2d9bffe57283082f3a6b"}, ] stevedore = [ - {file = "stevedore-2.0.0-py3-none-any.whl", hash = "sha256:471c920412265cc809540ae6fb01f3f02aba89c79bbc7091372f4745a50f9691"}, - {file = "stevedore-2.0.0.tar.gz", hash = "sha256:001e90cd704be6470d46cc9076434e2d0d566c1379187e7013eb296d3a6032d9"}, + {file = "stevedore-2.0.1-py3-none-any.whl", hash = "sha256:c4724f8d7b8f6be42130663855d01a9c2414d6046055b5a65ab58a0e38637688"}, + {file = "stevedore-2.0.1.tar.gz", hash = "sha256:609912b87df5ad338ff8e44d13eaad4f4170a65b79ae9cb0aa5632598994a1b7"}, ] urllib3 = [ {file = "urllib3-1.25.9-py2.py3-none-any.whl", hash = "sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115"}, @@ -1084,6 +1119,10 @@ werkzeug = [ {file = "Werkzeug-1.0.1-py2.py3-none-any.whl", hash = "sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43"}, {file = "Werkzeug-1.0.1.tar.gz", hash = "sha256:6c80b1e5ad3665290ea39320b91e1be1e0d5f60652b964a3070216de83d2e47c"}, ] +wtforms = [ + {file = "WTForms-2.3.1-py2.py3-none-any.whl", hash = "sha256:6ff8635f4caeed9f38641d48cfe019d0d3896f41910ab04494143fc027866e1b"}, + {file = "WTForms-2.3.1.tar.gz", hash = "sha256:861a13b3ae521d6700dac3b2771970bd354a63ba7043ecc3a82b5288596a1972"}, +] zipp = [ {file = "zipp-3.1.0-py3-none-any.whl", hash = "sha256:aa36550ff0c0b7ef7fa639055d797116ee891440eac1a56f378e2d3179e0320b"}, {file = "zipp-3.1.0.tar.gz", hash = "sha256:c599e4d75c98f6798c509911d08a22e6c021d074469042177c8c86fb92eefd96"}, diff --git a/pyproject.toml b/pyproject.toml index ad37c887..bd6f7943 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ uWSGI = "2.0.19.1" Werkzeug = "1.0.1" pyjwt = "^1.7.1" cryptography = "^2.9.2" +flask-admin = "^1.5.6" [tool.poetry.dev-dependencies] diff --git a/run.py b/run.py index cfe86401..71a2ab69 100644 --- a/run.py +++ b/run.py @@ -1,4 +1,4 @@ -from app import app, cli +from app import app, cli, admin from app.models import Category, Language, Resource, db from werkzeug.middleware.dispatcher import DispatcherMiddleware from prometheus_client import make_wsgi_app @@ -8,6 +8,7 @@ app.run() cli.register(app, db) +admin.run_flask_admin() # Add prometheus wsgi middleware to route /metrics requests app_dispatch = DispatcherMiddleware(app, {