Example #1
0
def simplify(table, comment, key, d):
    if comment:
        d[key] = unicode(comment.__dict__[key]).format(table.name, **d)
        d['id'] = d[u'{0}_{1}'.format(comment.aliases[table.name],
                                      table.primary_key)]
    else:
        d[key] = create_title(comment,
                              table.columns())[1].format(table.name, **d)
Example #2
0
def simplify(table, comment, key, d):
    if comment:
        d[key] = unicode(comment.__dict__[key]).format(table.name, **d)
        d['id'] = d[u'{0}_{1}'.format(
            comment.aliases[table.name], table.primary_key)]
    else:
        d[key] = create_title(
            comment, table.columns())[1].format(table.name, **d)
Example #3
0
    def test_create_title(self):
        """Tests the utils.create_title function"""

        con = DbTestCase.connection
        table = con.table('user')

        self.assertEqual(
            (None, None),
            utils.create_title(None, []))
        self.assertEqual(
            ('name', '{name}'),
            utils.create_title(None, [Column(table, 'name', type=str)]))
        self.assertEqual(
            ('my_name', '{my_name}'),
            utils.create_title(None, [Column(table, 'my_name', type=str)]))
        self.assertEqual(
            ('asdf', '{asdf}'),
            utils.create_title(None, [Column(table, 'asdf', type=str)]))
        self.assertEqual(
            ('id', '{_id}'),
            utils.create_title(
                Comment(
                    '_id', 'title', 'subtitle', 'order', 'search', 'display',
                    'columns', 'aliases'),
                []))
        self.assertEqual(
            ('id', '{_id}'),
            utils.create_title(
                Comment(
                    '_id', 'title', 'subtitle', 'order', 'search', 'display',
                    'columns', 'aliases'),
                [Column(table, 'asdf', type=str)]))
Example #4
0
            table.foreign_keys().iteritems()):
        caliases.update(filter(
            lambda (k, v): k not in caliases.keys(),
            column_aliases(
                v.b.table.columns(), aliases[v.b.table.name]).iteritems()))

    logger.debug('Column aliases: %s', caliases)

    primary_key = find_primary_key(table)
    id_ = find_id(comment, caliases, alias, primary_key)

    title, subtitle, name = None, None, None
    if comment.title:
        title = comment.title.format(**caliases)
    else:
        name, title = create_title(comment, table.columns())
        d = dict(map(lambda k: (k.name, k.name), table.columns()))
        logger.debug('search.add(title.format(**d)=%s)', title.format(**d))
        search.add(title.format(**d))

        title = title.format(**caliases)

    if not subtitle:
        if comment.subtitle:
            subtitle = comment.subtitle.format(**caliases)
        else:
            _, subtitle = create_title(comment, table.columns(), [name])
            d = dict(map(lambda k: (k.name, k.name), table.columns()))
            logger.debug(
                'search.add(subtitle.format(**d)=%s)', subtitle.format(**d))
            search.add(subtitle.format(**d))
Example #5
0
        caliases.update(
            filter(
                lambda (k, v): k not in caliases.keys(),
                column_aliases(v.b.table.columns(),
                               aliases[v.b.table.name]).iteritems()))

    logger.debug('Column aliases: %s', caliases)

    primary_key = find_primary_key(table)
    id_ = find_id(comment, caliases, alias, primary_key)

    title, subtitle, name = None, None, None
    if comment.title:
        title = comment.title.format(**caliases)
    else:
        name, title = create_title(comment, table.columns())
        d = dict(map(lambda k: (k.name, k.name), table.columns()))
        logger.debug('search.add(title.format(**d)=%s)', title.format(**d))
        search.add(title.format(**d))

        title = title.format(**caliases)

    if not subtitle:
        if comment.subtitle:
            subtitle = comment.subtitle.format(**caliases)
        else:
            _, subtitle = create_title(comment, table.columns(), [name])
            d = dict(map(lambda k: (k.name, k.name), table.columns()))
            logger.debug('search.add(subtitle.format(**d)=%s)',
                         subtitle.format(**d))
            search.add(subtitle.format(**d))