Blame page/root.py

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

' + answer.te('root page') + '

'
b838e2
    answer.content += '

' + answer.te('Welcome!') + '

'
b838e2
b838e2
    if request.model.users.can_list():
b838e2
      answer.content += '

' + self.make_link(answer, prevpath + ['users'], 'Users list') + '

\n'
b838e2
b838e2
    answer.content += '

Env: \n' + answer.e(str(request.env)) + '

'
b838e2
b838e2
    tables = list(v[0] for v in request.connection.query_list('SHOW TABLES'))
b838e2
    answer.content += '

DB tables: ' + answer.e(', '.join(tables)) + '

'
b838e2
    
b838e2
    rows = request.connection.query_dict('SELECT * FROM %T', 'test')
b838e2
    answer.content += '

Rows of test table: ' + answer.e(str(rows)) + '

'
b838e2
b838e2
    return answer.complete_content()
b838e2