aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2021-06-07 13:59:24 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2021-06-07 13:59:24 +0530
commit11a2e1c778cf4b2ea958b6bdd7868c8604d45df2 (patch)
tree1db1b387a4d0f34831b6e88aeced59c89e604cd6 /app
parent3a708b304319afe84ebf3d40ecebabe6acc339f3 (diff)
added docstrings
Diffstat (limited to 'app')
-rw-r--r--app/views/admin.py18
-rw-r--r--app/views/error_pages.py17
-rw-r--r--app/views/main.py18
3 files changed, 48 insertions, 5 deletions
diff --git a/app/views/admin.py b/app/views/admin.py
index 5215f02..8588e87 100644
--- a/app/views/admin.py
+++ b/app/views/admin.py
@@ -1,3 +1,7 @@
+# -*- coding: utf-8 -*-
+"""
+SuperUser/Admin portal using flask-admin
+"""
from app import app, login_manager, db
from flask import render_template, flash, url_for, redirect
import flask_login
@@ -7,10 +11,20 @@ from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
admin = Admin(app, name="Admin", template_mode="bootstrap4")
-
+"""
+Initialised Admin Portal
+"""
class ModelView(ModelView): # skipcq: PYL-E0102
+ """
+ Our extended ModelView Class
+
+ Refer to Flask-Admin Docs for more details
+
+ https://flask-admin.readthedocs.io/en/latest/introduction/?highlight=ModelView#modelview-configuration-attributes
+ """
def is_accessible(self):
+ """This function checks if a user should be given access or not"""
try:
if flask_login.current_user.get_role() == "SUPERUSER":
return True
@@ -19,4 +33,4 @@ class ModelView(ModelView): # skipcq: PYL-E0102
return False
-admin.add_view(ModelView(User, db.session))
+admin.add_view(ModelView(User, db.session)) \ No newline at end of file
diff --git a/app/views/error_pages.py b/app/views/error_pages.py
index 1f066cc..ef40163 100644
--- a/app/views/error_pages.py
+++ b/app/views/error_pages.py
@@ -1,14 +1,25 @@
+# -*- coding: utf-8 -*-
+"""
+This file describes the errors and the message the user should see.
+"""
+
from app import app
from flask import render_template
@app.route("/Simulate500")
def simulate_500():
+ """
+ Used to simulate a error 500 for test coverage of 500 handling
+ """
return 500
@app.errorhandler(403)
def page_forbidden(e):
+ """
+ Thrown when a user accesses a page with @flask_login.login_required
+ """
return (
render_template(
"message.html", code=403, message="Forbidden. You shall not pass"
@@ -19,6 +30,9 @@ def page_forbidden(e):
@app.errorhandler(404)
def page_not_found(e):
+ """
+ Page for resource or file nout found
+ """
return (
render_template("message.html", code=404, message="Whoops! Page Not Found"),
404,
@@ -27,6 +41,9 @@ def page_not_found(e):
@app.errorhandler(500)
def page_server_error(e):
+ """
+ Page for internal server error
+ """
return (
render_template(
"message.html", code=500, message="Server Could Not Process This."
diff --git a/app/views/main.py b/app/views/main.py
index 85df723..d4d94e9 100644
--- a/app/views/main.py
+++ b/app/views/main.py
@@ -1,20 +1,32 @@
+# -*- coding: utf-8 -*-
+"""
+This is the main views module.
+
+You should import all other views into this file rather than individually importing in __init__.py
+"""
+
from app import app
from app.forms.app_forms import MyForm
from flask import render_template, flash
from app.views import auth, error_pages, admin
from app.misc_func import flash_errors
-theme = "original"
-
-
@app.route("/")
@app.route("/index")
def index():
+ """
+ The view for the landing page.
+ """
return render_template("index.html")
@app.route("/ContactUs", methods=["GET", "POST"])
def contact_us():
+ """
+ A simple contact us form with basic validation.
+
+ This dummy form has not been linked to any database.
+ """
form = MyForm()
if form.validate_on_submit():
return "Wuhu"