def __init__(self, *args, **kwargs): if not args: kwargs.setdefault('import_name', __name__) Flask.__init__(self, template_folder= "%s/templates" % dirname(__file__), *args, **kwargs) self.bs = Bootstrap(self) self.nav = Navigation() self.nav.init_app(self) self.nav.Bar('top', [ self.nav.Item('Home', 'index'), self.nav.Item('Responsables', 'responsables'), self.nav.Item('Usuarios', 'usuarios'), self.nav.Item('Impresoras', 'impresoras'), self.nav.Item('Impresiones', 'impresiones'), ]) # register the routes from the decorator for route, fn in registered_routes.items(): partial_fn = partial(fn, self) partial_fn.__name__ = fn.__name__ self.route(route)(partial_fn)
from flask import Flask, render_template, request from flask_navigation import Navigation from sendemailitem import send_simple_message app = Flask("AvoidTheBin") nav = Navigation(app) nav.Bar('top', [ nav.Item('Home', 'home'), nav.Item('List It', 'listit'), nav.Item('Listed', 'listed') ]) @app.route("/") def home(): return render_template("index.html") @app.route("/listit") def listit(): return render_template("listit.html") availableitems = [] def getuniquefood(): i = 0 x = [] while i < len(availableitems):
}, r"/listens/*": { "origins": ["http://silchesterplayers.org", "https://silchesterplayers.org"] }, r"/soundcounter/*": { "origins": ["http://silchesterplayers.org", "https://silchesterplayers.org"] }, r"/sp-post*": { "origins": ["http://silchesterplayers.org", "https://silchesterplayers.org"] }, r"/sp-entry": { "origins": ["http://silchesterplayers.org", "https://silchesterplayers.org"] } }) db = SQLAlchemy(app) login_manager = LoginManager() login_manager.init_app(app) nav = Navigation() nav.init_app(app) app.env_vars = env_vars from webapp import routes # db.create_all()
def create_app(config): """ App factory for Flask app. Setup of database, login, navbar and registering of blueprints :param config: :return: running flask app """ # create pvtool app = Flask('pvtool') app.config.from_object(config) # database db.init_app(app) # create db @app.before_first_request def create_db(): db.create_all() login_manager.init_app(app) login_manager.login_view = 'users.signin' login_manager.login_message = 'Bitte melden Sie sich an um diese Seite zu sehen.' login_manager.login_message_category = 'info' @login_manager.user_loader def load_user(userid): return User.query.filter(User.id == userid).first() bcrypt.init_app(app) @app.before_first_request def create_admin(): """register an admin user via command""" if len(db.session.query(User).filter( User.user_name == 'admin').all()) > 0: print(db.session.query(User).filter(User._rights == 'Admin').all()) print('There already is an admin!') return new_user = User('-', '-', '-', '-') new_user._rights = 'Admin' new_user.user_name = 'admin' new_user._password = '******' db.session.add(new_user) db.session.commit() print('created admin user') # allow rounding app.jinja_env.globals.update(round=round) # navigation nav = Navigation(app) nav.Bar('top', [ nav.Item('Home', 'main.home'), nav.Item('Photovoltaik an der FHNW', 'main.pv_at_fhnw'), nav.Item('Laborübung Photovoltaik', 'main.test', items=[ nav.Item('PV-Module', 'pv.pv_modules'), nav.Item('Messungen', 'measurement.measurements'), nav.Item('Data', 'data.data'), nav.Item('Benutzer', 'users.users'), ]), ]) # routes app.register_blueprint(main_routes) app.register_blueprint(pv_modules_routes) app.register_blueprint(measurement_routes) app.register_blueprint(data_routes) app.register_blueprint(users_routes) app.register_error_handler(404, page_not_found) app.register_error_handler(500, internal_server_error) return app
wc.to_file('static/' + topic + '.png') #imgg = Image.open('static/words.png') print(f'Here is the result of {number} tweets about #{topic}') def run(topic, number): tweets = get_raw_tweets(topic, number) tweets_strings = clean_tweets(tweets) plot_could(tweets_strings, topic, number) bio_app = Flask(__name__) nav = Navigation(bio_app) #endpoint means the name of the function as in def nav.Bar('top', [ nav.Item('Home', endpoint='index'), nav.Item('About Me', endpoint='resume') ]) @bio_app.route('/', methods=['GET', 'POST']) def index(): return render_template('index.html') @bio_app.route('/result', methods=['GET', 'POST']) def query():
LOG = getLogger(__name__) APP_ROOT_FOLDER = os.path.abspath(os.path.dirname(app_root.__file__)) MIGRATE_ROOT_FOLDER = os.path.abspath( os.path.join(APP_ROOT_FOLDER, 'migrations')) @listens_for(Pool, 'connect', named=True) def _on_connect(dbapi_connection, **_) -> None: """Set MySQL mode to TRADITIONAL on databases that don't set this automatically. Without this, MySQL will silently insert invalid values in the database, causing very long debugging sessions in the long run. http://www.enricozini.org/2012/tips/sa-sqlmode-traditional/ """ pass # !FIXME set this only when MYSQL database is used # LOG.debug('FIXME! Setting SQL Mode to TRADITIONAL.') # dbapi_connection.cursor().execute("SET SESSION sql_mode='TRADITIONAL'") db = SQLAlchemy() sentry = Sentry() babel = Babel() login_manager = LoginManager() navigation = Navigation() celery = Celery() redis = Redis() migrate = Migrate(directory=MIGRATE_ROOT_FOLDER) cache = Cache()
def create_app(): app = Flask(__name__) app.config.from_pyfile("../config.py") db.init_app(app) bcrypt.init_app(app) login_manager.init_app(app) mail.init_app(app) nav = Navigation(app) # Navbar visible to all nav.Bar('top', [ nav.Item('Home', 'auth.home'), nav.Item('Calls For Proposals', 'call_system.view_all_calls'), nav.Item('Register', 'auth.register'), nav.Item('Login', 'auth.login') ]) # Navbar for logged in users (researchers) nav.Bar('user', [ nav.Item('Home', 'auth.home'), nav.Item('Profile', 'profile.view'), nav.Item('Calls For Proposals', 'call_system.view_all_calls'), nav.Item('Logout', 'auth.logout') ]) # Navbar for logged in admins nav.Bar('admin', [ nav.Item('Home', 'admin.dashboard'), nav.Item('Calls For Proposals', 'admin.allCalls'), nav.Item('Make CFP', 'call_system.make_call'), nav.Item('Logout', 'auth.logout') ]) # Navbar for logged in reviewers nav.Bar( 'reviewer', [ nav.Item('Home', 'auth.home'), nav.Item('Calls For Proposals', 'call_system.view_all_calls'), #nav.Item('Proposal Submissions', 'call_system.view_proposal_submissions'), nav.Item('Logout', 'auth.logout') ]) nav.Bar('researcher', [ nav.Item('Home', 'auth.home'), nav.Item('Calls For Proposals', 'call_system.view_all_calls'), nav.Item('Proposal Submissions', 'call_system.researcher_view_initial_pending_submissions'), nav.Item('Logout', 'auth.logout') ]) from app.auth import auth app.register_blueprint(auth, url_prefix="/auth/") from app.profile import profile app.register_blueprint(profile, url_prefix="/profile/") from app.call_system import call_system app.register_blueprint(call_system, url_prefix="/calls/") from app.admin import admin app.register_blueprint(admin, url_prefix="/admin/") from app.reviewer import reviewer app.register_blueprint(reviewer, url_prefix="/reviewer/") with app.app_context(): db.create_all() configure_uploads(app, programme_docs) configure_uploads(app, proposal_templates) from app import commands app.cli.add_command(commands.db_cli) app.cli.add_command(commands.user_cli) from app import jinja_filters app.jinja_env.filters["whatInput"] = jinja_filters.whatInput return app
from flask import Blueprint, render_template, abort, request, flash, redirect, url_for from jinja2 import TemplateNotFound from flask_login import login_required from flask_navigation import Navigation from forms import AddBookForm from app import models import isbnlib admin_page = Blueprint('admin_page', __name__, template_folder='templates/admin') admin_nav = Navigation() admin_nav.Bar('top', [ admin_nav.Item('Dashboard', 'admin_page.index'), admin_nav.Item('Public', 'index'), admin_nav.Item('Logout', 'logout') ]) admin_nav.Bar('left', [ admin_nav.Item('Overview', 'admin_page.index'), admin_nav.Item('Books', 'admin_page.books'), admin_nav.Item('Authors', 'admin_page.index'), admin_nav.Item('Users', 'admin_page.index'), ]) @admin_page.route('/') @admin_page.route('/index') @login_required def index():