Esempio n. 1
0
File: index.py Progetto: crst/pgui
def Login(params=None, title=None):
    """
    Renders the login page.

    There is no separate login for the application, this is passed to
    the database!
    """
    p = Page()
    p.content('<!DOCTYPE html>')
    with p.html():
        with p.head():
            with p.title():
                p.content('pgui - Login')
            with p.link({'href': 'static/lib/bootstrap/bootstrap-3.3.4-dist/css/bootstrap.css', 'rel': 'stylesheet'}): pass
            with p.link({'href': 'static/login.css', 'rel': 'stylesheet'}): pass

        with p.body():

            with p.div({'class': 'container'}):
                with p.form({'method': 'POST', 'class': 'login'}):
                    with p.h2({'class': 'login-header'}):
                        p.content('Connect to a postgres database server')

                    with p.label({'for': 'name', 'class': 'sr-only'}):
                        p.content('User name')
                    with p.input({'type': 'input', 'id': 'name', 'name': 'name', 'class': 'form-control', 'placeholder': 'User name'}): pass

                    with p.label({'for': 'password', 'class': 'sr-only'}):
                        p.content('Password')
                    with p.input({'type': 'password', 'id': 'password', 'name': 'password', 'class': 'form-control', 'placeholder': 'Password'}): pass

                    with p.label({'for': 'host', 'class': 'sr-only'}):
                        p.control('Host')
                    with p.input({'type': 'input', 'id': 'host', 'name': 'host', 'class': 'form-control', 'value': 'localhost'}): pass

                    with p.label({'for': 'port', 'class': 'sr-only'}):
                        p.content('Port')
                    with p.input({'type': 'input', 'id': 'port', 'name': 'port', 'class': 'form-control', 'value': '5432'}): pass

                    with p.button({'class': 'btn btn-lg btn-success btn-block', 'type': 'submit'}, args=['autofocus']):
                        p.content('Connect')


                with p.div({'class': 'login'}):
                    if 'err' in params and params['err']:
                        for err in params['err']:
                            with p.code():
                                p.content(err)

    return p
Esempio n. 2
0
File: shared.py Progetto: crst/pgui
def Navigation(params=None, page=None):
    p = Page()

    with p.nav({'class': 'navbar navbar-default'}):
        with p.div({'class': 'container-fluid'}):
            with p.div({'class': 'navbar-header'}):
                with p.button({
                        'type': 'button',
                        'class': 'navbar-toggle collapsed',
                        'data-toggle': 'collapse',
                        'data-target': '#navbar',
                        'aria-expanded': 'false',
                        'aria-controls': 'navbar'
                }):
                    with p.span({'class': 'sr-only'}):
                        p.content('Toggle navigation')
                    with p.span({'class': 'icon-bar'}):
                        pass
                    with p.span({'class': 'icon-bar'}):
                        pass
                    with p.span({'class': 'icon-bar'}):
                        pass

                with p.a({'class': 'navbar-brand', 'href': '/'}):
                    p.content('pgui')

            with p.div({'id': 'navbar', 'class': 'navbar-collapse collapse'}):
                with p.ul({'class': 'nav navbar-nav'}):
                    for i, page in enumerate(pages.index.PAGES, 1):
                        active = page['name'] == page and 'active' or ''
                        with p.li({'class': active}):
                            with p.a({
                                    'id': 'page-%s' % i,
                                    'href': '/%s' % page['name']
                            }):
                                with p.span({
                                        'class':
                                        'glyphicon glyphicon-%s' % page['icon']
                                }):
                                    pass
                                p.content(' %s' % page['name'].title())

                with p.ul({'class': 'nav navbar-nav navbar-right'}):
                    with p.li():
                        with p.a({'href': '/logout'}):
                            with p.span(
                                {'class': 'glyphicon glyphicon-log-out'}):
                                p.content(' Logout')

    return p
