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