Skip to content

Commit

Permalink
cleanup and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchbregs committed Apr 1, 2020
1 parent a478f26 commit 32a87de
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 504 deletions.
19 changes: 9 additions & 10 deletions application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
from pathlib import Path

from flask import Flask
from werkzeug.utils import import_string

from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
from flask_login import LoginManager
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import MetaData
from werkzeug.utils import import_string

# Possible configurations
# TODO :: Make production the default at some point
# TODO: Make production the default at some point
config_dict = {
"production": "application.config.ProductionConfig",
"testing": "application.config.TestConfig",
Expand Down Expand Up @@ -50,27 +48,28 @@ def create_app(test_config=True):
admininstrator.init_app(app)
db.init_app(app)
db.app = app
# TODO :: `render_as_batch` only for SQLite..
# TODO: `render_as_batch` only for SQLite..
migrate.init_app(app, db, render_as_batch=True)
login_manager.init_app(app)

with app.app_context():

# Import the Admin views
from application.admin.admin_routes import add_admin_views

# Register Admin routes
add_admin_views(admininstrator)

# Import the the Blueprints
# (this has to happen inside the app context)
from application.home.home_routes import home_bp
from application.loggedin.loggedin_routes import loggedin_bp
from application.signup.signup_routes import signup_bp
from application.login.login_routes import login_bp
from application.admin.admin_routes import add_admin_views

# Register Blueprints
app.register_blueprint(home_bp, url_prefix='/')
app.register_blueprint(loggedin_bp)
app.register_blueprint(signup_bp)
app.register_blueprint(login_bp)

# Admin Handling
add_admin_views(admininstrator)

return app
2 changes: 1 addition & 1 deletion application/admin/admin_routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask_admin.contrib.sqla import ModelView
from flask_login import login_required

from application import db
from application.models import (
Expand All @@ -14,7 +15,6 @@
User,
UserLedger
)
from flask_login import login_required


def add_admin_views(administrator):
Expand Down
1 change: 1 addition & 0 deletions application/admin/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ arg1 }}
10 changes: 10 additions & 0 deletions application/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@ class LogInForm(FlaskForm):
)

submit = SubmitField('Log In')


class SearchForm(FlaskForm):
"""
Class to encapsulate search form
"""
text = StringField(
'Search terms',
validators=[DataRequired("Please enter your search terms.")]
)
11 changes: 6 additions & 5 deletions application/home/home_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
home_bp = Blueprint('home_bp', __name__, template_folder='templates')


@home_bp.route('/', methods=['GET', 'POST'])
@home_bp.route('/', methods=['GET'])
def home():
"""
Homepage route.
TODO :: This needs to be updated.
GET: Redirects user to their dashboard if they are already logged in.
"""

# redirect a user to their dashboard
# if they are alreday logged in
if current_user.is_authenticated:
return redirect(url_for('loggedin_bp.dashboard'))

Expand All @@ -25,11 +28,9 @@ def about():
"""
About page route.
TODO :: This needs to be updated.
TODO: This needs to be updated.
"""
return render_template(
'index.html',
title='About',
template='template main',
body="About"
)
5 changes: 0 additions & 5 deletions application/home/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{% extends "base.html" %}

{% block content %}

{% include "navigation-default.html" %}

<main role="main">
<section class="jumbotron text-center">
<div class="container">
Expand Down Expand Up @@ -100,7 +97,5 @@ <h1 class="jumbotron-heading">Bet smarter with groups.</h1>
</div>
</div>
</main>

{% include "footer-default.html" %}

{% endblock %}
11 changes: 8 additions & 3 deletions application/loggedin/loggedin_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
from flask_login import current_user, login_required

from application import login_manager
from application.forms import SearchForm

loggedin_bp = Blueprint('loggedin_bp', __name__, template_folder='templates')


@login_manager.unauthorized_handler
def unauthorized_callback():
"""Redirects an unaurhtorize user to login page."""
return redirect(url_for('login_bp.login'))


@loggedin_bp.route('/dashboard', methods=['GET', 'POST'])
@loggedin_bp.route('/dashboard', methods=['GET'])
@login_required
def dashboard():
"""
Dashboard route.
TODO :: This will be updated.
TODO: This will be updated.
"""
search_form = SearchForm()

return render_template(
'dashboard.html',
title='Dashboard'
title='Dashboard',
form=search_form
)
4 changes: 2 additions & 2 deletions application/loggedin/templates/dashboard-container-start.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div class="container-fluid">
<div class="row">
<div class="container-fluid">
<div class="row">
Loading

0 comments on commit 32a87de

Please sign in to comment.