-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This initial version is a complete Flask application ready to run locally or on ep.io. It's very barebones, though.
- Loading branch information
0 parents
commit 6513c4a
Showing
18 changed files
with
377 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,7 @@ | ||
.DS_Store | ||
*~ | ||
env | ||
env* | ||
*.pyc | ||
*.pyo | ||
.epio-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,8 @@ | ||
syntax: glob | ||
.DS_Store | ||
*~ | ||
env | ||
env/* | ||
*.pyc | ||
*.pyo | ||
.epio-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,22 @@ | ||
Copyright (c) 2011 Matthew Frazier | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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,20 @@ | ||
======================== | ||
Matthew's Flask Skeleton | ||
======================== | ||
This is a simple skeleton for Flask applications. It assumes that you want | ||
to use Flask with Flask-Script. The application layout that it sets up is | ||
fairly bare-bones, and doesn't include any databases, forms, or other fun | ||
stuff by default. | ||
|
||
It does, however, provide tooling for ep.io, in the form of an example | ||
`epio.ini` and a launcher called `epio_launcher.py`. | ||
|
||
To get started, just: | ||
|
||
1. Copy this somewhere. | ||
2. Rename `myapp` to the package name of your app. | ||
3. Change the package references in `manage.py` (also `epio.ini`). | ||
4. Edit the README and LICENSE files as appropriate. | ||
5. Add any extensions or packages you want to use to `requirements.txt`. | ||
6. Run `sh bootstrap.sh` to set up your virtual environment. | ||
7. Hack away! |
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,12 @@ | ||
# shell script for setting up environment | ||
# assuming you're using virtualenv and pip, of course ;-) | ||
# this is safe to run multiple times if you update requirements.txt | ||
# (though if you want the env rebuilt, you'll need to remove it) | ||
|
||
BASE=$(dirname $0) | ||
ENV=$BASE/env | ||
|
||
test ! -d $ENV && virtualenv --distribute --no-site-packages $ENV | ||
pip install -E $ENV -r $BASE/requirements.txt | ||
|
||
echo "== Bootstrap finished, use env/bin/activate to get started" |
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,17 @@ | ||
[wsgi] | ||
entrypoint = epio_launcher:app | ||
requirements = requirements.txt | ||
|
||
[launcher] | ||
package = myapp | ||
#config_file = production.cfg | ||
|
||
[services] | ||
#postgres = true | ||
#redis = true | ||
|
||
[static] | ||
/static = myapp/static/ | ||
|
||
#[redis] | ||
#memory = 16 |
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,39 @@ | ||
# Automatic ep.io launcher. This will configure some stuff for your app. | ||
# Note that this assumes it is in the same directory as your epio.ini. | ||
|
||
import os | ||
from bundle_config import config as service_config | ||
from ConfigParser import ConfigParser # ...I hate that name | ||
from os.path import join, dirname | ||
from werkzeug.utils import import_string | ||
|
||
EPIO_INI = join(dirname(__file__), "epio.ini") | ||
|
||
config = ConfigParser() | ||
config.read(EPIO_INI) | ||
|
||
factory_path = config.get("launcher", "package") + ":create_app" | ||
factory = import_string(factory_path) | ||
|
||
if config.has_option("launcher", "config_file"): | ||
config_file = config.get("launcher", "config_file") | ||
else: | ||
config_file = None | ||
|
||
extras = {} | ||
|
||
has_service = lambda svc: (config.has_option("services", svc) and | ||
config.getboolean("services", svc)) | ||
|
||
if has_service("postgres"): | ||
extras['SQLALCHEMY_DATABASE_URI'] = ( | ||
"postgresql://%(username)s:%(password)s@%(host)s:%(port)s/%(database)s" | ||
% service_config['postgres'] | ||
) | ||
|
||
if has_service("redis"): | ||
extras["REDIS_HOST"] = service_config['redis']['host'] | ||
extras["REDIS_PORT"] = service_config['redis']['port'] | ||
extras["REDIS_PASSWORD"] = service_config['redis']['password'] | ||
|
||
app = factory(config_file, extras) |
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,3 @@ | ||
from myapp.manager import manager | ||
|
||
manager.run() |
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,10 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
myapp | ||
===== | ||
This is an application that does cool stuff. | ||
:copyright: (C) 2011, Matthew Frazier | ||
:license: MIT/X11, see LICENSE for details | ||
""" | ||
from .application import create_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,37 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
myapp.application | ||
================= | ||
This is the main entry point for your app. It contains the app factory. | ||
:copyright: (C) 2011, Matthew Frazier | ||
:license: MIT/X11, see LICENSE for details | ||
""" | ||
from flask import Flask | ||
from .views import BLUEPRINTS | ||
|
||
def create_app(config=None, extras=None): | ||
# create application object | ||
app = Flask("myapp") | ||
|
||
# configure application | ||
app.config.from_object("myapp.defaults") | ||
if isinstance(config, dict): | ||
app.config.update(config) | ||
elif isinstance(config, str): | ||
app.config.from_pyfile(config) | ||
if isinstance(extras, dict): | ||
# extras is primarily for the use of the ep.io launcher | ||
app.config.update(extras) | ||
|
||
# setup extensions | ||
|
||
for blueprint in BLUEPRINTS: | ||
if isinstance(blueprint, tuple): | ||
app.register_blueprint(blueprint[0], url_prefix=prefix[1]) | ||
else: | ||
app.register_blueprint(blueprint) | ||
|
||
# template utilities, etc. | ||
|
||
return 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,22 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
myapp.defaults | ||
============== | ||
This contains the default settings for the application. (Copy this and delete | ||
the header, and you can use it as a config file.) | ||
:copyright: (C) 2011, Matthew Frazier | ||
:license: MIT/X11, see LICENSE for details | ||
""" | ||
|
||
#: Whether to run the application in debug mode or not. (Most of the time, | ||
#: this should be `False`. Running this with `True` in production is a HUGE | ||
#: security loophole.) | ||
DEBUG = False | ||
|
||
#: The secret key used to sign sessions. You can generate one with the command | ||
#: ``python -c "import os; print(repr(os.urandom(20)))"``. | ||
SECRET_KEY = 'Not actually secret' | ||
|
||
#: The name of the cookie used to store user sessions. | ||
SESSION_COOKIE_NAME = 'myapp_session' |
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,15 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
myapp.manager | ||
============= | ||
This contains commands for the management script. | ||
:copyright: (C) 2011, Matthew Frazier | ||
:license: MIT/X11, see LICENSE for details | ||
""" | ||
from flask import current_app | ||
from flaskext.script import Manager | ||
from .application import create_app | ||
|
||
manager = Manager(create_app) | ||
manager.add_option('-c', '--config', dest='config', required=False) |
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,75 @@ | ||
/* This stylesheet is borrowed from Ryshcate. */ | ||
|
||
/* Page layout */ | ||
body { | ||
color: black; | ||
background-color: white; | ||
font-family: 'Liberation Serif', 'Georgia', serif; | ||
font-size: 1.1em; | ||
} | ||
#container { | ||
width: 700px; | ||
margin: 20px auto; | ||
} | ||
header { | ||
margin-bottom: 20px; | ||
text-align: center; | ||
font-size: 1.4em; | ||
} | ||
header h1 { | ||
margin-bottom: 0px; | ||
padding-bottom: 0px; | ||
} | ||
footer { | ||
margin-top: 20px; | ||
text-align: right; | ||
font-size: 0.9em; | ||
font-color: #444; | ||
} | ||
nav { | ||
text-align: right; | ||
} | ||
nav a { | ||
text-decoration: none; | ||
} | ||
|
||
/* Text formatting */ | ||
a { | ||
color: #972; | ||
} | ||
a:visited { | ||
color: #641; | ||
} | ||
code, pre, textarea.code { | ||
font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', | ||
'Bitstream Vera Sans Mono', monospace !important; | ||
} | ||
pre { | ||
line-height: 1.25; | ||
} | ||
span.description { | ||
color: #888; | ||
font-size: smaller; | ||
} | ||
|
||
/* Flashes */ | ||
#flashes { | ||
margin: 8px auto; | ||
} | ||
p.flash { | ||
margin: 2px; | ||
padding: 4px; | ||
text-align: center; | ||
-webkit-border-radius: 5px; | ||
-moz-border-radius: 5px; | ||
border-radius: 5px; | ||
} | ||
.flash-message { | ||
background-color: #ff9; | ||
} | ||
.flash-error { | ||
background-color: #fcc; | ||
} | ||
.flash-success { | ||
background-color: #cfc; | ||
} |
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,9 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% set title = "Index" %} | ||
|
||
{% block body %} | ||
<h2>Hello, world!</h2> | ||
|
||
<p>This is an example template.</p> | ||
{% endblock body %} |
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,45 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>My Application - {{ title }}</title> | ||
<meta charset="utf-8"> | ||
<!--[if lt IE 9]> | ||
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | ||
<![endif]--> | ||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> | ||
{% block head %}{% endblock head %} | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<header> | ||
<h1>My Application</h1> | ||
</header> | ||
|
||
<nav> | ||
Your navigation goes here. | ||
</nav> | ||
|
||
{% with flashes = get_flashed_messages(with_categories=True) -%} | ||
{% if flashes -%} | ||
<div id="flashes"> | ||
{%- for category, message in flashes %} | ||
<p class="flash flash-{{category}}"> | ||
{{ message }} | ||
</p> | ||
{%- endfor %} | ||
</div> | ||
{%- endif %} | ||
{%- endwith %} | ||
|
||
<div id="content"> | ||
{% block body %}{% endblock body %} | ||
</div> | ||
|
||
<footer> | ||
<a href="http://flask.pocoo.org/"> | ||
<img src="http://flask.pocoo.org/static/badges/powered-by-flask-s.png" | ||
border="0" alt="powered by Flask" title="powered by Flask"> | ||
</a> | ||
</footer> | ||
</div> | ||
</body> |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
myapp.views | ||
=========== | ||
This package contains all of the application's blueprints. | ||
:copyright: (C) 2011, Matthew Frazier | ||
:license: MIT/X11, see LICENSE for details | ||
""" | ||
from .blueprint import blueprint | ||
|
||
#: The items of `BLUEPRINTS` should either be actual `Blueprint` objects or | ||
#: tuples of ``(blueprint, url_prefix)``. | ||
BLUEPRINTS = ( | ||
blueprint, | ||
) |
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,17 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
myapp.views.blueprint | ||
===================== | ||
This is an example of how your blueprints would look. | ||
:copyright: (C) 2011, Matthew Frazier | ||
:license: MIT/X11, see LICENSE for details | ||
""" | ||
import os | ||
from flask import Blueprint, request, render_template | ||
|
||
blueprint = Blueprint('blueprint', __name__) | ||
|
||
@blueprint.route('/') | ||
def index(): | ||
return render_template("index.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,3 @@ | ||
Flask>=0.8 | ||
Flask-Script | ||
# Add additional dependencies here. |