Ejemplo n.º 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)
Ejemplo n.º 2
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)]))
Ejemplo n.º 3
0
    primary_key = table.primary_key

    if comment.id:
        id_ = comment.id.format(**caliases)
    else:
        if primary_key:
            id_ = u'{{{0}_{1}}}'.format(alias, primary_key)
        else:
            id_ = "-"

    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))