Пример #1
0
 def __mask_passwords(content):
     masks = config.password_masks()
     if masks:
         content = ''.join(render(content))
         for mask in masks:
             content = content.replace(mask, "***")
     return content
Пример #2
0
def schema_selection(db_alias: str):
    """Asynchronously computes the list of schemas with foreign key constraints"""
    schemas_with_fk_constraints = schemas_with_foreign_key_constraints(db_alias)

    if not schemas_with_fk_constraints or len(schemas_with_fk_constraints) == 0:
        return str(_.i['No schemas with foreign key constraints found'])

    return ''.join(xml.render([
        [_.div(class_='form-check form-check-inline')[
             _.label(class_='form-check-label')[
                 _.input(class_="form-check-input schema-checkbox", type="checkbox", value=schema_name)[
                     ''], ' ', schema_name]]
         for schema_name in sorted(schemas_with_fk_constraints)],
        '   ',
        _.div(class_='form-check form-check-inline')[
            _.label(class_='form-check-label')[
                _.input(class_="form-check-input", id='hide-columns-checkbox', type="checkbox")[
                    ''], ' ', 'hide columns']],
        '   ',
        _.div(class_='form-check form-check-inline')[
            _.label(class_='form-check-label')[
                'graphviz engine ',
                _.select(id='engine', style='border:none;background-color:white;')[
                    [_.option(value=engine)[engine] for engine in ['neato', 'dot', 'twopi', 'fdp']]
                ]]],
        _.script['''
var schemaPage = SchemaPage("''' + flask.url_for('mara_db.index_page', db_alias=db_alias) + '''", "''' + db_alias + '''");
''']]))
Пример #3
0
def schema_selection(db_alias: str):
    """Asynchronously computes the list of schemas with foreign key constraints"""
    schemas_with_fk_constraints = []
    with mara_db.postgresql.postgres_cursor_context(db_alias) as cursor:
        cursor.execute('''
SELECT
  array_cat(array_agg(DISTINCT constrained_table_schema.nspname), array_agg(DISTINCT referenced_table_schema.nspname))
FROM pg_constraint
  JOIN pg_class constrained_table ON constrained_table.oid = pg_constraint.conrelid
  JOIN pg_namespace constrained_table_schema ON constrained_table.relnamespace = constrained_table_schema.oid
  JOIN pg_class referenced_table ON referenced_table.oid = pg_constraint.confrelid
  JOIN pg_namespace referenced_table_schema ON referenced_table.relnamespace = referenced_table_schema.oid'''
                       )
        result = cursor.fetchone()
        if result != (None, ):
            schemas_with_fk_constraints = sorted(list(set(result[0])))

    if len(schemas_with_fk_constraints) == 0:
        return str(_.i['No schemas with foreign key constraints found'])

    return ''.join(
        xml.render(
            [[
                _.div(class_='form-check form-check-inline')[_.label(
                    class_='form-check-label')[
                        _.input(class_="form-check-input schema-checkbox",
                                type="checkbox",
                                value=schema_name)[''], ' ', schema_name]]
                for schema_name in sorted(schemas_with_fk_constraints)
            ], '   ',
             _.div(class_='form-check form-check-inline')[_.label(
                 class_='form-check-label')[_.input(class_="form-check-input",
                                                    id='hide-columns-checkbox',
                                                    type="checkbox")[''], ' ',
                                            'hide columns']], '   ',
             _.div(class_='form-check form-check-inline')[_.label(
                 class_='form-check-label'
             )['graphviz engine ',
               _.select(id='engine',
                        style='border:none;background-color:white;')[[
                            _.option(value=engine)[engine]
                            for engine in ['neato', 'dot', 'twopi', 'fdp']
                        ]]]], _.script['''
var schemaPage = SchemaPage("''' + flask.url_for('mara_db.index_page',
                                                 db_alias=db_alias) +
                                       '''", "''' + db_alias + '''");
''']]))
Пример #4
0
def head_elements(response: mara_page.response.Response) -> [xml.XMLElement]:
    """All elements in the head section of the html page"""
    return [
        _.meta(charset='utf-8'),
        _.meta(
            name='viewport',
            content='width=device-width, initial-scale=1, shrink-to-fit=no'),
        _.title[re.sub(r'<[^>]*?>', '', ''.join(xml.render(response.title)))],
        [
            _.link(rel='stylesheet',
                   href=url + ('&' if '?' in url else '?') +
                   _current_git_commit())[''] for url in css_files(response)
        ],
        _.link(rel='icon',
               type='image/png',
               href=config.favicon_url() + '?' + _current_git_commit())
    ]
Пример #5
0
def navigation_bar() -> [str]:
    from . import app

    # The navigation sidebar is loaded asynchronously for better rendering experience
    def render_entries(entries: [navigation.NavigationEntry] = [],
                       level: int = 1):
        def render_entry(entry: navigation.NavigationEntry, level: int = 1):
            attrs = {}
            if entry.children:
                attrs['onClick'] = 'toggleNavigationEntry(this)'
            else:
                attrs['href'] = entry.uri_fn()

            if entry.description:
                attrs.update({
                    'title': entry.description,
                    'data-toggle': 'tooltip',
                    'data-container': 'body',
                    'data-placement': 'right'
                })
            return _.div(
                class_='mara-nav-entry level-' + str(level),
                style='display:none' if level > 1 else ''
            )[_.a(**attrs)[_.div(
                class_='mara-nav-entry-icon fa fa-fw fa-' + entry.icon +
                (' fa-lg' if level == 1 else ''))[''] if entry.icon else '',
                           _.div(class_='mara-nav-entry-text'
                                 )[entry.label.replace('_', '_<wbr>')],
                           _.div(class_='mara-caret fa fa-caret-down'
                                 )[''] if entry.children else ''],
              render_entries(entry.children, level + 1)]

        return [
            functools.partial(render_entry, level=level)(entry)
            for entry in sorted([entry for entry in entries if entry.visible],
                                key=lambda x: x.rank)
        ]

    return flask.Response(''.join(
        list(
            xml.render(
                render_entries(app.combine_navigation_entries().children)))))