Exemplo n.º 1
0
    Column('notes', types.UnicodeText),
    Column('license_id', types.UnicodeText),
    Column('type', types.UnicodeText, default=u'dataset'),
    Column('owner_org', types.UnicodeText),
    Column('creator_user_id', types.UnicodeText),
    Column('metadata_created',
           types.DateTime,
           default=datetime.datetime.utcnow),
    Column('metadata_modified',
           types.DateTime,
           default=datetime.datetime.utcnow),
    Column('private', types.Boolean, default=False),
)

vdm.sqlalchemy.make_table_stateful(package_table)
package_revision_table = core.make_revisioned_table(package_table)

## -------------------
## Mapped classes


class Package(vdm.sqlalchemy.RevisionedObjectMixin,
              vdm.sqlalchemy.StatefulObjectMixin, domain_object.DomainObject):

    text_search_fields = ['name', 'title']

    def __init__(self, **kw):
        from ckan import model
        super(Package, self).__init__(**kw)

    @classmethod
Exemplo n.º 2
0
        Column('author_email', types.UnicodeText),
        Column('maintainer', types.UnicodeText),
        Column('maintainer_email', types.UnicodeText),
        Column('notes', types.UnicodeText),
        Column('license_id', types.UnicodeText),
        Column('type', types.UnicodeText, default=u'dataset'),
        Column('owner_org', types.UnicodeText),
        Column('creator_user_id', types.UnicodeText),
        Column('metadata_created', types.DateTime, default=datetime.datetime.utcnow),
        Column('metadata_modified', types.DateTime, default=datetime.datetime.utcnow),
        Column('private', types.Boolean, default=False),
)


vdm.sqlalchemy.make_table_stateful(package_table)
package_revision_table = core.make_revisioned_table(package_table)

## -------------------
## Mapped classes

class Package(vdm.sqlalchemy.RevisionedObjectMixin,
        vdm.sqlalchemy.StatefulObjectMixin,
        domain_object.DomainObject):

    text_search_fields = ['name', 'title']

    def __init__(self, **kw):
        from ckan import model
        super(Package, self).__init__(**kw)

    @classmethod
Exemplo n.º 3
0
    def _(txt):
        return txt

__all__ = ['PackageRelationship', 'package_relationship_table',
           'package_relationship_revision_table']

package_relationship_table = Table('package_relationship', meta.metadata,
     Column('id', types.UnicodeText, primary_key=True, default=_types.make_uuid),
     Column('subject_package_id', types.UnicodeText, ForeignKey('package.id')),
     Column('object_package_id', types.UnicodeText, ForeignKey('package.id')),
     Column('type', types.UnicodeText),
     Column('comment', types.UnicodeText),
     )

vdm.sqlalchemy.make_table_stateful(package_relationship_table)
package_relationship_revision_table = core.make_revisioned_table(package_relationship_table)

class PackageRelationship(vdm.sqlalchemy.RevisionedObjectMixin,
                          vdm.sqlalchemy.StatefulObjectMixin,
                          domain_object.DomainObject):
    '''The rule with PackageRelationships is that they are stored in the model
    always as the "forward" relationship - i.e. "child_of" but never
    as "parent_of". However, the model functions provide the relationships
    from both packages in the relationship and the type is swapped from
    forward to reverse accordingly, for meaningful display to the user.'''
    
    # List of (type, corresponding_reverse_type)
    # e.g. (A "depends_on" B, B has a "dependency_of" A)
    # don't forget to add specs to Solr's schema.xml
    types = [(u'depends_on', u'dependency_of'),
             (u'derives_from', u'has_derivation'),
Exemplo n.º 4
0
        Column('name', types.Unicode(PACKAGE_NAME_MAX_LENGTH),
               nullable=False, unique=True),
        Column('title', types.UnicodeText),
        Column('version', types.Unicode(PACKAGE_VERSION_MAX_LENGTH)),
        Column('url', types.UnicodeText),
        Column('author', types.UnicodeText),
        Column('author_email', types.UnicodeText),
        Column('maintainer', types.UnicodeText),
        Column('maintainer_email', types.UnicodeText),                      
        Column('notes', types.UnicodeText),
        Column('license_id', types.UnicodeText),
)


vdm.sqlalchemy.make_table_stateful(package_table)
package_revision_table = make_revisioned_table(package_table)

## -------------------
## Mapped classes


class Package(vdm.sqlalchemy.RevisionedObjectMixin,
        vdm.sqlalchemy.StatefulObjectMixin,
        DomainObject):
    
    text_search_fields = ['name', 'title']

    def __init__(self, **kw):
        from ckan import model
        super(Package, self).__init__(**kw)
        resource_group = model.ResourceGroup(label="default")
Exemplo n.º 5
0
    Column('extras', _types.JsonDictType),
)

