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 menu.append({ 41 'link': flask.url_for('coprs_ns.coprs_by_user', username=user.name), 42 'desc': user.name, 43 }) 44 45 menu.append({ 46 'link': flask.url_for('misc.logout'), 47 'desc': 'log out', 48 }) 49 50 else: 51 if config['FAS_LOGIN']: 52 menu.append({ 53 'link': flask.url_for('misc.login'), 54 'desc': 'log in', 55 }) 56 57 if config['KRB5_LOGIN']: 58 base = config['KRB5_LOGIN_BASEURI'] 59 for _, login in config['KRB5_LOGIN'].items(): 60 menu.append({ 61 'link': base + login['URI'], 62 'desc': login['log_text'], 63 }) 64 65 if config['FAS_LOGIN']: 66 menu.append({ 67 'link': 'https://admin.fedoraproject.org/accounts/user/new', 68 'desc': 'sign up', 69 }) 70 71 return dict(login_menu=menu)
72
73 @app.context_processor 74 -def counter_processor():
75 def counter(name): 76 if not 'counters' in flask.g: 77 flask.g.counters = {} 78 if not name in flask.g.counters: 79 flask.g.counters[name] = 0 80 81 flask.g.counters[name] += 1 82 return str(flask.g.counters[name])
83 84 return dict(counter=counter) 85