Blob Blame Raw


import exception

from page.page import Page
from page.user import UserPage, UserCreatePage, UserListPage


class RootPage(Page):
  def __init__(self):
    super().__init__()
    self.user = UserPage()
    self.user_create = UserCreatePage()
    self.users = UserListPage()
  
  def process(self, request, path, prevpath):
    answer = request.answer
    answer.template = self.commontemplate
    
    if path:
      if path[0] == 'user':
        return self.user.sub_process(request, path, prevpath)
      if path[0] == 'user_create':
        return self.user_create.sub_process(request, path, prevpath)
      if path[0] == 'users':
        return self.users.sub_process(request, path, prevpath)
      if path[0] == 'auth':
        answer.headers.append( ('WWW-Authenticate', 'Basic realm="Repo", charset="UTF-8"') )
        answer.status = '401 Unauthorized'
      else:
        raise exception.HttpNotFound()
    
    answer.content += '<p>' + answer.te('root page') + '</p>'
    answer.content += '<p>' + answer.te('Welcome!') + '</p>'

    if request.model.users.can_list():
      answer.content += '<p>' + self.make_link(answer, prevpath + ['users'], 'Users list') + '</p>\n'

    answer.content += '<p>Env: \n' + answer.e(str(request.env)) + '</p>'

    tables = list(v[0] for v in request.connection.query_list('SHOW TABLES'))
    answer.content += '<p>DB tables: ' + answer.e(', '.join(tables)) + '</p>'
    
    rows = request.connection.query_dict('SELECT * FROM %T', 'test')
    answer.content += '<p>Rows of test table: ' + answer.e(str(rows)) + '</p>'

    return answer.complete_content()