forked from lingthio/Flask-User-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit deff5cb
Showing
37 changed files
with
1,162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# | ||
# General Python settings (from https://github.com/github/gitignore) | ||
# | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
|
||
# | ||
# Application specific settings | ||
# | ||
.idea/ | ||
*.sqlite | ||
app/config/local_settings.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn runserver:app --log-file - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
Flask-User starter app | ||
======== | ||
|
||
This code base serves as a great starting point to write your next Flask application. | ||
|
||
|
||
**Development Feature set** | ||
|
||
* Modular and well-document directory structure with _readme.txt files. | ||
* Well-named source code files with lots of helpful comments. | ||
* Separate ``settings.py`` for general settings and ``local_settings.py`` for environment-specific settings. | ||
* Bootstrap3 base template that can easily be changed. | ||
* Complete with a skeleton for an automated test suite. | ||
|
||
It's a great starting point for new Flask applications -- whether you plan to use Flask-User or not. | ||
|
||
|
||
**Application Feature set** | ||
|
||
* Home page | ||
* User Profile page | ||
* User account management (Register, Confirm, Forgot password, | ||
Login, Change username, Change password, Logout) using Flask-User | ||
* SMTPHandler for error-level log messages -- sends emails on unhandled exceptions | ||
|
||
|
||
**Dependencies** | ||
|
||
* Flask | ||
* Flask-SQLAlchemy | ||
* Flask-User v0.6 and up (v0.5 does not support UserAuthClass) | ||
|
||
|
||
Installation | ||
-------- | ||
|
||
**Install git** | ||
|
||
See http://git-scm.com/book/en/Getting-Started-Installing-Git | ||
|
||
**Clone this github repository** | ||
|
||
Open a command line shell and type: | ||
|
||
:: | ||
|
||
mkdir -p ~/dev | ||
cd ~/dev | ||
git clone https://github.com/lingthio/Flask-User-starter-app.git my_app | ||
cd ~/dev/my_app | ||
|
||
**Install virtualenvwrapper** | ||
|
||
Install it with:: | ||
|
||
sudo pip install virtualenvwrapper | ||
|
||
Configure it with:: | ||
|
||
export WORKON_HOME=$HOME/.virtualenvs | ||
export PROJECT_HOME=$HOME/dev | ||
source /usr/local/bin/virtualenvwrapper.sh | ||
|
||
You may want to place the above in your .bashrc or .profile or .bash_profile file | ||
|
||
See http://virtualenvwrapper.readthedocs.org/en/latest/install.html | ||
|
||
**Create a new virtualenv** | ||
|
||
Find a Python 2.7 executable using ``python --version`` and ``which python``. | ||
|
||
Run this command once: | ||
|
||
:: | ||
|
||
mkvirtualenv -p /full/path/to/python2.7 my_app | ||
workon my_app | ||
|
||
where the result of ``which python`` can be used instead of ``/full/path/to/python2.7``, | ||
and where ``my_app`` is the name of the new virtualenv. | ||
|
||
**Install Fabric** | ||
|
||
Fabric is a build and deployment tool that uses the Python language for its scripts. | ||
Though the product name is 'Fabric', the command line tool is 'fab'. | ||
|
||
:: | ||
|
||
workon my_app | ||
pip install python-dev | ||
pip install python-setuptools | ||
pip install fabric | ||
|
||
See also: http://www.fabfile.org/installing.html | ||
|
||
**Install required Python packages** | ||
|
||
:: | ||
|
||
workon my_app | ||
cd ~/dev/my_app | ||
fab update_env | ||
|
||
**Initialize the Database** | ||
|
||
:: | ||
|
||
workon my_app | ||
cd ~/dev/my_app | ||
fab reset_db # Warning: This will delete all data in the database! | ||
|
||
**Update configuration settings** | ||
|
||
Before we can use this application, we will have to configure the database URL and SMTP account | ||
that will be used to access the database and to send emails. | ||
|
||
Instead of editing app/config/settings.py and checking in sensitive information into | ||
the code repository, these settings can be set using OS environment variables | ||
in your ``.bashrc`` or ``.bash_profile`` shell configuration file. | ||
|
||
:: | ||
|
||
export DATABASE_URL='sqlite:///app.sqlite' | ||
|
||
export MAIL_USERNAME='[email protected]' | ||
export MAIL_PASSWORD='password' | ||
export MAIL_DEFAULT_SENDER='MyApp" <[email protected]>' | ||
export MAIL_SERVER='smtp.gmail.com' | ||
export MAIL_PORT='465' | ||
export MAIL_USE_SSL='1' | ||
|
||
export ADMIN1='"Admin One" <[email protected]>' | ||
|
||
|
||
Running the app | ||
-------- | ||
|
||
**Start the development webserver** | ||
|
||
Flask comes with a convenient WSGI web application server for development environments. | ||
|
||
:: | ||
|
||
workon my_app | ||
cd ~/dev/my_app | ||
fab runserver | ||
|
||
Point your web browser to http://localhost:5000/ | ||
|
||
``fab reset_db`` will create one user with username 'admin' and password 'Password1'. | ||
|
||
|
||
Automated tests and code coverage | ||
-------- | ||
The tests are in the tests/ directory. | ||
|
||
pytest is used to run the automated tests. | ||
|
||
pytest is also used to run the code coverage assessment. | ||
|
||
:: | ||
|
||
workon my_app | ||
cd ~/dev/my_app | ||
fab test | ||
fab test_cov | ||
|
||
|
||
Acknowledgements | ||
-------- | ||
This project used `Flask-User-starter-app <https://github.com/lingthio/Flask-User-starter-app>`_ as a starting point. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# special Python file to turn a subdirectory into a Python 'package' | ||
# Python packages can be accessed using the Python 'import' statement | ||
|
||
# Intentionally left empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is the root directory of a Flask application. | ||
|
||
It contains the following Flask-specific subdirectories: | ||
- static # This subdirectory will be mapped to the "/static/" URL | ||
- templates # Jinja2 HTML template files | ||
|
||
It contains the following special App subdirectories: | ||
- config # Application setting files | ||
- startup # Application startup code | ||
|
||
The remaining subdirectories organizes the code into functional modules: | ||
- pages # Web pages (without a CMS for now) | ||
- users # User and Role related code | ||
|
||
Each functional models organizes code in the following way: | ||
- models.py # Database/Object models | ||
- views.py # Model-View functions that typically: | ||
# - Loads objects from the database | ||
# - Prepares a template data context | ||
# - Renders the context using a Jinja2 template file | ||
|
||
It contains the following Python-specific files: | ||
- __init__.py # special Python file to turn a subdirectory into a Python 'package' | ||
# Python packages can be accessed using the Python 'import' statement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This file declares the Flask Singletons 'app' and 'db' | ||
# 'app' and 'db' are defined in a separate file to avoid circular imports | ||
# Usage: from app.app_and_db import app, db | ||
# | ||
# Copyright 2014 SolidBuilds.com. All rights reserved | ||
# | ||
# Authors: Ling Thio <[email protected]> | ||
|
||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
# This is the WSGI compliant web application object | ||
app = Flask(__name__) | ||
|
||
# This is the SQLAlchemy ORM object | ||
db = SQLAlchemy(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# special Python file to turn a subdirectory into a Python 'package' | ||
# Python packages can be accessed using the Python 'import' statement | ||
|
||
# Intentionally left empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2014 SolidBuilds.com. All rights reserved | ||
# | ||
# Authors: Ling Thio <[email protected]> | ||
|
||
|
||
from flask import render_template | ||
from flask_user import login_required, roles_required | ||
|
||
from app.app_and_db import app | ||
|
||
|
||
# The Home page is accessible to anyone | ||
@app.route('/') | ||
def home_page(): | ||
return render_template('pages/home_page.html') | ||
|
||
# The Member page is accessible to authenticated users (users that have logged in) | ||
@app.route('/member') | ||
@login_required # Limits access to authenticated users | ||
def member_page(): | ||
return render_template('pages/member_page.html') | ||
|
||
# The Admin page is accessible to users with the 'admin' role | ||
@app.route('/admin') | ||
@roles_required('admin') # Limits access to users with the 'admin' role | ||
def admin_page(): | ||
return render_template('pages/admin_page.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# special Python file to turn a subdirectory into a Python 'package' | ||
# Python packages can be accessed using the Python 'import' statement | ||
|
||
# Intentionally left empty |
Oops, something went wrong.