Revision 3dc095112a8a () - Diff

Link to this snippet: https://friendpaste.com/4Nd8x5PwTW0B9uNSFHM5V
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
_tables = []

for name in TABLES_NAMES:
# table
exec '%s = Table(name, metadata, autoload=True, autoload_with=engine)' % name
exec 'table = %s' % name

# mapper with props
properties = dict([(f.split('_', 1)[1].lower(), getattr(table.c, f)) \
for f in table.c.keys()])
mapper_name = ''.join([s.title() for s in name.split('_')[2:]])
doc = "Mapper for table %s with properties:\n" % name
for k, v in properties.items():
doc += '\n- `%s`: %r\n' % (k, v)
exec '%s = type("%s", (BaseMapper,), {"__doc__":doc})' % (
mapper_name, mapper_name)
_tables.append((mapper_name, name, properties))

# native mapper
properties = {}
mapper_name = ''.join([s.title() for s in name.split('_')])
doc = "Mapper for table %s with properties:" % name
for k, v in properties.items():
doc += '\n- `%s`: %r' % (k, v)
exec '%s = type("%s", (BaseMapper,), {"__doc__":doc})' % (
mapper_name, mapper_name)
_tables.append((mapper_name, name, properties))

print >> sphinx_doc, '.. autoclass:: '+name
print >> sphinx_doc, ''


# define specific properties to append to mappers
TABLES_PROPERTIES = {}


for mapper_name, name, properties in _tables:
# mappers
log.debug('orm.mapper(%s, %s, properties=%s)',
mapper_name, name, properties)
exec 'orm.mapper(%s, %s, properties=properties)' % (
mapper_name, name)

print >> sphinx_doc, '.. autoclass:: '+mapper_name
print >> sphinx_doc, ''

__all.append(mapper_name)