def _q_index(self): content = htmltext('') if not get_user(): content += htmltext('<p>%s</p>' % href('login', 'login')) else: content += htmltext( '<p>Hello, %s.</p>') % get_user() content += htmltext('<p>%s</p>' % href('logout', 'logout')) sessions = get_session_manager().items() if sessions: sessions.sort() content += htmltext('<table><tr>' '<th></th>' '<th>Session</th>' '<th>User</th>' '<th>Number of Requests</th>' '</tr>') this_session = get_session() for index, (id, session) in enumerate(sessions): if session is this_session: formatted_id = htmltext( '<span style="font-weight:bold">%s</span>' % id) else: formatted_id = id content += htmltext( '<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td>' % ( index, formatted_id, session.user or htmltext("<em>None</em>"), session.num_requests)) content += htmltext('</table>') return format_page("Quixote Session Management Demo", content)
def _q_index(self): content = htmltext('') if not get_user(): content += htmltext('<p>%s</p>' % href('login', 'login')) else: content += htmltext('<p>Hello, %s.</p>') % get_user() content += htmltext('<p>%s</p>' % href('logout', 'logout')) sessions = sorted([(s.id, s) for s in get_session_manager()]) if sessions: content += htmltext('<table><tr>' '<th></th>' '<th>Session</th>' '<th>User</th>' '<th>Number of Requests</th>' '</tr>') this_session = get_session() for index, (id, session) in enumerate(sessions): if session is this_session: formatted_id = htmltext( '<span style="font-weight:bold">%s</span>' % id) else: formatted_id = id content += htmltext( '<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td>' % (index, formatted_id, session.user or htmltext("<em>None</em>"), session.num_requests)) content += htmltext('</table>') return format_page("Quixote Session Management Demo", content)
def logout(self): if get_user(): content = htmltext('<p>Goodbye, %s.</p>') % get_user() else: content = htmltext('<p>That would be redundant.</p>') content += href("..", "start over") get_session_manager().expire_session() # This is the important part. return format_page("Quixote Session Demo: Logout", content)
def wrapper(root): user = get_user() if not user or not isinstance(user, self.valid_groups): root.resume = meth_name valid_groups = ", ".join(cls.__name__ for cls in self.valid_groups) return "You are trying to access a page restricted to %s. " % \ valid_groups + href("login", "Please login as a valid user.") else: return method(root)
def __init__(self, images): self.images = images self.links = [] for name in self.images: nospaces_name = name.replace(" ", "_") self._q_exports.append(nospaces_name) self.links.append(href(nospaces_name, name)) def imagesrc(name=name): return "<image src='file://%s'>" % os.path.join(imagedir, name) setattr(self, nospaces_name, imagesrc)
def login(self): content = htmltext('') if get_field("name"): session = get_session() session.set_user(get_field("name")) # This is the important part. content += htmltext( '<p>Welcome, %s! Thank you for logging in.</p>') % get_user() content += href("..", "go back") else: content += htmltext('<p>Please enter your name here:</p>\n' '<form method="POST" action="login">' '<input name="name" />' '<input type="submit" />' '</form>') return format_page("Quixote Session Demo: Login", content)
def login(self): content = htmltext('') if get_field("name"): session = get_session() session.set_user(get_field("name")) # This is the important part. content += htmltext( '<p>Welcome, %s! Thank you for logging in.</p>') % get_user() content += href("..", "go back") else: content += htmltext( '<p>Please enter your name here:</p>\n' '<form method="POST" action="login">' '<input name="name" />' '<input type="submit" />' '</form>') return format_page("Quixote Session Demo: Login", content)
def format_link_list(targets): return htmltext('<ul>%s</ul>') % htmltext('').join( [htmltext('<li>%s</li>') % href(target, target) for target in targets])
def check_href(self): assert str(href('/foo/bar', 'bar')) == '<a href="/foo/bar">bar</a>'
def format_link_list(targets): return htmltext('<ul>%s</ul>') % htmltext('').join([ htmltext('<li>%s</li>') % href(target, target) for target in targets])
def wrapper(root): user = get_user() if not user or not isinstance(user, self.valid_groups): root.resume = meth_name valid_groups = ", ".join(cls.__name__ for cls in self.valid_groups) return "You are trying to access a page restricted to %s. " % valid_groups + href( "login", "Please login as a valid user." ) else: return method(root)