from app import app app.add_template_global(str, 'str') app.run(debug=True)
# # print(dt) # return dt def get_sbdowndata(): data = db.session.query(db.func.count( machinesstate.id).label("count")).filter( db.and_( machinesstate.sj >= (datetime.now() + timedelta(days=-2)).strftime("%Y-%m-%d"), machinesstate.zt != "下载完成")).first() return data.count def get_sumlistbumen(bumen, jifen): bm = '' jf = 0 if bm != bumen: bm = bumen jf = 0 else: jf = jf + jifen return bumen app.add_template_global(get_parentmenu, 'get_parentmenu') app.add_template_global(get_var, 'get_varmenu') app.add_template_global(get_sbdowndata, 'sbcount') app.add_template_global(get_sumlistbumen, 'get_bmlist')
args = request.args.to_dict() # Scopes will be passed as mutliple args, and to_dict() will only # return one. So, we use getlist() to get all of the scopes. args['scopes'] = request.args.getlist('scopes') return_url = args.pop('return_url', None) if return_url is None: if 'previous_url' in session: return session['previous_url'] return request.referrer or '/' return return_url def static(path): return path.replace(APP_PATH, '') def resource(path): return path.replace(APP_STATIC, '') def absolute(path): return join(APP_PATH, path) app.add_template_global(static, name='static')
from functools import wraps from itertools import groupby import wtforms from flask import abort, g, render_template from flask_babelex import lazy_gettext as _ from flask_wtf import FlaskForm from app import app import db import localization app.add_template_global({}, 'main_menu_items') def main_menu_item(label): def decorator(func): app.jinja_env.globals['main_menu_items'][func.__name__] = label @wraps(func) def wrapper(*args, **kwargs): g.is_on_main_menu_item = True return func(*args, **kwargs) return wrapper return decorator @localization.route('/') @main_menu_item(_('Почетна'))
portfolio_samples = Assets(src="app/static/assets/portfolio/") portfolio_samples.load_asset(processing=portfolio_processing) @app.route('/') @app.route('/index') def index(): return render_template("blog.html", title="Blog", posts=posts.load_recent(10)) # Converting date from datetime to string app.add_template_global(lambda x: x.strftime("%Y %b %-d"), name="blog_date") @app.route('/blog') def blog(): return render_template("blog.html", title="Blog", posts=posts.load_recent(10)) @app.route('/portfolio') def portfolio(): return render_template("portfolio.html", title="Portfolio", samples=portfolio_samples.load_recent(10))
@staticmethod def save(user): session['logged_in'] = True session['user_id'] = user.id @staticmethod def crypt_password(password): return sha256_crypt.encrypt(password) @staticmethod def user(): if 'user_id' in session: return User.query.filter_by(id=session['user_id']).first() return False app.add_template_global(Auth, name='Auth') def is_logged_in(f): @wraps(f) def wrap(*args, **kwards): if Auth.check(): return f(*args, **kwards) else: flash('Unauthorized, Please login', 'danger') return redirect(url_for('login')) return wrap