Mostly got this file passing flake8 tests
This commit is contained in:
parent
9074abd7ab
commit
9cae239994
@ -4,10 +4,8 @@ Simple Refstack website.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import random
|
from flask import Flask, abort, flash, request, redirect, url_for, \
|
||||||
import sqlite3
|
render_template, g, session
|
||||||
import sys
|
|
||||||
from flask import Flask, abort, flash, request, redirect, url_for, render_template, g, session
|
|
||||||
from flask_openid import OpenID
|
from flask_openid import OpenID
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
from flask.ext.admin import Admin, BaseView, expose, AdminIndexView
|
from flask.ext.admin import Admin, BaseView, expose, AdminIndexView
|
||||||
@ -15,34 +13,34 @@ from flask.ext.admin.contrib.sqlamodel import ModelView
|
|||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from flask.ext.security import Security, SQLAlchemyUserDatastore, \
|
from flask.ext.security import Security, SQLAlchemyUserDatastore, \
|
||||||
UserMixin, RoleMixin, login_required
|
UserMixin, RoleMixin, login_required
|
||||||
|
from wtforms import Form, BooleanField, TextField, \
|
||||||
from wtforms import Form, BooleanField, TextField, PasswordField, validators
|
PasswordField, validators
|
||||||
from flask_mail import Mail
|
from flask_mail import Mail
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
app.config['MAILGUN_KEY'] = 'key-this-is-a-fake-key'
|
app.config['MAILGUN_KEY'] = 'key-7o9l9dupikfpsdvqi0ewot-se8g1hz64'
|
||||||
app.config['MAILGUN_DOMAIN'] = 'hastwoparents.com'
|
app.config['MAILGUN_DOMAIN'] = 'hastwoparents.com'
|
||||||
|
|
||||||
|
|
||||||
app.config['SECRET_KEY'] = 'GIANT_UGLY-SECRET-GOES-H3r3'
|
app.config['SECRET_KEY'] = 'GIANT_UGLY-SECRET-GOES-H3r3'
|
||||||
db_path = os.path.abspath(os.path.join(os.path.basename(__file__), "../"))
|
db_path = os.path.abspath(
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:///%s/refstack.db' % (db_path))
|
os.path.join(os.path.basename(__file__), "../"))
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
|
||||||
|
'DATABASE_URL', 'sqlite:///%s/refstack.db' % (db_path))
|
||||||
app.config['DEBUG'] = True
|
app.config['DEBUG'] = True
|
||||||
|
|
||||||
app.config['SECURITY_PASSWORD_HASH'] = 'sha512_crypt'
|
app.config['SECURITY_PASSWORD_HASH'] = 'sha512_crypt'
|
||||||
app.config['SECURITY_PASSWORD_SALT'] = app.config['SECRET_KEY']
|
app.config['SECURITY_PASSWORD_SALT'] = app.config['SECRET_KEY']
|
||||||
app.config['SECURITY_POST_LOGIN_VIEW'] = 'dashboard'
|
app.config['SECURITY_POST_LOGIN_VIEW'] = 'dashboard'
|
||||||
app.config['SECURITY_RECOVERABLE'] = True
|
app.config['SECURITY_RECOVERABLE'] = True
|
||||||
app.config['SECURITY_REGISTERABLE'] = True
|
app.config['SECURITY_REGISTERABLE'] = True
|
||||||
app.config['SECURITY_EMAIL_SENDER'] = "admin@hastwoparents.com"
|
app.config['SECURITY_EMAIL_SENDER'] = "admin@hastwoparents.com"
|
||||||
|
|
||||||
app.config['MAIL_SERVER'] = 'smtp.mailgun.org'
|
app.config['MAIL_SERVER'] = 'smtp.mailgun.org'
|
||||||
app.config['MAIL_PORT'] = 465
|
app.config['MAIL_PORT'] = 465
|
||||||
app.config['MAIL_USE_SSL'] = True
|
app.config['MAIL_USE_SSL'] = True
|
||||||
app.config['MAIL_USERNAME'] = 'postmaster@hastwoparents.com'
|
app.config['MAIL_USERNAME'] = 'postmaster@hastwoparents.com'
|
||||||
app.config['MAIL_PASSWORD'] = 'ugly-password'
|
app.config['MAIL_PASSWORD'] = '0sx00qlvqbo3'
|
||||||
|
|
||||||
mail = Mail(app)
|
mail = Mail(app)
|
||||||
|
|
||||||
@ -59,12 +57,13 @@ class Vendor(db.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.vendor_name
|
return self.vendor_name
|
||||||
|
|
||||||
|
|
||||||
class Cloud(db.Model):
|
class Cloud(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
vendor_id = db.Column(db.Integer, db.ForeignKey('vendor.id'))
|
vendor_id = db.Column(db.Integer, db.ForeignKey('vendor.id'))
|
||||||
vendor = db.relationship('Vendor',
|
vendor = db.relationship('Vendor',
|
||||||
backref=db.backref('clouds', lazy='dynamic'))
|
backref=db.backref('clouds',
|
||||||
|
lazy='dynamic'))
|
||||||
endpoint = db.Column(db.String(120), unique=True)
|
endpoint = db.Column(db.String(120), unique=True)
|
||||||
test_user = db.Column(db.String(80), unique=True)
|
test_user = db.Column(db.String(80), unique=True)
|
||||||
test_key = db.Column(db.String(80), unique=True)
|
test_key = db.Column(db.String(80), unique=True)
|
||||||
@ -75,6 +74,7 @@ class Cloud(db.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.endpoint
|
return self.endpoint
|
||||||
|
|
||||||
|
|
||||||
class User(db.Model):
|
class User(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(60))
|
name = db.Column(db.String(60))
|
||||||
@ -89,8 +89,8 @@ class User(db.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
# IndexView = AdminIndexView(url="/")
|
admin = Admin(app)
|
||||||
admin = Admin(app) #, index_view=IndexView)
|
|
||||||
|
|
||||||
class SecureView(ModelView):
|
class SecureView(ModelView):
|
||||||
def is_accessible(self):
|
def is_accessible(self):
|
||||||
@ -103,15 +103,17 @@ admin.add_view(SecureView(User, db.session))
|
|||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def before_request():
|
def before_request():
|
||||||
|
"""Runs before the request it self"""
|
||||||
g.user = None
|
g.user = None
|
||||||
if 'openid' in session:
|
if 'openid' in session:
|
||||||
g.user = User.query.filter_by(openid=session['openid']).first()
|
g.user = User.query.filter_by(openid=session['openid']).first()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['POST','GET'])
|
@app.route('/', methods=['POST', 'GET'])
|
||||||
def index():
|
def index():
|
||||||
|
"""Index view"""
|
||||||
vendors = Vendor.query.all()
|
vendors = Vendor.query.all()
|
||||||
return render_template('index.html', vendors = vendors)
|
return render_template('index.html', vendors=vendors)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
@ -123,7 +125,8 @@ def login():
|
|||||||
# if we are already logged in, go back to were we came from
|
# if we are already logged in, go back to were we came from
|
||||||
if g.user is not None:
|
if g.user is not None:
|
||||||
return redirect(oid.get_next_url())
|
return redirect(oid.get_next_url())
|
||||||
return oid.try_login("https://login.launchpad.net/", ask_for=['email', 'nickname'])
|
return oid.try_login(
|
||||||
|
"https://login.launchpad.net/", ask_for=['email', 'nickname'])
|
||||||
# return render_template('login.html', next=oid.get_next_url(),
|
# return render_template('login.html', next=oid.get_next_url(),
|
||||||
# error=oid.fetch_error())
|
# error=oid.fetch_error())
|
||||||
|
|
||||||
@ -165,7 +168,8 @@ def create_profile():
|
|||||||
db.session.add(User(name, email, session['openid']))
|
db.session.add(User(name, email, session['openid']))
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(oid.get_next_url())
|
return redirect(oid.get_next_url())
|
||||||
return render_template('create_profile.html', next_url=oid.get_next_url())
|
return render_template(
|
||||||
|
'create_profile.html', next_url=oid.get_next_url())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/profile', methods=['GET', 'POST'])
|
@app.route('/profile', methods=['GET', 'POST'])
|
||||||
@ -203,7 +207,6 @@ def logout():
|
|||||||
return redirect(oid.get_next_url())
|
return redirect(oid.get_next_url())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.logger.setLevel('DEBUG')
|
app.logger.setLevel('DEBUG')
|
||||||
port = int(os.environ.get('PORT', 5000))
|
port = int(os.environ.get('PORT', 5000))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user