Esempio n. 3
0
File: query.py Progetto: crst/pgui
def Query(params=None):
    handle_params(params)
    p = Page()

    # Header
    p.add_page(Header(title='Query',
                      js=['static/pages/query.js',
                          'static/pages/query_completion.js',
                          'static/pages/keywords.js',
                          'static/lib/springy/springy.js',
                          'static/lib/springy/springyui.js'],
                      css=['static/pages/query.css']))
    with p.script():
        p.content('PGUI.QUERY.keymap = "%s";' % current_user.keymap)
    p.add_page(Navigation(page='query'))

    with p.div({'class': 'container-fluid'}):
        # Modal dialog for displaying previous queries
        with p.div({'class': 'modal fade', 'id': 'query-history-dialog', 'tabindex': '-1', 'role': 'dialog', 'aria-labelledby': 'Query History'}):
            with p.div({'class': 'modal-dialog', 'role': 'document'}):
                with p.div({'class': 'modal-content'}):
                    with p.div({'class': 'modal-header'}):
                        with p.button({'type': 'button', 'class': 'close', 'data-dismiss': 'modal', 'aria-label': 'Close'}):
                            with p.span({'aria-hidden': 'true'}):
                                p.content('&times;')
                        with p.h4({'class': 'modal-title', 'id': 'query-history-label'}):
                            p.content('Query history')

                    with p.div({'clas': 'modal-body'}):
                        with p.div({'id': 'query-history'}): pass

        # Tab bar controls
        with p.div({'id': 'query-panel', 'role': 'tabpanel'}):
            with p.ul({'id': 'query-nav-tabs', 'class': 'nav nav-tabs', 'role': 'tablist'}):
                with p.li({'role': 'presentation'}):
                    with p.a({'id': 'show-query-history', 'href': 'javascript:void(0);'}):
                        with p.span({'class': 'add-tab glyphicon glyphicon-camera', 'aria-hidden': 'true'}): pass
                with p.li({'role': 'presentation'}):
                    with p.a({'id': 'add-tab', 'href': 'javascript:void(0);'}):
                        with p.span({'class': 'add-tab glyphicon glyphicon-plus', 'aria-hidden': 'true'}): pass
            # Tab bar contents
            with p.div({'id': 'query-tab-panes', 'class': 'tab-content'}): pass

    # Footer
    p.add_page(Footer())

    return p
Esempio n. 4
0
File: shared.py Progetto: crst/pgui
def Navigation(params=None, page=None):
    p = Page()

    with p.nav({'class': 'navbar navbar-default'}):
        with p.div({'class': 'container-fluid'}):
            with p.div({'class': 'navbar-header'}):
                with p.button({'type': 'button',
                               'class': 'navbar-toggle collapsed',
                               'data-toggle': 'collapse',
                               'data-target': '#navbar',
                               'aria-expanded': 'false',
                               'aria-controls': 'navbar'}):
                    with p.span({'class': 'sr-only'}):
                        p.content('Toggle navigation')
                    with p.span({'class': 'icon-bar'}): pass
                    with p.span({'class': 'icon-bar'}): pass
                    with p.span({'class': 'icon-bar'}): pass

                with p.a({'class': 'navbar-brand', 'href': '/'}):
                    p.content('pgui')

            with p.div({'id': 'navbar', 'class': 'navbar-collapse collapse'}):
                with p.ul({'class': 'nav navbar-nav'}):
                    for i, page in enumerate(pages.index.PAGES, 1):
                        active = page['name'] == page and 'active' or ''
                        with p.li({'class': active}):
                            with p.a({'id': 'page-%s' % i, 'href': '/%s' % page['name']}):
                                with p.span({'class': 'glyphicon glyphicon-%s' % page['icon']}): pass
                                p.content(' %s' % page['name'].title())

                with p.ul({'class': 'nav navbar-nav navbar-right'}):
                    with p.li():
                        with p.a({'href': '/logout'}):
                            with p.span({'class': 'glyphicon glyphicon-log-out'}):
                                p.content(' Logout')

    return p
