Package coprs :: Module context_processors
[hide private]
[frames] | no frames]

Source Code for Module coprs.context_processors

 1  import os 
 2  from . import app 
 3  import flask 
 4   
 5  BANNER_LOCATION = "/var/lib/copr/banner-include.html" 
6 7 8 @app.context_processor 9 -def include_banner():
10 if os.path.exists(BANNER_LOCATION): 11 return {"copr_banner": open(BANNER_LOCATION).read()} 12 else: 13 return {}
14
15 16 @app.context_processor 17 -def inject_fedmenu():
18 """ Inject fedmenu url if available. """ 19 if 'FEDMENU_URL' in app.config: 20 return dict( 21 fedmenu_url=app.config['FEDMENU_URL'], 22 fedmenu_data_url=app.config['FEDMENU_DATA_URL'], 23 ) 24 return dict()
25
26 @app.context_processor 27 -def login_menu():
28 """ 29 Based on authentication configuration, construct the login menu links 30 to be placed at the top of each webui page. 31 """ 32 33 menu = [] 34 config = app.config 35 info = config['LOGIN_INFO'] 36 37 if flask.g.user: 38 # User authenticated. 39 user = flask.g.user 40 desc = " ({})".format(info['user_desc']) if 'user_desc' in info else '' 41 menu.append({ 42 'link': info['user_link'].format(username=user.name), 43 'desc': "{0}{1}".format(user.name, desc), 44 }) 45 46 menu.append({ 47 'link': flask.url_for('misc.logout'), 48 'desc': 'log out', 49 }) 50 51 else: 52 if config['FAS_LOGIN']: 53 menu.append({ 54 'link': flask.url_for('misc.login'), 55 'desc': 'log in', 56 }) 57 58 if config['KRB5_LOGIN']: 59 base = config['KRB5_LOGIN_BASEURI'] 60 for _, login in config['KRB5_LOGIN'].iteritems(): 61 menu.append({ 62 'link': base + login['URI'], 63 'desc': login['log_text'], 64 }) 65 66 if config['FAS_LOGIN']: 67 menu.append({ 68 'link': 'https://admin.fedoraproject.org/accounts/user/new', 69 'desc': 'sign up', 70 }) 71 72 return dict(login_menu=menu)
73