-
Notifications
You must be signed in to change notification settings - Fork 2k
/
group_extra.py
50 lines (39 loc) · 1.49 KB
/
group_extra.py
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
48
49
50
# encoding: utf-8
import vdm.sqlalchemy
from sqlalchemy import orm, types, Column, Table, ForeignKey
from sqlalchemy.ext.associationproxy import association_proxy
from six import text_type
import group
import meta
import core
import types as _types
import domain_object
__all__ = ['GroupExtra', 'group_extra_table']
group_extra_table = Table('group_extra', meta.metadata,
Column('id', types.UnicodeText, primary_key=True, default=_types.make_uuid),
Column('group_id', types.UnicodeText, ForeignKey('group.id')),
Column('key', types.UnicodeText),
Column('value', types.UnicodeText),
Column('state', types.UnicodeText, default=core.State.ACTIVE),
)
# Define the group_extra_revision table, but no need to map it, as it is only
# used by migrate_package_activity.py
group_extra_revision_table = \
core.make_revisioned_table(group_extra_table, frozen=True)
class GroupExtra(core.StatefulObjectMixin,
domain_object.DomainObject):
pass
meta.mapper(GroupExtra, group_extra_table, properties={
'group': orm.relation(group.Group,
backref=orm.backref('_extras',
collection_class=orm.collections.attribute_mapped_collection(u'key'),
cascade='all, delete, delete-orphan',
),
)
},
order_by=[group_extra_table.c.group_id, group_extra_table.c.key],
)
def _create_extra(key, value):
return GroupExtra(key=text_type(key), value=value)
group.Group.extras = association_proxy(
'_extras', 'value', creator=_create_extra)