resource_group_table = Table(
    'resource_group',
    meta.metadata,
    Column('id', types.UnicodeText, primary_key=True,
           default=_types.make_uuid),
    Column('package_id', types.UnicodeText, ForeignKey('package.id')),
    Column('label', types.UnicodeText),
    Column('sort_order', types.UnicodeText),
    Column('extras', _types.JsonDictType),
)

vdm.sqlalchemy.make_table_stateful(resource_table)
resource_revision_table = core.make_revisioned_table(resource_table)

vdm.sqlalchemy.make_table_stateful(resource_group_table)
resource_group_revision_table = core.make_revisioned_table(
    resource_group_table)


class Resource(vdm.sqlalchemy.RevisionedObjectMixin,
               vdm.sqlalchemy.StatefulObjectMixin, domain_object.DomainObject):
    extra_columns = None

    def __init__(self,
                 resource_group_id=None,
                 url=u'',
                 format=u'',
                 description=u'',
Exemplo n.º 6
0
import meta
import core
import domain_object

__all__ = ['system_info_revision_table', 'system_info_table', 'SystemInfo',
           'SystemInfoRevision', 'get_system_info', 'set_system_info']

system_info_table = Table(
    'system_info', meta.metadata,
    Column('id', types.Integer(),  primary_key=True, nullable=False),
    Column('key', types.Unicode(100), unique=True, nullable=False),
    Column('value', types.UnicodeText),
)

vdm.sqlalchemy.make_table_stateful(system_info_table)
system_info_revision_table = core.make_revisioned_table(system_info_table)


class SystemInfo(vdm.sqlalchemy.RevisionedObjectMixin,
                 vdm.sqlalchemy.StatefulObjectMixin,
                 domain_object.DomainObject):

    def __init__(self, key, value):

        super(SystemInfo, self).__init__()

        self.key = key
        self.value = unicode(value)


meta.mapper(SystemInfo, system_info_table,
Exemplo n.º 7
0
    'member_revision_table', 'member_table'
]

member_table = Table(
    'member',
    meta.metadata,
    Column('id', types.UnicodeText, primary_key=True,
           default=_types.make_uuid),
    Column('table_name', types.UnicodeText, nullable=False),
    Column('table_id', types.UnicodeText, nullable=False),
    Column('capacity', types.UnicodeText, nullable=False),
    Column('group_id', types.UnicodeText, ForeignKey('group.id')),
)

vdm.sqlalchemy.make_table_stateful(member_table)
member_revision_table = core.make_revisioned_table(member_table)

group_table = Table(
    'group', meta.metadata,
    Column('id', types.UnicodeText, primary_key=True,
           default=_types.make_uuid),
    Column('name', types.UnicodeText, nullable=False, unique=True),
    Column('title', types.UnicodeText),
    Column('type', types.UnicodeText, nullable=False),
    Column('description', types.UnicodeText),
    Column('image_url', types.UnicodeText),
    Column('created', types.DateTime, default=datetime.datetime.now),
    Column('is_organization', types.Boolean, default=False),
    Column('approval_status', types.UnicodeText, default=u"approved"))

vdm.sqlalchemy.make_table_stateful(group_table)
Exemplo n.º 8
0
           nullable=False,
           unique=True),
    Column('title', types.UnicodeText),
    Column('version', types.Unicode(PACKAGE_VERSION_MAX_LENGTH)),
    Column('url', types.UnicodeText),
    Column('author', types.UnicodeText),
    Column('author_email', types.UnicodeText),
    Column('maintainer', types.UnicodeText),
    Column('maintainer_email', types.UnicodeText),
    Column('notes', types.UnicodeText),
    Column('license_id', types.UnicodeText),
    Column('type', types.UnicodeText),
)

vdm.sqlalchemy.make_table_stateful(package_table)
package_revision_table = make_revisioned_table(package_table)

## -------------------
## Mapped classes


class Package(vdm.sqlalchemy.RevisionedObjectMixin,
              vdm.sqlalchemy.StatefulObjectMixin, DomainObject):

    text_search_fields = ['name', 'title']

    def __init__(self, **kw):
        from ckan import model
        super(Package, self).__init__(**kw)
        resource_group = model.ResourceGroup(label="default")
        self.resource_groups.append(resource_group)
Exemplo n.º 9
0
member_table = Table('member', meta.metadata,
                     Column('id', types.UnicodeText,
                            primary_key=True,
                            default=_types.make_uuid),
                     Column('table_name', types.UnicodeText,
                            nullable=False),
                     Column('table_id', types.UnicodeText,
                            nullable=False),
                     Column('capacity', types.UnicodeText,
                            nullable=False),
                     Column('group_id', types.UnicodeText,
                            ForeignKey('group.id')),)

vdm.sqlalchemy.make_table_stateful(member_table)
member_revision_table = core.make_revisioned_table(member_table)

