Exemple #1
0
    def test_prefixes(self):
        """Tests the utils.prefixes function"""

        self.assertEqual(
            set(['a']),
            utils.prefixes(['a.b']))
        self.assertEqual(
            set(['a', 'b']),
            utils.prefixes(['a.b', 'a.c', 'b']))
        self.assertEqual(
            set(['a', 'b', 'c']),
            utils.prefixes(['a.b', 'b.c', 'b', 'c.c']))
Exemple #2
0
def create_items(connection, items, include, exclude, substitutes):
    results_pre = []
    results_post = []
    includes = {}

    check_excludes(items, exclude)

    item = None
    for item in items:
        for i in include:
            process_item(item, i, includes)

    if item is not None:
        for fk in includes.keys():
            if fk.a.table.name == item.table.name:
                # forward references, must be in pre
                results_pre += create_items(
                    connection,
                    connection.rows(
                        fk.b.table,
                        QueryFilter(fk.b.name, 'in', includes[fk]),
                        limit=-1,
                        simplify=False),
                    remove_prefix(fk.a.name, include),
                    remove_prefix(fk.a.name, exclude),
                    remove_prefix(fk.a.name, substitutes))
            else:
                # backward reference, must be in post
                results_post += create_items(
                    connection,
                    connection.rows(
                        fk.a.table,
                        QueryFilter(fk.a.name, 'in', includes[fk]),
                        limit=-1,
                        simplify=False),
                    remove_prefix(fk.a.table.name, include),
                    remove_prefix(fk.a.table.name, exclude),
                    remove_prefix(fk.a.table.name, substitutes))

    return results_pre + map(
        lambda i: RowItem(
            to_dto(i),
            prefixes(include),
            prefixes(exclude),
            prefixes(substitutes)),
        items) + results_post
Exemple #3
0
def create_items(connection, items, include, exclude, substitutes):
    results_pre = []
    results_post = []
    includes = {}

    check_excludes(items, exclude)

    item = None
    for item in items:
        for i in include:
            process_item(item, i, includes)

    if item is not None:
        for fk in includes.keys():
            if fk.a.table.name == item.table.name:
                # forward references, must be in pre
                results_pre += create_items(
                    connection,
                    connection.rows(fk.b.table,
                                    QueryFilter(fk.b.name, 'in', includes[fk]),
                                    limit=-1,
                                    simplify=False),
                    remove_prefix(fk.a.name, include),
                    remove_prefix(fk.a.name, exclude),
                    remove_prefix(fk.a.name, substitutes))
            else:
                # backward reference, must be in post
                results_post += create_items(
                    connection,
                    connection.rows(fk.a.table,
                                    QueryFilter(fk.a.name, 'in', includes[fk]),
                                    limit=-1,
                                    simplify=False),
                    remove_prefix(fk.a.table.name, include),
                    remove_prefix(fk.a.table.name, exclude),
                    remove_prefix(fk.a.table.name, substitutes))

    return results_pre + map(
        lambda i: RowItem(to_dto(i), prefixes(include), prefixes(exclude),
                          prefixes(substitutes)), items) + results_post