Esempio n. 5
0
File: index.py Progetto: crst/pgui
def Index(params=None):
    """
    Renders the index page which displays some generic connections
    information and links to all the activated modules.
    """
    handle_params(params)
    p = Page()

    # Header
    p.add_page(Header(title='Index'))
    p.add_page(Navigation(page='index'))

    with p.div({'class': 'container-fluid'}):
        # Connection information
        data, params = [], defaultdict(str)
        param_keys = ('server_version', 'server_encoding', 'client_encoding', 'is_superuser', 'TimeZone')
        with pg_connection(*current_user.get_config()) as (con, cur, err):
            for k in param_keys:
                params[k] = con.get_parameter_status(k)
            with pg_log_err('list databases'):
                cur.execute(query('list-databases'))
                data = cur.fetchall()

        with p.div({'class': 'row'}):
            with p.div({'class': 'col-md-2'}):
                with p.div({'class': 'btn-group'}):
                    with p.button({'class': 'btn btn-default dropdown-toggle', 'data-toggle': 'dropdown', 'aria-expanded': 'false'}):
                        p.content('Switch database <span class="caret"></span>')
                    with p.ul({'class': 'dropdown-menu', 'role': 'menu'}):
                        for n, d in enumerate(data):
                            with p.li():
                                with p.a({'href': 'index?database=%s' % d[0]}):
                                    p.content(d[0])
                            if n < len(data) - 1:
                                with p.li({'class': 'divider'}): pass

            with p.div({'class': 'col-md-4 small'}):
                p.content('<strong>%s</strong>' % current_user.database)
                p.content('<br>%s@%s:%s' % (current_user.name, current_user.host, current_user.port))

            with p.div({'class': 'col-md-6 small'}):
                with p.ul({'class': 'list-inline'}):
                    for k, v in sorted(params.items()):
                        with p.li():
                            p.content('%s: %s' % (k, v))

        with p.hr(): pass

        # Modules
        cols = 12
        col_size = 4
        col = 0
        for page in PAGES[1:]:
            if col == 0:
                with p.div({'class': 'row'}, close=False): pass

            with p.div({'class': 'col-md-%s' % col_size}):
                with p.a({'href': '/%s' % page['name']}):
                    with p.div({'class': 'page-link'}):
                        with p.span({'class': 'page-icon glyphicon glyphicon-%s' % page['icon']}): pass
                        with p.h3():
                            p.content(page['caption'])
                        p.content(page['desc'])

            col = (col + col_size) % cols
            if col == 0:
                p.close('div')

    p.add_page(Footer())

    return p
Esempio n. 6
0
File: index.py Progetto: crst/pgui
def Login(params=None, title=None):
    """
    Renders the login page.

    There is no separate login for the application, this is passed to
    the database!
    """
    p = Page()
    p.content('<!DOCTYPE html>')
    with p.html():
        with p.head():
            with p.title():
                p.content('pgui - Login')
            with p.link({
                    'href':
                    'static/lib/bootstrap/bootstrap-3.3.4-dist/css/bootstrap.css',
                    'rel': 'stylesheet'
            }):
                pass
            with p.link({'href': 'static/login.css', 'rel': 'stylesheet'}):
                pass

        with p.body():

            with p.div({'class': 'container'}):
                with p.form({'method': 'POST', 'class': 'login'}):
                    with p.h2({'class': 'login-header'}):
                        p.content('Connect to a postgres database server')

                    with p.label({'for': 'name', 'class': 'sr-only'}):
                        p.content('User name')
                    with p.input({
                            'type': 'input',
                            'id': 'name',
                            'name': 'name',
                            'class': 'form-control',
                            'placeholder': 'User name'
                    }):
                        pass

                    with p.label({'for': 'password', 'class': 'sr-only'}):
                        p.content('Password')
                    with p.input({
                            'type': 'password',
                            'id': 'password',
                            'name': 'password',
                            'class': 'form-control',
                            'placeholder': 'Password'
                    }):
                        pass

                    with p.label({'for': 'host', 'class': 'sr-only'}):
                        p.control('Host')
                    with p.input({
                            'type': 'input',
                            'id': 'host',
                            'name': 'host',
                            'class': 'form-control',
                            'value': 'localhost'
                    }):
                        pass

                    with p.label({'for': 'port', 'class': 'sr-only'}):
                        p.content('Port')
                    with p.input({
                            'type': 'input',
                            'id': 'port',
                            'name': 'port',
                            'class': 'form-control',
                            'value': '5432'
                    }):
                        pass

                    with p.button(
                        {
                            'class': 'btn btn-lg btn-success btn-block',
                            'type': 'submit'
                        },
                            args=['autofocus']):
                        p.content('Connect')

                with p.div({'class': 'login'}):
                    if 'err' in params and params['err']:
                        for err in params['err']:
                            with p.code():
                                p.content(err)

    return p
