Python module documentation and start work on SQL db.

Commit
fd1f3fba182efb1ff154dc24f2553601b28791fb
Author
blendoit <blendoit@gmail.com>
Author date
Committer
blendoit <blendoit@gmail.com>
Committer date
Changed files
Pipfile
index e28b64e9..a2204842 100644..100644
@@ -10,6 +10,7 @@
10 10 flask-wtf = "*"
11 11 uwsgi = "*"
12 12 flask-socketio = "*"
13 Added: flask-sqlalchemy = "*"
13 14
14 15 [requires]
15 16 python_version = "3.8"
Pipfile.lock
index 1e6bd411..0b33a961 100644..100644
@@ -1,7 +1,7 @@
1 1 {
2 2 "_meta": {
3 3 "hash": {
4 Removed: "sha256": "efc56d845e2a3dfa2fa6132963f17abed9e32f9efdc80d03898efdcd1c3d07a3"
4 Added: "sha256": "28f4a6fb6e08e2b08c8f9dd44c53ab851efd6b6883afe810ae0222d73176abf3"
5 5 },
6 6 "pipfile-spec": 6,
7 7 "requires": {
@@ -39,6 +39,14 @@
39 39 "index": "pypi",
40 40 "version": "==4.2.1"
41 41 },
42 Added: "flask-sqlalchemy": {
43 Added: "hashes": [
44 Added: "sha256:0078d8663330dc05a74bc72b3b6ddc441b9a744e2f56fe60af1a5bfc81334327",
45 Added: "sha256:6974785d913666587949f7c2946f7001e4fa2cb2d19f4e69ead02e4b8f50b33d"
46 Added: ],
47 Added: "index": "pypi",
48 Added: "version": "==2.4.1"
49 Added: },
42 50 "flask-wtf": {
43 51 "hashes": [
44 52 "sha256:5d14d55cfd35f613d99ee7cba0fc3fbbe63ba02f544d349158c14ca15561cc36",
@@ -96,10 +104,10 @@
96 104 },
97 105 "python-engineio": {
98 106 "hashes": [
99 Removed: "sha256:50d108fc7feb7f970e6ebc86733752ebd714545bb5622383e6135bdad45fc9fe",
100 Removed: "sha256:f6bd466dea769bb19c59eaf8e68a296b195b6957650523f13a73d8c0767b7a38"
107 Added: "sha256:47ae4a9b3b4f2e8a68929f37a518338838e119f24c9a9121af92c49f8bea55c3",
108 Added: "sha256:c3a3822deb51fdf9c7fe4d78abf807c73b83ea538036a50862d3024450746253"
101 109 ],
102 Removed: "version": "==3.11.1"
110 Added: "version": "==3.11.2"
103 111 },
104 112 "python-socketio": {
105 113 "hashes": [
@@ -110,10 +118,16 @@
110 118 },
111 119 "six": {
112 120 "hashes": [
113 Removed: "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd",
114 Removed: "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"
121 Added: "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a",
122 Added: "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c"
115 123 ],
116 Removed: "version": "==1.13.0"
124 Added: "version": "==1.14.0"
125 Added: },
126 Added: "sqlalchemy": {
127 Added: "hashes": [
128 Added: "sha256:64a7b71846db6423807e96820993fa12a03b89127d278290ca25c0b11ed7b4fb"
129 Added: ],
130 Added: "version": "==1.3.13"
117 131 },
118 132 "uwsgi": {
119 133 "hashes": [
app/routes.py
index 46048272..6c7059a9 100644..100644
@@ -1,33 +1,60 @@
1 Added: """
2 Added: routes.py module
3 Added: ----------------
4 Added:
5 Added: This Python module contains the logic supporting:
6 Added: 1. Navigating between website pages
7 Added: 2. Interpreting user requests to the server
8 Added: 3. Dispatching requested content back to the user
9 Added:
10 Added: Python dependencies:
11 Added: - flask: provides web application features
12 Added: - forms: provides secure form user submission
13 Added: - sqlalchemy: provides communication with database on server.
14 Added:
15 Added: Personal imports:
16 Added: These are used to avoid cluttering this file with
17 Added: placeholder data for posts' content.
18 Added: """
1 19 from flask import Flask, render_template, flash, redirect, url_for
2 20 from forms import RegistrationForm, LoginForm
21 Added: from flask_sqlalchemy import SQLAlchemy
22 Added:
3 23 from placeholder_posts import posts
4 24 from placeholder_news import news
5 25 from placeholder_messages import messages
6 26
7 27 app = Flask(__name__)
8 28 app.config['SECRET_KEY'] = 'foobarblendoitfoobar!'
29 Added: app.config['SQLALCHEMY_DATABASE_URI'] = 'mariadb:///site.db'
9 30
31 Added: db = SQLAlchemy(app)
10 32
33 Added:
11 34 @app.route("/")
12 35 @app.route("/home")
13 36 def home():
37 Added: """This is our homepage."""
14 38 home_posts = posts + news + messages
15 39 return render_template('home.html', posts=home_posts)
16 40
17 41
18 42 @app.route("/yes")
19 43 def yes():
44 Added: """Another page, presenting the user with content marked as 'yes'."""
20 45 return render_template("yes.html", messages=messages, news=news)
21 46
22 47
23 48 @app.route("/no")
24 49 def no():
50 Added: """This page contains an archive of 'no's, for forgiving user mistakes."""
25 51 archives = posts + news + messages
26 52 return render_template("no.html", archive=archives)
27 53
28 54
29 55 @app.route("/register", methods=['GET', 'POST'])
30 56 def register():
57 Added: """Account registration page leveraging the form Python package."""
31 58 form = RegistrationForm()
32 59 if form.validate_on_submit():
33 60 flash(f"Alias created for {form.alias.data}.", 'success')
@@ -41,5 +68,12 @@
41 68 return render_template('login.html', title="Login", form=form)
42 69
43 70
71 Added: # If this file is executed as a script (i.e. double-clicked),
72 Added: # the Python interpreter will run the Flask process and begin serving
73 Added: # the web pages on the standard localhost address (127.0.0.1).
74 Added: # But if this file is called as a module by another Python script, it will not
75 Added: # serve content to the web pages, but the function definitions contained in
76 Added: # this file will be available to the calling script.
77 Added: # E.g. calling script will know what the yes() function is.
44 78 if __name__ == '__main__':
45 79 app.run(debug=True)