예제 #1
0
파일: altdemo.py 프로젝트: pganti/micheles
 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)
예제 #2
0
파일: altdemo.py 프로젝트: zhou0/quixote
 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)
예제 #3
0
파일: altdemo.py 프로젝트: zhou0/quixote
 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)
예제 #4
0
파일: altdemo.py 프로젝트: pganti/micheles
 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)
예제 #5
0
 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)
예제 #6
0
파일: viewer.py 프로젝트: pganti/micheles
    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)
예제 #7
0
파일: altdemo.py 프로젝트: zhou0/quixote
 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)
예제 #8
0
파일: altdemo.py 프로젝트: pganti/micheles
 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)
예제 #9
0
파일: altdemo.py 프로젝트: zhou0/quixote
def format_link_list(targets):
    return htmltext('<ul>%s</ul>') % htmltext('').join(
        [htmltext('<li>%s</li>') % href(target, target) for target in targets])
예제 #10
0
 def check_href(self):
     assert str(href('/foo/bar', 'bar')) == '<a href="/foo/bar">bar</a>'
예제 #11
0
 def check_href(self):
     assert str(href('/foo/bar', 'bar')) == '<a href="/foo/bar">bar</a>'
예제 #12
0
파일: altdemo.py 프로젝트: pganti/micheles
def format_link_list(targets):
    return htmltext('<ul>%s</ul>') % htmltext('').join([
        htmltext('<li>%s</li>') % href(target, target) for target in targets])
예제 #13
0
 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)