-
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 bcaf70e
Showing
26 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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 @@ | ||
from flask import Flask | ||
from flask.ext.sqlalchemy import SQLAlchemy | ||
|
||
app = Flask(__name__) | ||
app.config.from_object('config') | ||
db = SQLAlchemy(app) | ||
|
||
from app import views, models |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 @@ | ||
from flask.ext.wtf import Form | ||
from wtforms import StringField, BooleanField | ||
from wtforms.validators import DataRequired | ||
|
||
|
||
class LoginForm(Form): | ||
openid = StringField('openid', validators=[DataRequired()]) | ||
remember_me = BooleanField('remember_me', default=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,9 @@ | ||
from app import db | ||
|
||
class User(db.Model): | ||
id = db.Column(db.Integer, primary_key = True) | ||
nickname = db.Column(db.String(64), index = True, unique = True) | ||
email = db.Column(db.String(120), index = True, unique = True) | ||
|
||
def __repr__(self): | ||
return '<User %r>' % (self.nickname) |
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,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
{% if title %} | ||
<title>{{title}} - microblog</title> | ||
{% else %} | ||
<title>microblog</title> | ||
{% endif %} | ||
</head> | ||
<body> | ||
<div>HelloFlask: <a href="/index">Home</a></div> | ||
<hr> | ||
{% with messages = get_flashed_messages() %} | ||
{% if messages %} | ||
<ul> | ||
{% for message in messages %} | ||
<li>{{ message }} </li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% endwith %} | ||
{% block content %}{% endblock %} | ||
</body> | ||
</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,7 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<h1>Hi, {{user.nickname}}!</h1> | ||
{% for post in posts %} | ||
<div><p>{{post.author.nickname}} says: <b>{{post.body}}</b></p></div> | ||
{% endfor %} | ||
{% endblock %} |
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,35 @@ | ||
<!-- extend from base layout --> | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<script type="text/javascript"> | ||
function set_openid(openid, pr) | ||
{ | ||
u = openid.search('<username>') | ||
if (u != -1) { | ||
// openid requires username | ||
user = prompt('Enter your ' + pr + ' username:') | ||
openid = openid.substr(0, u) + user | ||
} | ||
form = document.forms['login']; | ||
form.elements['openid'].value = openid | ||
} | ||
</script> | ||
<h1>Sign In</h1> | ||
<form action="" method="post" name="login"> | ||
{{ form.hidden_tag() }} | ||
<p> | ||
Please enter your OpenID, or select one of the providers below:<br> | ||
{{ form.openid(size=80) }} | ||
{% for error in form.openid.errors %} | ||
<span style="color: red;">[{{error}}]</span> | ||
{% endfor %}<br> | ||
|{% for pr in providers %} | ||
<a href="javascript:set_openid('{{ pr.url }}', '{{ pr.name }}');">{{ pr.name }}</a> | | ||
{% endfor %} | ||
</p> | ||
<p>{{ form.remember_me }} Remember Me</p> | ||
<p><input type="submit" value="Sign In"></p> | ||
</form> | ||
{% endblock %} | ||
|
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,36 @@ | ||
from flask import render_template, flash, redirect | ||
from app import app | ||
from .forms import LoginForm | ||
|
||
|
||
@app.route('/') | ||
@app.route('/index') | ||
def index(): | ||
user = {'nickname': 'Scott'} | ||
posts = [ # fake array of posts | ||
{ | ||
'author': {'nickname': 'Lucine'}, | ||
'body': 'My beautiful girlfriend!' | ||
}, | ||
{ | ||
'author': {'nickname': 'James'}, | ||
'body': 'The manager of Unigardens!' | ||
} | ||
] | ||
return render_template("index.html", | ||
title='Home', | ||
user=user, | ||
posts=posts) | ||
|
||
|
||
@app.route('/login', methods = ['GET', 'POST']) | ||
def login(): | ||
form = LoginForm() | ||
if form.validate_on_submit(): | ||
flash('Login requested for OpenID="' + form.openid.data + '", remember_me=' + str(form.remember_me.data)) | ||
return redirect('/index') | ||
return render_template('login.html', | ||
title='Sign In', | ||
form=form, | ||
providers=app.config['OPENID_PROVIDERS']) | ||
|
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 @@ | ||
import os | ||
basedir = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db') | ||
SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository') | ||
|
||
|
||
CSRF_ENABLED = True | ||
SECRET_KEY = 'password' | ||
|
||
OPENID_PROVIDERS = [ | ||
{ 'name': 'Google', 'url': 'https://www.google.com/accounts/o8/id' }, | ||
{ 'name': 'Yahoo', 'url': 'https://me.yahoo.com' }, | ||
{ 'name': 'AOL', 'url': 'http://openid.aol.com/<username>' }, | ||
{ 'name': 'Flickr', 'url': 'http://www.flickr.com/<username>' }, | ||
{ 'name': 'MyOpenID', 'url': 'https://www.myopenid.com' }] |
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 @@ | ||
#!flask/bin/python | ||
from migrate.versioning import api | ||
from config import SQLALCHEMY_DATABASE_URI | ||
from config import SQLALCHEMY_MIGRATE_REPO | ||
from app import db | ||
import os.path | ||
db.create_all() | ||
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO): | ||
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository') | ||
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) | ||
else: | ||
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO)) |
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 @@ | ||
#!flask/bin/python | ||
import imp | ||
from migrate.versioning import api | ||
from app import db | ||
from config import SQLALCHEMY_DATABASE_URI | ||
from config import SQLALCHEMY_MIGRATE_REPO | ||
migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1) | ||
tmp_module = imp.new_module('old_model') | ||
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) | ||
exec(old_model, tmp_module.__dict__) | ||
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata) | ||
open(migration, "wt").write(script) | ||
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) | ||
print('New migration saved as ' + migration) | ||
print('Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))) |
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 @@ | ||
This is a database migration repository. | ||
|
||
More information at | ||
http://code.google.com/p/sqlalchemy-migrate/ |
Empty file.
Binary file not shown.
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,5 @@ | ||
#!/usr/bin/env python | ||
from migrate.versioning.shell import main | ||
|
||
if __name__ == '__main__': | ||
main() |
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,25 @@ | ||
[db_settings] | ||
# Used to identify which repository this database is versioned under. | ||
# You can use the name of your project. | ||
repository_id=database repository | ||
|
||
# The name of the database table used to track the schema version. | ||
# This name shouldn't already be used by your project. | ||
# If this is changed once a database is under version control, you'll need to | ||
# change the table name in each database too. | ||
version_table=migrate_version | ||
|
||
# When committing a change script, Migrate will attempt to generate the | ||
# sql for all supported databases; normally, if one of them fails - probably | ||
# because you don't have that database installed - it is ignored and the | ||
# commit continues, perhaps ending successfully. | ||
# Databases in this list MUST compile successfully during a commit, or the | ||
# entire commit will fail. List the databases your application will actually | ||
# be using to ensure your updates to that database work properly. | ||
# This must be a list; example: ['postgres','sqlite'] | ||
required_dbs=[] | ||
|
||
# When creating new change scripts, Migrate will stamp the new script with | ||
# a version number. By default this is latest_version + 1. You can set this | ||
# to 'true' to tell Migrate to use the UTC timestamp instead. | ||
use_timestamp_numbering=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,19 @@ | ||
from sqlalchemy import * | ||
from migrate import * | ||
|
||
|
||
from migrate.changeset import schema | ||
pre_meta = MetaData() | ||
post_meta = MetaData() | ||
|
||
def upgrade(migrate_engine): | ||
# Upgrade operations go here. Don't create your own engine; bind | ||
# migrate_engine to your metadata | ||
pre_meta.bind = migrate_engine | ||
post_meta.bind = migrate_engine | ||
|
||
|
||
def downgrade(migrate_engine): | ||
# Operations to reverse the above upgrade go here. | ||
pre_meta.bind = migrate_engine | ||
post_meta.bind = migrate_engine |
Empty file.
Binary file not shown.
Binary file not shown.
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/bin/python | ||
from app import app | ||
app.run(debug=True) |