Skip to content

Commit

Permalink
Merge pull request #27 from jpalazz2/develop
Browse files Browse the repository at this point in the history
Add logging infrastructure
  • Loading branch information
jpalazz2 committed Apr 1, 2016
2 parents e9f9f31 + 1ba24cd commit a508f75
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
29 changes: 22 additions & 7 deletions bikeshare_app/config.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
"""Module containing configurations for the flask server"""
from os import getenv
# TODO: Setup a logging environment
import logging


# pylint: disable=too-few-public-methods
class BaseConfig(object):
"""The base configuration that should be used in production"""
DEBUG = False
TESTING = False
MONGODB_SETTINGS = {'db': 'bikeshare'}
LOGGING_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
LOGGING_LOCATION = 'bikeshare.log'
LOGGING_LEVEL = logging.INFO


class TestingConfig(BaseConfig):
"""Configuration for running unit tests"""
DEBUG = False
TESTING = True
MONGODB_SETTINGS = {'db': 'bikeshare-test'}
LOGGING_LEVEL = logging.DEBUG


class DevelopmentConfig(BaseConfig):
"""The configuration that should be run during development"""
DEBUG = True
TESTING = True
MONGODB_SETTINGS = {'db': 'bikeshare-test'}
LOGGING_LEVEL = logging.DEBUG


CONFIG = {
"development": "bikeshare_app.config.DevelopmentConfig",
"testing": "bikeshare_app.config.TestingConfig",
"default": "bikeshare_app.config.BaseConfig"
'development': 'bikeshare_app.config.DevelopmentConfig',
'testing': 'bikeshare_app.config.TestingConfig',
'default': 'bikeshare_app.config.BaseConfig',
}


def configure_app(app):
"""Configure the app based on where it is deployed. First check for the
FLASK_ENVIRONMENT environment variable, fallback to the default
BaseConfig"""
config_name = getenv("FLASK_ENVIRONMENT", "default")
print(config_name)
config_name = getenv('FLASK_ENVIRONMENT', 'default')
app.config.from_object(CONFIG[config_name])
handler = logging.FileHandler(app.config['LOGGING_LOCATION'])
handler.setLevel(app.config['LOGGING_LEVEL'])
logging.getLogger().setLevel(app.config['LOGGING_LEVEL'])
formatter = logging.Formatter(app.config['LOGGING_FORMAT'])
handler.setFormatter(formatter)
app.logger.addHandler(handler)

21 changes: 14 additions & 7 deletions bikeshare_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def user_loader(email):
@app.route('/')
def index():
"""Return the index page for the app"""
app.logger.debug('Rendering index page')
return render_template('bikes.html',
bikes=ActiveShare.objects(available=True))


@app.route('/login', methods=['GET', 'POST'])
def login():
"""Page to both login and process logins"""
if request.method == 'GET':
# Allow user through if check passed, else log attempt and return home
return render_template('login.html')
Expand All @@ -54,16 +56,21 @@ def logout():
return redirect(url_for('index'))


# Admin page
# Display bike availabilities again. Ability to alter database info
@app.route('/admin')
@flask_login.login_required
def admin():
"""The admin page"""
return render_template('admin.html')
"""The admin page.
Display the bike availabilities again. Also add ability to alter
the DB's
"""
app.logger.debug('Rendering admin page')
# TODO Check user credentials for admin role
# Allow user through if check passed, else log attempt and return home
return render_template('admin.html')

@app.route('/request_bike/<user_email>/<int:bike_id>')
def request_bike():
@app.route("/request_bike/<user_email>/<int:bike_id>")
def request_bike(user_email, bike_id):
"""This endpoint is for requesting a bike"""
return 'Bike request'
app.logger.debug('User {} requesting bike {}'.format(user_email, bike_id))
return render_template('admin.html')

0 comments on commit a508f75

Please sign in to comment.