group_table = Table('group', meta.metadata,
                    Column('id', types.UnicodeText,
                           primary_key=True,
                           default=_types.make_uuid),
                    Column('name', types.UnicodeText,
                           nullable=False, unique=True),
                    Column('title', types.UnicodeText),
                    Column('type', types.UnicodeText,
                           nullable=False),
                    Column('description', types.UnicodeText),
                    Column('image_url', types.UnicodeText),
                    Column('created', types.DateTime,
                           default=datetime.datetime.now),
                    Column('is_organization', types.Boolean, default=False),
Exemplo n.º 10
0
    Column('url_type', types.UnicodeText),
    Column('extras', _types.JsonDictType),
)

resource_group_table = Table(
    'resource_group', meta.metadata,
    Column('id', types.UnicodeText, primary_key=True,
           default=_types.make_uuid),
    Column('package_id', types.UnicodeText, ForeignKey('package.id')),
    Column('label', types.UnicodeText),
    Column('sort_order', types.UnicodeText),
    Column('extras', _types.JsonDictType),
)

vdm.sqlalchemy.make_table_stateful(resource_table)
resource_revision_table = core.make_revisioned_table(resource_table)

vdm.sqlalchemy.make_table_stateful(resource_group_table)
resource_group_revision_table = core.make_revisioned_table(
    resource_group_table)


class Resource(vdm.sqlalchemy.RevisionedObjectMixin,
               vdm.sqlalchemy.StatefulObjectMixin,
               domain_object.DomainObject):
    extra_columns = None

    def __init__(self, resource_group_id=None, url=u'',
                 format=u'', description=u'', hash=u'',
                 extras=None,
                 **kwargs):
Exemplo n.º 11
0
import domain_object

__all__ = ['GroupExtra', 'group_extra_table', 'GroupExtraRevision']

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

vdm.sqlalchemy.make_table_stateful(group_extra_table)
group_extra_revision_table = core.make_revisioned_table(group_extra_table)


class GroupExtra(vdm.sqlalchemy.RevisionedObjectMixin,
                 vdm.sqlalchemy.StatefulObjectMixin,
                 domain_object.DomainObject):
    pass


meta.mapper(
    GroupExtra,
    group_extra_table,
    properties={
        'group':
        orm.relation(
            group.Group,
Exemplo n.º 12
0
__all__ = [
    'system_info_revision_table', 'system_info_table', 'SystemInfo',
    'SystemInfoRevision', 'get_system_info', 'set_system_info'
]

system_info_table = Table(
    'system_info',
    meta.metadata,
    Column('id', types.Integer(), primary_key=True, nullable=False),
    Column('key', types.Unicode(100), unique=True, nullable=False),
    Column('value', types.UnicodeText),
    Column('state', types.UnicodeText, default=core.State.ACTIVE),
)

system_info_revision_table = core.make_revisioned_table(system_info_table)


class SystemInfo(vdm.sqlalchemy.RevisionedObjectMixin,
                 core.StatefulObjectMixin, domain_object.DomainObject):
    def __init__(self, key, value):

        super(SystemInfo, self).__init__()

        self.key = key
        self.value = text_type(value)


meta.mapper(SystemInfo,
            system_info_table,
            extension=[
Exemplo n.º 13
0

__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],
Exemplo n.º 14
0
__all__ = ['PackageExtra', 'package_extra_table']

package_extra_table = Table('package_extra', meta.metadata,
    Column('id', types.UnicodeText, primary_key=True, default=_types.make_uuid),
    # NB: only (package, key) pair is unique
    Column('package_id', types.UnicodeText, ForeignKey('package.id')),
    Column('key', types.UnicodeText),
    Column('value', types.UnicodeText),
    Column('state', types.UnicodeText, default=core.State.ACTIVE),
)

# Define the package_extra_revision table, but no need to map it, as it is only
# used by migrate_package_activity.py
extra_revision_table = \
    core.make_revisioned_table(package_extra_table, frozen=True)


class PackageExtra(
        core.StatefulObjectMixin,
        domain_object.DomainObject):

    def related_packages(self):
        return [self.package]


meta.mapper(PackageExtra, package_extra_table, properties={
    'package': orm.relation(_package.Package,
        backref=orm.backref('_extras',
            collection_class=orm.collections.attribute_mapped_collection(u'key'),
            cascade='all, delete, delete-orphan',
Exemplo n.º 15
0
import core
import types as _types
import domain_object


__all__ = ['GroupExtra', 'group_extra_table', 'GroupExtraRevision']

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

vdm.sqlalchemy.make_table_stateful(group_extra_table)
group_extra_revision_table = core.make_revisioned_table(group_extra_table)


class GroupExtra(vdm.sqlalchemy.RevisionedObjectMixin,
        vdm.sqlalchemy.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',
            ),
        )
    },