Esempio n. 7
0
File: index.py Progetto: crst/pgui
def Index(params=None):
    """
    Renders the index page which displays some generic connections
    information and links to all the activated modules.
    """
    handle_params(params)
    p = Page()

    # Header
    p.add_page(Header(title='Index'))
    p.add_page(Navigation(page='index'))

    with p.div({'class': 'container-fluid'}):
        # Connection information
        data, params = [], defaultdict(str)
        param_keys = ('server_version', 'server_encoding', 'client_encoding',
                      'is_superuser', 'TimeZone')
        with pg_connection(*current_user.get_config()) as (con, cur, err):
            for k in param_keys:
                params[k] = con.get_parameter_status(k)
            with pg_log_err('list databases'):
                cur.execute(query('list-databases'))
                data = cur.fetchall()

        with p.div({'class': 'row'}):
            with p.div({'class': 'col-md-2'}):
                with p.div({'class': 'btn-group'}):
                    with p.button({
                            'class': 'btn btn-default dropdown-toggle',
                            'data-toggle': 'dropdown',
                            'aria-expanded': 'false'
                    }):
                        p.content(
                            'Switch database <span class="caret"></span>')
                    with p.ul({'class': 'dropdown-menu', 'role': 'menu'}):
                        for n, d in enumerate(data):
                            with p.li():
                                with p.a({'href': 'index?database=%s' % d[0]}):
                                    p.content(d[0])
                            if n < len(data) - 1:
                                with p.li({'class': 'divider'}):
                                    pass

            with p.div({'class': 'col-md-4 small'}):
                p.content('<strong>%s</strong>' % current_user.database)
                p.content(
                    '<br>%s@%s:%s' %
                    (current_user.name, current_user.host, current_user.port))

            with p.div({'class': 'col-md-6 small'}):
                with p.ul({'class': 'list-inline'}):
                    for k, v in sorted(params.items()):
                        with p.li():
                            p.content('%s: %s' % (k, v))

        with p.hr():
            pass

        # Modules
        cols = 12
        col_size = 4
        col = 0
        for page in PAGES[1:]:
            if col == 0:
                with p.div({'class': 'row'}, close=False):
                    pass

            with p.div({'class': 'col-md-%s' % col_size}):
                with p.a({'href': '/%s' % page['name']}):
                    with p.div({'class': 'page-link'}):
                        with p.span({
                                'class':
                                'page-icon glyphicon glyphicon-%s' %
                                page['icon']
                        }):
                            pass
                        with p.h3():
                            p.content(page['caption'])
                        p.content(page['desc'])

            col = (col + col_size) % cols
            if col == 0:
                p.close('div')

    p.add_page(Footer())

    return p
Esempio n. 8
0
def Query(params=None):
    handle_params(params)
    p = Page()

    # Header
    p.add_page(
        Header(title='Query',
               js=[
                   'static/pages/query.js', 'static/pages/query_completion.js',
                   'static/pages/keywords.js', 'static/lib/springy/springy.js',
                   'static/lib/springy/springyui.js'
               ],
               css=['static/pages/query.css']))
    with p.script():
        p.content('PGUI.QUERY.keymap = "%s";' % current_user.keymap)
    p.add_page(Navigation(page='query'))

    with p.div({'class': 'container-fluid'}):
        # Modal dialog for displaying previous queries
        with p.div({
                'class': 'modal fade',
                'id': 'query-history-dialog',
                'tabindex': '-1',
                'role': 'dialog',
                'aria-labelledby': 'Query History'
        }):
            with p.div({'class': 'modal-dialog', 'role': 'document'}):
                with p.div({'class': 'modal-content'}):
                    with p.div({'class': 'modal-header'}):
                        with p.button({
                                'type': 'button',
                                'class': 'close',
                                'data-dismiss': 'modal',
                                'aria-label': 'Close'
                        }):
                            with p.span({'aria-hidden': 'true'}):
                                p.content('&times;')
                        with p.h4({
                                'class': 'modal-title',
                                'id': 'query-history-label'
                        }):
                            p.content('Query history')

                    with p.div({'clas': 'modal-body'}):
                        with p.div({'id': 'query-history'}):
                            pass

        # Tab bar controls
        with p.div({'id': 'query-panel', 'role': 'tabpanel'}):
            with p.ul({
                    'id': 'query-nav-tabs',
                    'class': 'nav nav-tabs',
                    'role': 'tablist'
            }):
                with p.li({'role': 'presentation'}):
                    with p.a({
                            'id': 'show-query-history',
                            'href': 'javascript:void(0);'
                    }):
                        with p.span({
                                'class': 'add-tab glyphicon glyphicon-camera',
                                'aria-hidden': 'true'
                        }):
                            pass
                with p.li({'role': 'presentation'}):
                    with p.a({'id': 'add-tab', 'href': 'javascript:void(0);'}):
                        with p.span({
                                'class': 'add-tab glyphicon glyphicon-plus',
                                'aria-hidden': 'true'
                        }):
                            pass
            # Tab bar contents
            with p.div({'id': 'query-tab-panes', 'class': 'tab-content'}):
                pass

    # Footer
    p.add_page(Footer())

    return p