Created
August 16, 2016 05:50
-
-
Save gisdev-km/9224e5f6720c90c2cef55fc4b887623f to your computer and use it in GitHub Desktop.
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
from flask import Flask, render_template | |
from flask_mail import Mail | |
from sqlalchemy import create_engine | |
from flask_sqlalchemy import SQLAlchemy | |
from flask_security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin, login_required | |
from datetime import datetime | |
# Main Flask App | |
app = Flask(__name__) | |
app.config['DEBUG'] = True | |
app.config['SECRET_KEY'] = 'super-secret' | |
# Database | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://sql8130559:b4AmN8EzZB@:3306/sql8130559?charset=utf8' | |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | |
app.config['SECURITY_REGISTERABLE'] = True | |
app.config['MAIL_SERVER'] = 'smtp.yandex.com' | |
app.config['MAIL_PORT'] = 465 | |
app.config['MAIL_USE_SSL'] = True | |
app.config['MAIL_USERNAME'] = '' | |
app.config['MAIL_PASSWORD'] = 'e58d' | |
app.config['SECURITY_EMAIL_SENDER'] = 'mo' | |
mail = Mail(app) | |
# Create database connection object | |
db = SQLAlchemy(app) | |
# Define models | |
db.Model.metadata.reflect(db.engine, only=["roles_users", "Role", "User", "do_1"]) # Assuming this actually exists in the database | |
class Role(db.Model): # Assuming this actually exists in the database | |
__table = db.model.metadata.tables["Role"] | |
def __repr__(self): | |
return self.id | |
class User(db.Model): | |
__table = db.model.metadata.tables["User"] | |
def __repr__(self): | |
return self.id | |
class do_1(db.Model): | |
__table = db.model.metadata.tables["do_1"] | |
def __repr__(self): | |
return self.id | |
# Setup Flask-Security | |
user_datastore = SQLAlchemyUserDatastore(db, User, Role) | |
security = Security(app, user_datastore) | |
# Views | |
@app.route('/') | |
@login_required | |
def home(): | |
return render_template('index.html') | |
@app.route("/topgroups") | |
@login_required | |
def topgroups(): | |
result = db.session.query(do_1).filter(do_1.AddDate < datetime.strftime("2016-08-09", "%Y-%M-%D")).limit(50).all() | |
return render_template("base.html", result = result) | |
@app.route("/sorted") | |
def sorted(): | |
return render_template("index.html", rows = rows) | |
if __name__ == "__main__": | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!!