def test_default_config_values(self): app = flask.Flask('missing-shelve-filename') app.config['SHELVE_FILENAME'] = self.tempfile.name init_app(app) cfg = app.config self.assertEqual(cfg['SHELVE_PROTOCOL'], None) self.assertEqual(cfg['SHELVE_WRITEBACK'], False) self.assertEqual(cfg['SHELVE_LOCKFILE'], self.tempfile.name + '.lock')
def setUp(self): self.tempfile = tempfile.NamedTemporaryFile() # shelve (anydbm) won't work with empty files. os.unlink(self.tempfile.name) app = flask.Flask('test-flask-shelve') app.debug = True app.config['SHELVE_FILENAME'] = self.tempfile.name @app.route('/setkey/', methods=['POST']) def setkey(): db = get_shelve() db['foo'] = 'bar' return db['foo'] @app.route('/getkey/') def getkey(): db = get_shelve('r') return db.get('foo', 'NOEXIST') init_app(app) self.app = app
def setUp(self): app.config['TESTING'] = True app.config['SHELVE_FILENAME'] = 'shelve.db' shelve.init_app(app) return app
#!/usr/bin/python #Judy Mai & Maia Ezratty from flask import Flask, request, url_for, render_template, session, redirect from flask.ext import shelve app = Flask(__name__) app.config["SHELVE_FILENAME"] = "shelve.db" app.secret_key = "my secret key" shelve.init_app(app) @app.route("/", methods=["GET", "POST"]) def home(): if "username" in session: return "<h2>You are logged in.</h2>" else: return redirect("login") @app.route("/register", methods=["GET", "POST"]) def register(): if "username" in session: return redirect("home") elif request.method == "GET": return render_template("register.html", message="") else: userlist = shelve.get_shelve() user = request.form["user"].encode("utf8") pw = request.form["pass"].encode("utf8")
#!/usr/bin/python from flask import Flask, request, url_for, render_template, session, redirect from flask.ext import shelve app = Flask(__name__) app.config["SHELVE_FILENAME"] = "shelve.db" app.secret_key = "my secret key" shelve.init_app(app) @app.route("/", methods = ["GET", "POST"]) def home(): if "username" in session: return "<h2>You are logged in.</h2>" else: return redirect("login") @app.route("/register", methods = ["GET", "POST"]) def register(): if "username" in session: return redirect("home") elif request.method == "GET": return render_template("register.html", message = "") else: userlist = shelve.get_shelve() user = request.form["user"] pw = request.form["pass"] if user in userlist: return render_template("register.html", message = "Username already taken.")
#Submitted by Christine and Glib from flask import Flask from flask import session,url_for,request,redirect,render_template from flask.ext import shelve import sqlite3, utils app = Flask(__name__) app.secret_key= 'my secret key' shelve.init_app(login) @app.route("/") def home(): if 'username' in session: page = """ <h1> This is the main page for %s</h1> <a href="/logout">Logout</a> """ return page%(session['username']) else: return "<h1> This is the Main Page. Welcome Everyone!!</h1>" <style type="text/css"> .my_content_container a { border-bottom: 1px solid #777777; border-left: 1px solid #000000; border-right: 1px solid #333333; border-top: 1px solid #000000; color: #000000; display: block;
# configuration DEBUG = True SECRET_KEY = 'FA4ataGsdgs' # Config encoding import sys reload(sys) sys.setdefaultencoding('utf8') # create our little application :) app = Flask(__name__) # create shelve db from flask.ext.shelve import init_app, get_shelve app.config['SHELVE_FILENAME'] = 'bioanalyzer/databases/shelve.db' init_app(app) # IMPORTS AFTER app -------- import bioanalyzer.process_signal # t = threading.Thread(target=bioanalyzer.process_signal.loadFile, args=("s",)) # Post to web in a thread # t.start() from bioanalyzer.db_functions import * # END_OF IMPORTS AFTER app -------- app.config.from_object(__name__) app.config.from_envvar('FLASKR_SETTINGS', silent=True) @app.route('/') def bioanalyzer(): return render_template('bioanalyzer.html')
from flask import Flask, flash, render_template, url_for, request, redirect, session from flask.ext import shelve import uuid retovoter = Flask(__name__) retovoter.secret_key = '\x9d\xa2\x03\x1d\xef\xa5JK"\x8czi_Y\xe6\xb2\xfa\x0c\xba\xa8xL\xaf\xd9' retovoter.config['SHELVE_FILENAME'] = 'votes.db' shelve.init_app(retovoter) @retovoter.route('/', methods=['GET', 'POST']) def home(): if request.method == 'POST': # Create new Season season_uuid = str(uuid.uuid4()) with shelve.get_shelve('c') as db: db[season_uuid] = {'users': set(), 'votes': [{}]} session['role'] = 'moderator' return url_for('vote', _external=True) + '?season=' + season_uuid return render_template('index.html') def user_id(): if 'user' not in session: session['user'] = str(uuid.uuid4()) return session['user']