示例#1
0
def change_requests(schema, table):
    """
    Loads the dataedit admin interface
    :param request:
    :return:
    """
    # I want to display old and new data, if different.

    display_message = None
    api_columns = dba.get_column_changes(reviewed=False,
                                         schema=schema,
                                         table=table)
    api_constraints = dba.get_constraints_changes(reviewed=False,
                                                  schema=schema,
                                                  table=table)

    # print(api_columns)
    # print(api_constraints)

    cache = dict()
    data = dict()

    data['api_columns'] = {}
    data['api_constraints'] = {}

    keyword_whitelist = [
        'column_name', 'c_table', 'c_schema', 'reviewed', 'changed', 'id'
    ]

    old_description = dba.describe_columns(schema, table)

    for change in api_columns:

        name = change['column_name']
        id = change['id']

        # Identifing over 'new'.
        if change.get('new_name') is not None:
            change['column_name'] = change['new_name']

        old_cd = old_description.get(name)

        data['api_columns'][id] = {}
        data['api_columns'][id]['old'] = {}

        if old_cd is not None:
            old = api.parser.parse_scolumnd_from_columnd(
                schema, table, name, old_description.get(name))

            for key in list(change):
                value = change[key]
                if key not in keyword_whitelist and (value is None
                                                     or value == old[key]):
                    old.pop(key)
                    change.pop(key)
            data['api_columns'][id]['old'] = old
        else:
            data['api_columns'][id]['old']['c_schema'] = schema
            data['api_columns'][id]['old']['c_table'] = table
            data['api_columns'][id]['old']['column_name'] = name

        data['api_columns'][id]['new'] = change

    for i in range(len(api_constraints)):
        value = api_constraints[i]
        id = value.get('id')
        if value.get('reference_table') is None or value.get(
                'reference_column') is None:
            value.pop('reference_table')
            value.pop('reference_column')

        data['api_constraints'][id] = value

    display_style = [
        'c_schema', 'c_table', 'column_name', 'not_null', 'data_type',
        'reference_table', 'constraint_parameter', 'reference_column',
        'action', 'constraint_type', 'constraint_name'
    ]

    return {
        'data': data,
        'display_items': display_style,
        'display_message': display_message
    }
示例#2
0
def change_requests(schema, table):
    """
    Loads the dataedit admin interface
    :param request:
    :return:
    """
    # I want to display old and new data, if different.

    display_message = None
    api_columns = actions.get_column_changes(reviewed=False,
                                             schema=schema,
                                             table=table)
    api_constraints = actions.get_constraints_changes(reviewed=False,
                                                      schema=schema,
                                                      table=table)

    # print(api_columns)
    # print(api_constraints)

    cache = dict()
    data = dict()

    data["api_columns"] = {}
    data["api_constraints"] = {}

    keyword_whitelist = [
        "column_name",
        "c_table",
        "c_schema",
        "reviewed",
        "changed",
        "id",
    ]

    old_description = actions.describe_columns(schema, table)

    for change in api_columns:

        name = change["column_name"]
        id = change["id"]

        # Identifing over 'new'.
        if change.get("new_name") is not None:
            change["column_name"] = change["new_name"]

        old_cd = old_description.get(name)

        data["api_columns"][id] = {}
        data["api_columns"][id]["old"] = {}

        if old_cd is not None:
            old = api.parser.parse_scolumnd_from_columnd(
                schema, table, name, old_description.get(name))

            for key in list(change):
                value = change[key]
                if key not in keyword_whitelist and (value is None
                                                     or value == old[key]):
                    old.pop(key)
                    change.pop(key)
            data["api_columns"][id]["old"] = old
        else:
            data["api_columns"][id]["old"]["c_schema"] = schema
            data["api_columns"][id]["old"]["c_table"] = table
            data["api_columns"][id]["old"]["column_name"] = name

        data["api_columns"][id]["new"] = change

    for i in range(len(api_constraints)):
        value = api_constraints[i]
        id = value.get("id")
        if (value.get("reference_table") is None
                or value.get("reference_column") is None):
            value.pop("reference_table")
            value.pop("reference_column")

        data["api_constraints"][id] = value

    display_style = [
        "c_schema",
        "c_table",
        "column_name",
        "not_null",
        "data_type",
        "reference_table",
        "constraint_parameter",
        "reference_column",
        "action",
        "constraint_type",
        "constraint_name",
    ]

    return {
        "data": data,
        "display_items": display_style,
        "display_message": display_message,
    }