Skip to content
Permalink
Browse files

Initial commit setting up project

- Create default flask project
- Include auth and other basic routes
- Incorporate SQLAlchemy for data storage
- Setup views and basic templates
- Add bootstrap stylesheet dependency
- Add basic 404 page
- Setup unauthenticated request to GitHub API
- Create OAuth flow for GitHub API
- Update search ability
  • Loading branch information...
nlaz committed Jan 11, 2019
0 parents commit b8827f40377ec3e03ece9164c6f719ce49ffcec1
@@ -0,0 +1,7 @@
# Sample environment variables file.
FLASK_APP=starter/app.py
FLASK_ENV=development
DATABASE_URL="sqlite:////tmp/dev.db"
SECRET_KEY="octocat"
GITHUB_CLIENT_ID="<INSERT_CLIENT_ID>"
GITHUB_CLIENT_SECRET="<INSERT_CLIENT_SECRET>"
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# 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
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
@@ -0,0 +1,6 @@
include starter/schema.sql
graft starter/static
graft starter/templates
graft starter/models
graft starter/views
global-exclude *.pyc
@@ -0,0 +1 @@
web: gunicorn --bind 0.0.0.0:${PORT} starter.app:create_app\(\)
@@ -0,0 +1,15 @@
certifi==2018.11.29
chardet==3.0.4
Click==7.0
Flask==1.0.2
Flask-SQLAlchemy==2.3.2
gunicorn==19.9.0
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
python-dotenv==0.10.1
requests==2.21.0
SQLAlchemy==1.2.16
urllib3==1.24.1
Werkzeug==0.14.1
@@ -0,0 +1,12 @@
from setuptools import find_packages, setup

setup(
name='starter',
version='1.0.0',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=[
'flask',
],
)
@@ -0,0 +1 @@
"""Main application package"""
@@ -0,0 +1,44 @@
import os

from flask import Flask, render_template
from starter import settings, views, models, database

project_dir = os.path.dirname(os.path.abspath(__file__))
database_file = "sqlite:///{}".format(os.path.join(project_dir, "starter.db"))

def create_app(config_object=settings):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_object(config_object)
register_extensions(app)
register_blueprints(app)
register_errorhandlers(app)
return app

def register_extensions(app):
"""Register Flask extensions."""
database.init_app(app)
return None

def register_blueprints(app):
"""Register Flask blueprints."""
app.register_blueprint(views.public.blueprint)
app.register_blueprint(views.auth.blueprint)
app.register_blueprint(views.github.blueprint)
return None

def register_errorhandlers(app):
"""Register error handlers."""
@app.errorhandler(401)
def internal_error(error):
return render_template('401.html'), 401

@app.errorhandler(404)
def page_not_found(error):
return render_template('404.html'), 404

@app.errorhandler(500)
def internal_error(error):
return render_template('500.html'), 500

return None
@@ -0,0 +1,28 @@
import sqlite3

from flask_sqlalchemy import SQLAlchemy

import click
from flask import current_app, g
from flask.cli import with_appcontext

def get_db():
if 'db' not in g:
g.db = SQLAlchemy(current_app)

return g.db


def init_db():
db = get_db()
db.create_all()

@click.command('init-db')
@with_appcontext
def init_db_command():
"""Clear the existing data and create new tables."""
init_db()
click.echo('Initialized the database.')

def init_app(app):
app.cli.add_command(init_db_command)
@@ -0,0 +1 @@
"""Models package"""
@@ -0,0 +1,11 @@
from starter.db import get_db

db = get_db()

class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)
password = db.Column(db.String(120), nullable=False)

def __repr__(self):
return "<User: {}>".format(self.username)
@@ -0,0 +1,13 @@
"""Settings configuration."""

import os
from dotenv import load_dotenv

load_dotenv()

ENV = os.getenv('FLASK_ENV', default='production')
DEBUG = ENV == 'development'
SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL')
SECRET_KEY = os.getenv('SECRET_KEY')
GITHUB_CLIENT_ID = os.getenv('GITHUB_CLIENT_ID')
GITHUB_CLIENT_SECRET = os.getenv('GITHUB_CLIENT_SECRET')
No changes.
Binary file not shown.
@@ -0,0 +1 @@
/* Custom stylesheet */
@@ -0,0 +1,9 @@
{% extends 'layout.html' %}

