summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalevi Yypänaho <kyypanah@local>2023-11-27 20:55:03 +0200
committerKalevi Yypänaho <kyypanah@local>2023-11-27 20:55:03 +0200
commitcbfd7ed7fb8c1bf4aefdcf77aa03d806011daf29 (patch)
tree20f668b774f643e1b472f5b8753c18aba301a81d
parentd74aca91c689b54b7b49bbfa7121f458f4caf751 (diff)
DB_URI and SECRET has now defaults in app.py. Added venv install instructions.
-rw-r--r--README.md30
-rw-r--r--app.py14
2 files changed, 31 insertions, 13 deletions
diff --git a/README.md b/README.md
index c3c090e..f137c82 100644
--- a/README.md
+++ b/README.md
@@ -3,28 +3,36 @@
TO GET IT RUNNING:
-[Note that quide in the course material works as well]<https://hy-tsoha.github.io/materiaali/aikataulu/>
-
Install postgresql for local user & get it running (as in course material)
- $ wget https://github.com/hy-tsoha/local-pg/raw/master/pg-install.sh
- $ bash pg-install.sh
- $ postrgres &
-Install poetry if nessesary. (refer your distro)
-- $ pip install --user poetry
-- $ pipx install poetry
-
Clone the source & install poetry dependencies
- $ git clone https://github.com/triionhe/kyselma.git
- $ cd kyselma
-- $ export PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring (Just in case..)
-- $ poetry install --no-root
Get database ready
- $ psql < SCHEMA.sql (BE CAREFUL! This drops some tables.)
-Start the app in poetry virtual environment
-- $ SQLALCHEMY_DATABASE_URI="postgresql:///$USER" SECRET_KEY=29347884 poetry run flask run
+Either use (1) poetry or (2) venv to handle dependencies and run the app
+
+(1) Install poetry if nessesary. (refer your distro)
+- $ pip install --user poetry
+- $ pipx install poetry
+(1) Install dependencies
+- $ export PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring (Just in case..)
+- $ poetry install --no-root
+(1) Start the app in poetry virtual environment
+- $ poetry run flask run
+
+(2) Activate venv environment
+- $ python3 -m venv venv
+- $ source venv/bin/activate
+(2) Install dependencies with pip
+- $ pip install -r ./requirements.txt
+(2) Start the app
+- $ flask run
Surf to the webpage and start two sessions for better testing
- $ firefox http://localhost:5000/ http://127.0.0.1:5000/
@@ -36,6 +44,7 @@ There is ready made kyselmä named 'kysdemo' for testing.
DONE:
+- Tietoturvaseikat: CSRF suojaus
- Eniten ja vähiten yhdenmukaiset vastaajat
- Parempi ulkoasu
- Vastauksen ja luomisen aloittamisen yksinkertaistaminen
@@ -59,7 +68,6 @@ DONE:
TODO:
- Moderointi
-- Tietoturvaseikat?
...
Tarkoitus on luoda sivu jossa voi luoda kysymyksiä ja kyselyitä, joita
diff --git a/app.py b/app.py
index 2f3b965..3d8d5c7 100644
--- a/app.py
+++ b/app.py
@@ -1,10 +1,20 @@
+from secrets import token_hex
from flask import Flask
from os import getenv
from db_actions import db
app = Flask(__name__, static_url_path='')
-app.secret_key = getenv("SECRET_KEY")
-app.config["SQLALCHEMY_DATABASE_URI"] = getenv("SQLALCHEMY_DATABASE_URI")
+
+if db_uri := getenv("SQLALCHEMY_DATABASE_URI"):
+ app.config["SQLALCHEMY_DATABASE_URI"]=db_uri
+else:
+ app.config["SQLALCHEMY_DATABASE_URI"]="postgresql:///"
+
+if s_key := getenv("SECRET_KEY"):
+ app.secret_key = s_key
+else:
+ app.secret_key = token_hex()
+
db.init_app(app)
import routes.base