Coverage for control/topbar.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Topbar.
3* The current user
4* Login/out buttons
5* Logo and link to docs
6"""
8from config import Config as C, Names as N
9from control.html import HtmlElements as H
10from control.utils import pick as G, E
12CW = C.web
15URLS = CW.urls
16LOGIN = URLS[N.login]
17LOGOUT = URLS[N.logout]
18SLOGOUT = URLS[N.slogout]
19LOGO = URLS[N.logo]
20HELP = URLS[N.help]
21TECH = URLS[N.tech]
24class Topbar:
25 """Present the topbar on the interface.
27 It shows the current user, buttons to log in/out and a logo.
28 """
30 def __init__(self, context):
31 """## Initialization
33 Store the incoming information.
35 Parameters
36 ----------
37 context: object
38 See below.
39 """
41 self.context = context
42 """*object* A `control.context.Context` singleton.
43 """
45 def wrap(self):
46 """Wrap it all up."""
48 context = self.context
49 auth = context.auth
50 eppn = G(auth.user, N.eppn) if auth.authenticated() else N.public
51 eppnRep = H.span(eppn, cls="mono")
53 (identityRep, accessRep) = auth.credentials()
54 login = (
55 E
56 if auth.authenticated()
57 else (
58 auth.wrapTestUsers()
59 if auth.isDevel
60 else H.a(G(LOGIN, N.text), G(LOGIN, N.url), cls="button small loginout")
61 )
62 )
63 logout = (
64 H.join(
65 [
66 H.a(
67 G(LOGOUT, N.text), G(LOGOUT, N.url), cls="button small loginout"
68 ),
69 H.a(
70 G(SLOGOUT, N.text),
71 G(SLOGOUT, N.url),
72 cls="button small loginout",
73 title=G(SLOGOUT, N.title),
74 ),
75 ]
76 )
77 if auth.authenticated()
78 else E
79 )
80 techdoc = (
81 H.a(
82 G(TECH, N.text),
83 G(TECH, N.url),
84 target=N._blank,
85 cls="button medium help",
86 title=G(TECH, N.title),
87 )
88 )
89 userhelp = (
90 H.a(
91 G(HELP, N.text),
92 G(HELP, N.url),
93 target=N._blank,
94 cls="button medium help",
95 title=G(HELP, N.title),
96 )
97 )
98 return H.div(
99 [
100 H.div(
101 [
102 H.icon(N.devel) if auth.isDevel else E,
103 H.details(identityRep, eppnRep, "usereppn", cls="user"),
104 H.div(accessRep, cls="access"),
105 login,
106 logout,
107 ],
108 cls="headlinestart",
109 ),
110 H.div(
111 [
112 techdoc,
113 userhelp,
114 ],
115 cls="headlineend",
116 ),
117 H.img(
118 G(LOGO, N.src),
119 href=G(LOGO, N.url),
120 target=N._blank,
121 title=G(LOGO, N.text),
122 imgAtts=dict(height=G(LOGO, N.height)),
123 id="logo",
124 ),
125 ],
126 cls="headline",
127 )