def create_client(use_cdn=None, use_minified=None, responsive=None): app = flask.Flask(__name__) app.config['TESTING'] = True if use_cdn is not None: app.config['PURECSS_USE_CDN'] = use_cdn if use_minified is not None: app.config['PURECSS_USE_MINIFIED'] = use_minified if responsive is not None: app.config['PURECSS_RESPONSIVE_GRIDS'] = responsive Pure(app) @app.route('/') def index(): return flask.render_template('pure/layout.html') return app.test_client()
from flask import Flask, session, redirect, render_template, flash, request, url_for from flask_wtf import FlaskForm from wtforms import StringField, PasswordField from wtforms.validators import DataRequired, Email from werkzeug.security import generate_password_hash, check_password_hash from wtforms.fields.html5 import EmailField from flask_pure import Pure import sqlite3 as sql app = Flask(__name__) app.secret_key = 'super secret key' app.config['SESSION_TYPE'] = 'filesystem' Pure(app) class Sign(FlaskForm): username = StringField('username', validators=[DataRequired()]) email = EmailField("Email", [ DataRequired("Please enter your email address."), Email("Please enter your email address.") ]) password = PasswordField('password', validators=[DataRequired()]) @app.route('/sign') def sign(): form = Sign() return render_template('sign.html', form=form) @app.route('/save', methods=['POST', 'GET'])
def create_app(test_config=None): # create and configure the app app = Flask(__name__, instance_relative_config=True) # ensure the instance folder exists try: os.makedirs(app.instance_path) except OSError: pass # Handle configurtion app.config['SECRET_KEY'] = 'dev' app.config['HISTOANNOT_DELEGATE_DZI'] = False # Descriptive keys app.config['HISTOANNOT_PUBLIC_NAME'] = 'PICSL Histology Annotation System' # Read the config file if test_config is None: # load the instance config, if it exists, when not testing app.config.from_pyfile('config.py', silent=True) else: # load the test config if passed in app.config.from_mapping(test_config) # SERVER_NAME in Flask is a mess. It should only be set for dzi_node # (worker) instances, but avoid it for master instances, because it will # cause havoc with requests that refer to the server differently (by IP, etc) if not app.config.get('SERVER_NAME'): if app.config['HISTOANNOT_SERVER_MODE'] == 'dzi_node': # When server name is missing and we are on a worker node, this is # a problem. It is also a problem if we are running in command-line mode app.config['SERVER_NAME'] = gethostname() # DZI blueprint used in every mode app.register_blueprint(dzi.bp) dzi.init_app(app) # Set the default queues app.config['PRELOAD_QUEUE'] = "%s_preload" % (app.config.get( 'HISTOANNOT_REDIS_PREFIX', ''), ) # Server mode determines what we do next if app.config['HISTOANNOT_SERVER_MODE'] == "master": # Configure database app.config['DATABASE'] = os.path.join(app.instance_path, 'histoannot.sqlite') # Database connection db.init_app(app) # Auth commands auth.init_app(app) # Project CLI commands project_cli.init_app(app) # Auth blueprint app.register_blueprint(auth.bp) # Slide blueprint app.register_blueprint(slide.bp) slide.init_app(app) # Delegation blueprint app.register_blueprint(delegate.bp) delegate.init_app(app) # DLTrain blueprint app.register_blueprint(dltrain.bp) dltrain.init_app(app) # Pure CSS app.config['PURECSS_RESPONSIVE_GRIDS'] = True app.config['PURECSS_USE_CDN'] = True app.config['PURECSS_USE_MINIFIED'] = True Pure(app) app.add_url_rule('/', endpoint='index') # Enable hello world @app.route('/hello') def hello(): return 'HISTOANNOT MASTER' # Supporting 'dzi' node (serves images/tiles but no database) elif app.config['HISTOANNOT_SERVER_MODE'] == "dzi_node": # A master must be configured if 'HISTOANNOT_MASTER_URL' not in app.config: raise ValueError('Missing HISTOANNOT_MASTER_URL in config') # a simple page that says hello. This is needed for load balancers @app.route('/') def hello(): return 'HISTOANNOT DZI NODE' # Allow CORS headers app.after_request(_add_cors_headers) else: raise ValueError('Missing or unknown HISTOANNOT_SERVER_MODE') return app