{% block content %}
<div class='container py-5 my-5 text-muted text-center'>
<h1 class='h5'>This isn't the page you are looking for.</h1>
<p>We couldn't find this page. Please check your URL or go back home.<p>
<a href='/' class='btn btn-primary'>Go back home</a>
</div>
{% endblock %}
@@ -0,0 +1,9 @@
{% extends 'layout.html' %}

{% block content %}
<div class='container py-5 my-5 text-muted text-center'>
<h1 class='h5'>This isn't the page you are looking for.</h1>
<p>We couldn't find this page. Please check your URL or go back home.<p>
<a href='/' class='btn btn-primary'>Go back home</a>
</div>
{% endblock %}
@@ -0,0 +1,9 @@
{% extends 'layout.html' %}

{% block content %}
<div class='container py-5 my-5 text-muted text-center'>
<h1 class='h5'>This isn't the page you are looking for.</h1>
<p>We couldn't find this page. Please check your URL or go back home.<p>
<a href='/' class='btn btn-primary'>Go back home</a>
</div>
{% endblock %}
@@ -0,0 +1,27 @@
{% extends 'layout.html' %}

{% block content %}
<div class='container my-5 pt-5'>
<div class='row'>
<div class='col-md-6 offset-md-3 col-lg-4 offset-lg-4'>
<h1 class='h4'>Sign in to your account.</h1>
<form method="post" class='form-group'>
<div class='form-group'>
<label for="username" class='mb-0'><small class='font-weight-bold'>Username</small></label>
<input class='form-control' name="username" id="username" placeholder='Enter your username' required>
</div>
<div class='form-group'>
<label for="password" class='mb-0'><small class='font-weight-bold'>Password</small></label>
<input class='form-control' type="password" name="password" placeholder="Enter your password" id="password" required>
</div>
<button type="submit" class='btn btn-primary w-100'>Sign in</button>
</form>
<form action="{{ url_for('auth.githubLogin')}}" method="get">
<button type="submit" class='btn btn-dark w-100'>Sign in with GitHub</button>
</form>
<hr/>
<p class='text-muted text-center small'>Don't have an account? <a href="{{ url_for('auth.register') }}">Create an account</a>.
</div>
</div>
</div>
{% endblock %}
@@ -0,0 +1,27 @@
{% extends 'layout.html' %}

{% block content %}
<div class='container my-5 pt-5'>
<div class='row'>
<div class='col-md-6 offset-md-3 col-lg-4 offset-lg-4'>
<h1 class='h4'>Create an account.</h1>
<form method="post" class='form-group'>
<div class='form-group'>
<label for="username" class='mb-0'><small class='font-weight-bold'>Username</small></label>
<input class='form-control' name="username" id="username" placeholder='Pick a username' required>
</div>
<div class='form-group'>
<label for="password" class='mb-0'><small class='font-weight-bold'>Password</small></label>
<input class='form-control' type="password" name="password" id="password" placeholder='Create a password' required>
</div>
<button type="submit" class='btn btn-primary w-100'>Create account</button>
</form>
<form action="{{ url_for('auth.githubLogin')}}" method="get">
<button type="submit" class='btn btn-dark w-100'>Sign up with GitHub</button>
</form>
<hr/>
<p class='text-muted text-center small'>Already have an account? <a href="{{ url_for('auth.login') }}">Sign in here</a>.
</div>
</div>
</div>
{% endblock %}
@@ -0,0 +1,7 @@
{% for message in get_flashed_messages() %}
<div class="alert alert-danger mb-0 rounded-0">
<div class="container">
{{ message }}
</div>
</div>
{% endfor %}
@@ -0,0 +1,13 @@
<footer>
{% block footer %}
<div class='container text-muted my-2'>
<div class='d-flex flex-column flex-sm-row justify-content-between align-items-center'>
<small>Project Name © 2019</small>
<span>
<small><a href=''>Feedback</a></small>
<small><a href=''>GitHub</a></small>
</span>
</div>
</div>
{% endblock %}
</footer>

0 comments on commit b8827f4

Please sign in to comment.
You can’t perform that action at this time.