@app.before_request
def setup_g():
 uid = session.get('uid', None)
 if uid:
  g.user = Journalist.query.get(uid)
 if (request.method == 'POST'):
  sid = request.form.get('sid')
  if sid:
   g.sid = sid
   g.source = get_source(sid)

@ app . before_request def setup_g ( ) : uid = session . get ( 'uid' , None ) if uid : g . user = Journalist . query . get ( uid ) if ( request . method == 'POST' ) : sid = request . form . get ( 'sid' ) if sid : g . sid = sid g . source = get_source ( sid )
store commonly used values in flasks special g object .