def index(): #import shit providers = micawber.bootstrap_basic() add_oembed_filters(app, providers) #connect to db db_obj = connect_db('data.db') #assign cursor and connection to variables cur = db_obj[0] con = db_obj[1] #get list of all threads cur.execute('SELECT * FROM thread;') threads = cur.fetchall() #get original post belonging to each thread cur.execute('SELECT * FROM post WHERE id = 1 ;') posts = cur.fetchall() if request.method == 'POST': #grab form data subject = request.form['subjectLine'] comment = request.form['comment'] embed = request.form['embed'] if subject == "" or comment == "" or embed == "": return "need javascript" #get highest threadID cur.execute('SELECT MAX(id) FROM thread;') #current post is 1 higher threadID = cur.fetchone()[0] + 1 thread = [threadID, subject] #adds thread to the database by passing it the item cur.execute('insert into thread values(?,?)', thread) #create original post post = [1, threadID, strftime("%I:%M %B %d, %Y"), comment, embed] cur.execute('insert into post values(?,?,?,?,?)', post) #save the changes con.commit() con.close() return redirect(url_for('index')) con.close() return render_template('listthreads.html', threads=reversed(threads), posts=posts)
def index(): #import shit providers = micawber.bootstrap_basic() add_oembed_filters(app, providers) #connect to db db_obj = connect_db('data.db') #assign cursor and connection to variables cur = db_obj[0] con = db_obj[1] #get list of all threads cur.execute('SELECT * FROM thread;') threads = cur.fetchall() #get original post belonging to each thread cur.execute('SELECT * FROM post WHERE id = 1 ;') posts = cur.fetchall() if request.method == 'POST': #grab form data subject = request.form['subjectLine'] comment = request.form['comment'] embed = request.form['embed'] if subject == "" or comment == "" or embed =="": return "need javascript" #get highest threadID cur.execute('SELECT MAX(id) FROM thread;') #current post is 1 higher threadID = cur.fetchone()[0] + 1 thread = [threadID, subject] #adds thread to the database by passing it the item cur.execute('insert into thread values(?,?)',thread) #create original post post = [1, threadID, strftime("%I:%M %B %d, %Y"), comment, embed] cur.execute('insert into post values(?,?,?,?,?)',post) #save the changes con.commit() con.close() return redirect(url_for('index')) con.close() return render_template('listthreads.html', threads=reversed(threads), posts=posts)
def viewThread(threadID): #import shit providers = micawber.bootstrap_basic() add_oembed_filters(app, providers) #database shit db_obj = connect_db('data.db') cur = db_obj[0] con = db_obj[1] #get information about this thread cur.execute('SELECT * FROM thread WHERE id ='+threadID+';') threadInfo = cur.fetchall() title = threadInfo[0][1] #get original post belonging to each thread cur.execute('SELECT * FROM post WHERE threadID ='+threadID+';') posts = cur.fetchall() return render_template('viewthread.html',title=title, posts=posts)
def viewThread(threadID): #import shit providers = micawber.bootstrap_basic() add_oembed_filters(app, providers) #database shit db_obj = connect_db('data.db') cur = db_obj[0] con = db_obj[1] #get information about this thread cur.execute('SELECT * FROM thread WHERE id =' + threadID + ';') threadInfo = cur.fetchall() title = threadInfo[0][1] #get original post belonging to each thread cur.execute('SELECT * FROM post WHERE threadID =' + threadID + ';') posts = cur.fetchall() return render_template('viewthread.html', title=title, posts=posts)
def create_app(): app = Flask(__name__) app.debug = True #app.config.from_object('config') #app.config['SECRET_KEY'] = 'devkeytestibsvbdsvbsd' #app.config['DEBUG_TB_PANELS'] = ['flask_mongoengine.panels.MongoDebugPanel'] #app.config['MONGODB_SETTINGS'] = {'db': 'testing'} #toolbar = DebugToolbarExtension(app) #toolbar.init_app(app) #app.config['DISQUS_SECRET_KEY'] #app.config['DISQUS_PUBLIC_KEY'] #app.config['CKEDITOR_HEIGHT'] = 400 #app.config['CKEDITOR_FILE_UPLOADER'] = 'upload' #app.config['UPLOADED_PATH'] = basedir + '/uploads' add_oembed_filters(app, oembed_providers) app.config['SECRET_KEY'] = os.urandom(24) app.config['CKEDITOR_PKG_TYPE'] = 'full' app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False #app.config['THUMBNAIL_MEDIA_ROOT'] = '/home/www/media' #app.config['THUMBNAIL_MEDIA_URL'] = '/media/' app.config['MONGODB_SETTINGS'] = { 'db': 'testing', 'connect': False, } register_babel(app) register_jinjia_filters(app) init_login(app) register_blueprints(app) register_database(app) create_admin(app) Material(app) disq = Disqus(app) ckeditor = CKEditor(app) #thumb = Thumbnail(app) #csrf.init_app(app) return app
from database_setup import Base, Category, Item, User import httplib2 import json import requests # import random import string engine = create_engine('sqlite:///catalog.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() app = Flask(__name__) APP_PATH = os.path.dirname(os.path.abspath(__file__)) auth = HTTPBasicAuth() oembed_providers = bootstrap_basic() add_oembed_filters(app, oembed_providers) @auth.verify_password def verify_password(username_or_token, password): # check to see if it's a token first session = DBSession() user_id = User.verify_auth_token(username_or_token) if user_id: user = session.query(User).filter_by(id=user_id).one() else: user = session.query(User).filter_by(username=username_or_token).\ first() if not user or not user.verify_password(password): return False g.user = user
def shutdown_session(response): db.session.remove() return response app = create_app() app.config.from_object('config') mail = Mail(app) cloudinary = Cloudinary(app) cache = Cache(app) wtforms_json.init() bcrypt = Bcrypt() oembed_providers = bootstrap_basic() oembed_providers.register('http://www.ustream.tv/channel/\S+', Provider('http://www.ustream.tv/oembed')) add_oembed_filters(app, oembed_providers) from services.user_service import UserService user_service = UserService() login_manager = LoginManager() #login_manager.anonymous_user = Anonymous login_manager.login_view = "login" login_manager.login_message = u"Please log in to access this page." login_manager.refresh_view = "reauth"
import os, sys, traceback from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flaskext.markdown import Markdown from flask_moment import Moment from micawber.providers import bootstrap_basic from micawber.contrib.mcflask import add_oembed_filters txtweb = Flask(__name__) txtweb.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL'] db = SQLAlchemy(txtweb) migrate = Migrate(txtweb, db) moment = Moment(txtweb) Markdown(txtweb) oembed_providers = bootstrap_basic() add_oembed_filters(txtweb, oembed_providers) from txtweb import routes, models if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) print(port) txtweb.run(host="0.0.0.0", port=port)