Continuing to add correct documentation to components within the application
This commit is contained in:
parent
066659c266
commit
216d71c15d
@ -5,6 +5,10 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
class DatabaseController(ABC):
|
class DatabaseController(ABC):
|
||||||
|
""" Abstract Base Class to handle database access for each component
|
||||||
|
in the web app
|
||||||
|
"""
|
||||||
|
|
||||||
__data_dir = "./data/"
|
__data_dir = "./data/"
|
||||||
__db_name = "wmgzon.db"
|
__db_name = "wmgzon.db"
|
||||||
|
|
||||||
@ -15,6 +19,9 @@ class DatabaseController(ABC):
|
|||||||
__sqlitefile = __data_dir + __db_name
|
__sqlitefile = __data_dir + __db_name
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
""" Initialises the object and creates a connection to the local
|
||||||
|
DB on the server
|
||||||
|
"""
|
||||||
self._conn = None
|
self._conn = None
|
||||||
try:
|
try:
|
||||||
# Creates a connection and specifies a flag to parse all types
|
# Creates a connection and specifies a flag to parse all types
|
||||||
@ -28,13 +35,14 @@ class DatabaseController(ABC):
|
|||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
""" Object Destructor which kills the connection to the database """
|
||||||
if self._conn is not None:
|
if self._conn is not None:
|
||||||
self._conn.close()
|
self._conn.close()
|
||||||
|
|
||||||
""" Takes a dictionary of fields and returns the object
|
|
||||||
with those fields populated """
|
|
||||||
|
|
||||||
def new_instance(self, of: type, with_fields: Mapping[str, Any]):
|
def new_instance(self, of: type, with_fields: Mapping[str, Any]):
|
||||||
|
""" Takes a dictionary of fields and returns the object
|
||||||
|
with those fields populated
|
||||||
|
"""
|
||||||
obj = of.__new__(of)
|
obj = of.__new__(of)
|
||||||
for attr, value in with_fields.items():
|
for attr, value in with_fields.items():
|
||||||
setattr(obj, attr, value)
|
setattr(obj, attr, value)
|
||||||
@ -46,16 +54,28 @@ class DatabaseController(ABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def create(self):
|
def create(self):
|
||||||
|
""" Abstract method used to create a new record of a given
|
||||||
|
type within the database
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def read(self):
|
def read(self):
|
||||||
|
""" Abstract method used to read a record of a given
|
||||||
|
type from the database
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def update(self):
|
def update(self):
|
||||||
|
""" Abstract method used to update a record of a given
|
||||||
|
type within the database
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def delete(self):
|
def delete(self):
|
||||||
|
""" Abstract method used to delete record of a given
|
||||||
|
type from the database
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
""" The user controller to manage all of the user related endpoints
|
||||||
|
in the web app
|
||||||
|
"""
|
||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
|
|
||||||
from flask import render_template, redirect, request, session, flash
|
from flask import render_template, redirect, request, session, flash
|
||||||
@ -10,19 +13,17 @@ from hashlib import sha512
|
|||||||
# Blueprint to append user endpoints to
|
# Blueprint to append user endpoints to
|
||||||
blueprint = Blueprint("users", __name__)
|
blueprint = Blueprint("users", __name__)
|
||||||
|
|
||||||
|
|
||||||
# LOGIN FUNCTIONALITY
|
# LOGIN FUNCTIONALITY
|
||||||
# Function responsible for delivering the Login page for the site
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/login')
|
@blueprint.route('/login')
|
||||||
def display_login():
|
def display_login():
|
||||||
|
""" Function responsible for delivering the Login page for the site """
|
||||||
return render_template('index.html', content="login.html")
|
return render_template('index.html', content="login.html")
|
||||||
|
|
||||||
# Function responsible for handling logins to the site
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.post('/login')
|
@blueprint.post('/login')
|
||||||
def login():
|
def login():
|
||||||
|
""" Function to handle the backend processing of a login request """
|
||||||
database = UserController()
|
database = UserController()
|
||||||
user = database.read(request.form['username'])
|
user = database.read(request.form['username'])
|
||||||
error = None
|
error = None
|
||||||
@ -44,16 +45,15 @@ def login():
|
|||||||
|
|
||||||
|
|
||||||
# SIGNUP FUNCTIONALITY
|
# SIGNUP FUNCTIONALITY
|
||||||
# Function responsible for delivering the Signup page for the site
|
|
||||||
@blueprint.route('/signup')
|
@blueprint.route('/signup')
|
||||||
def display_signup():
|
def display_signup():
|
||||||
|
""" Function responsible for delivering the Signup page for the site """
|
||||||
return render_template('index.html', content="signup.html")
|
return render_template('index.html', content="signup.html")
|
||||||
|
|
||||||
# Function responsible for handling signups to the site
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.post('/signup')
|
@blueprint.post('/signup')
|
||||||
def signup():
|
def signup():
|
||||||
|
""" Function to handle the backend processing of a signup request """
|
||||||
database = UserController()
|
database = UserController()
|
||||||
|
|
||||||
# User already exists
|
# User already exists
|
||||||
@ -91,9 +91,9 @@ def signup():
|
|||||||
|
|
||||||
|
|
||||||
# SIGN OUT FUNCTIONALITY
|
# SIGN OUT FUNCTIONALITY
|
||||||
# Function responsible for handling logouts from the site
|
|
||||||
@blueprint.route('/logout')
|
@blueprint.route('/logout')
|
||||||
def logout():
|
def logout():
|
||||||
|
""" Function responsible for handling logouts from the site """
|
||||||
# Clear the current user from the session if they are logged in
|
# Clear the current user from the session if they are logged in
|
||||||
session.pop('user_id', None)
|
session.pop('user_id', None)
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
Loading…
Reference in New Issue
Block a user