#from app import app from flask import Flask from flask_sqlalchemy import SQLAlchemy from db_classes import db, Request, Goal, Teacher, Schedule, WeekDay, Booking from data import * app = Flask(__name__) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( "DATABASE_URL") #"sqlite:///test.db" #db = SQLAlchemy(app) app.app_context().push() db.init_app(app) def init_db(db): test_id = db.session.query(Goal).get(list(goals.keys())[0]) if test_id is None: for goal_id, goal_name in goals.items(): # goals from data.py db.session.add(Goal(id=goal_id, name=goal_name)) db.session.commit() test_id = db.session.query(WeekDay).get("mon") if test_id is None: days = {"mon": (1, "Понедельник"), "tue": (2, "Вторник"), \ "wed": (3, "Среда"), "thu": (4, "Четверг"), "fri": (5, "Пятница"), \ "sat": (6, "Суббота"), "sun": (7, "Воскресенье")} for day in days:
from flask import Flask, request, render_template, redirect, url_for from flask_wtf import FlaskForm from wtforms import StringField, RadioField, HiddenField from wtforms.validators import InputRequired from flask_sqlalchemy import SQLAlchemy #from flask_migrate import Migrate from db_classes import db, Request, Goal, Teacher, Schedule, Booking app = Flask(__name__) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URL") app.secret_key = os.environ.get("SECRET_KEY") app.app_context().push() db.init_app(app) #SQLAlchemy(app) #migrate = Migrate(app, db) #import db_classes #from init_db import init_db #db.create_all() #db = init_db(db) #db.session.commit() @app.route("/") def render_main(): goals = {goal.id: goal.name for goal in db.session.query(Goal).all()} teachers = db.session.query(Teacher).order_by(db.func.random()).limit(6) return render_template("index.html", goals=goals, teachers=teachers)
WTF_CSRF_ENABLED = True server.secret_key = os.urandom(999) #Environment/Debugging Mode Setting #ENV = 'production'/'development', single quotes needed server.config["ENV"] = 'development' server.config["DEBUG"] = True server.config["SQLALCHEMY_DATABASE_URI"] = None server.config["SQLALCHEMY_POOL_RECYCLE"] = 60 server.config['SQLALCHEMY_POOL_TIMEOUT'] = 20 server.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False server.config["PHOTO_UPLOAD_DIR"] = "../static/photos" server.config["STATIC_FOLDER"] = "../static/" db.init_app(server) ############################################################################################################# ############################################################################################################# ############################################################################################################# ############################################################################################################# ############################################################################################################# ############################################################################################################# ############################################################################################################# ############################################################################################################# @server.route("/", methods=["GET"]) @server.route("/home", methods=["GET"]) def index():
from flask import Flask, redirect, url_for, session, request,render_template,flash, abort from flask_login import UserMixin from flask_oauthlib.client import OAuth, OAuthException from flask_login import LoginManager, login_user ,current_user,login_required, logout_user from forms import TableManageForm from functools import wraps import subprocess from db_classes import Course, Exam, User, db, reset_table, update_schedule from download import scrape_artsci, scrape_engineering app = Flask(__name__) app.config.from_pyfile('config.py') #set as envar in local windows environment. # This doesn't seem to be specified by the werkzeug dispatcher middleware, and is necessary to prevent cookie clash app.config['APPLICATION_ROOT'] = '/admin' db.init_app(app) oauth = OAuth() oauth.init_app(app) lm = LoginManager(app) lm.login_view= 'login' google = oauth.remote_app( 'google', app_key = 'GOOGLE', request_token_params={ 'scope': 'email' }, base_url='https://www.googleapis.com/oauth2/v1/', request_token_url=None, access_token_method='POST',