本文整理汇总了Python中meta.mapper函数的典型用法代码示例。如果您正苦于以下问题:Python mapper函数的具体用法?Python mapper怎么用?Python mapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Activity
class Activity(domain_object.DomainObject):
def __init__(self, user_id, object_id, revision_id, activity_type, data=None):
self.id = _types.make_uuid()
self.timestamp = datetime.datetime.now()
self.user_id = user_id
self.object_id = object_id
self.revision_id = revision_id
self.activity_type = activity_type
if data is None:
self.data = {}
else:
self.data = data
meta.mapper(Activity, activity_table)
class ActivityDetail(domain_object.DomainObject):
def __init__(self, activity_id, object_id, object_type, activity_type, data=None):
self.activity_id = activity_id
self.object_id = object_id
self.object_type = object_type
self.activity_type = activity_type
if data is None:
self.data = {}
else:
self.data = data
@classmethod
def by_activity_id(cls, activity_id):
示例2: reverse_type
@classmethod
def reverse_type(cls, forward_or_reverse_type):
for fwd, rev in cls.types:
if fwd == forward_or_reverse_type:
return rev
if rev == forward_or_reverse_type:
return fwd
@classmethod
def make_type_printable(cls, type_):
for i, types in enumerate(cls.types):
for j in range(2):
if type_ == types[j]:
return cls.types_printable[i][j]
raise TypeError, type_
meta.mapper(PackageRelationship, package_relationship_table, properties={
'subject':orm.relation(_package.Package, primaryjoin=\
package_relationship_table.c.subject_package_id==_package.Package.id,
backref='relationships_as_subject'),
'object':orm.relation(_package.Package, primaryjoin=package_relationship_table.c.object_package_id==_package.Package.id,
backref='relationships_as_object'),
},
extension = [vdm.sqlalchemy.Revisioner(package_relationship_revision_table)]
)
vdm.sqlalchemy.modify_base_object_mapper(PackageRelationship, core.Revision, core.State)
PackageRelationshipRevision = vdm.sqlalchemy.create_object_version(
meta.mapper, PackageRelationship, package_relationship_revision_table)
示例3: RatingValueException
class RatingValueException(Exception):
pass
# import here to prevent circular import
import tag
meta.mapper(Package, package_table, properties={
# delete-orphan on cascade does NOT work!
# Why? Answer: because of way SQLAlchemy/our code works there are points
# where PackageTag object is created *and* flushed but does not yet have
# the package_id set (this cause us other problems ...). Some time later a
# second commit happens in which the package_id is correctly set.
# However after first commit PackageTag does not have Package and
# delete-orphan kicks in to remove it!
'package_tags':orm.relation(tag.PackageTag, backref='package',
cascade='all, delete', #, delete-orphan',
),
},
order_by=package_table.c.name,
extension=[vdm.sqlalchemy.Revisioner(package_revision_table),
extension.PluginMapperExtension(),
],
)
vdm.sqlalchemy.modify_base_object_mapper(Package, core.Revision, core.State)
PackageRevision = vdm.sqlalchemy.create_object_version(meta.mapper, Package,
package_revision_table)
def related_packages(self):
return [self.continuity]
示例4: isinstance
assert isinstance(_domain_object, domain_object.DomainObject)
if isinstance(_domain_object, _package.Package):
q = meta.Session.query(PackageRole).filter_by(package=_domain_object)
elif isinstance(_domain_object, group.Group):
q = meta.Session.query(GroupRole).filter_by(group=_domain_object)
else:
raise NotImplementedError()
user_roles = q.all()
for user_role in user_roles:
meta.Session.delete(user_role)
## ======================================
## Mappers
meta.mapper(RoleAction, role_action_table)
meta.mapper(UserObjectRole, user_object_role_table,
polymorphic_on=user_object_role_table.c.context,
polymorphic_identity=u'user_object',
properties={
'user': orm.relation(_user.User,
backref=orm.backref('roles',
cascade='all, delete, delete-orphan'
)
),
'authorized_group': orm.relation(auth_group.AuthorizationGroup,
backref=orm.backref('authorized_roles',
cascade='all, delete, delete-orphan'
)
)
示例5: user_ids_for_name_or_id
else:
query = sqlalchemy_query
qstr = '%' + querystr + '%'
filters = [
cls.name.ilike(qstr),
cls.fullname.ilike(qstr),
]
# sysadmins can search on user emails
import ckan.authz as authz
if user_name and authz.is_sysadmin(user_name):
filters.append(cls.email.ilike(qstr))
query = query.filter(or_(*filters))
return query
@classmethod
def user_ids_for_name_or_id(self, user_list=[]):
'''
This function returns a list of ids from an input that can be a list of
names or ids
'''
query = meta.Session.query(self.id)
query = query.filter(or_(self.name.in_(user_list),
self.id.in_(user_list)))
return [user.id for user in query.all()]
meta.mapper(User, user_table,
properties={'password': synonym('_password', map_column=True)},
order_by=user_table.c.name)
示例6: setattr
'ckan.extra_resource_group_fields', '').split()
for field in cls.extra_columns:
setattr(cls, field, DictProxy(field, 'extras'))
return cls.extra_columns
## Mappers
meta.mapper(Resource, resource_table, properties={
'resource_group': orm.relation(
ResourceGroup,
# all resources including deleted
# formally package_resources_all
backref=orm.backref('resources_all',
collection_class=ordering_list('position'),
cascade='all, delete',
order_by=resource_table.c.position,
),
)
},
order_by=[resource_table.c.resource_group_id],
extension=[vdm.sqlalchemy.Revisioner(resource_revision_table),
extension.PluginMapperExtension(),
],
)
meta.mapper(ResourceGroup, resource_group_table, properties={
'package': orm.relation(
_package.Package,
# all resources including deleted
backref=orm.backref('resource_groups_all',
cascade='all, delete, delete-orphan',
示例7: related_packages
.filter(Tag.name==tag_name))
else:
query = (meta.Session.query(PackageTag)
.filter(_package.Package.name==package_name)
.filter(Tag.name==tag_name))
query = query.autoflush(autoflush)
return query.one()[0]
def related_packages(self):
return [self.package]
meta.mapper(Tag, tag_table, properties={
'package_tags': relation(PackageTag, backref='tag',
cascade='all, delete, delete-orphan',
),
'vocabulary': relation(vocabulary.Vocabulary,
order_by=tag_table.c.name)
},
order_by=tag_table.c.name,
)
meta.mapper(PackageTag, package_tag_table, properties={
'pkg':relation(_package.Package, backref='package_tag_all',
cascade='none',
)
},
order_by=package_tag_table.c.id,
extension=[vdm.sqlalchemy.Revisioner(package_tag_revision_table),
_extension.PluginMapperExtension(),
],
)
示例8: UserFollowingDataset
user_following_user_table = sqlalchemy.Table('user_following_user',
meta.metadata,
sqlalchemy.Column('follower_id', sqlalchemy.types.UnicodeText,
sqlalchemy.ForeignKey('user.id', onupdate='CASCADE',
ondelete='CASCADE'),
primary_key=True, nullable=False),
sqlalchemy.Column('object_id', sqlalchemy.types.UnicodeText,
sqlalchemy.ForeignKey('user.id', onupdate='CASCADE',
ondelete='CASCADE'),
primary_key=True, nullable=False),
sqlalchemy.Column('datetime', sqlalchemy.types.DateTime, nullable=False),
)
meta.mapper(UserFollowingUser, user_following_user_table)
class UserFollowingDataset(ModelFollowingModel):
'''A many-many relationship between users and datasets (packages).
A relationship between a user (the follower) and a dataset (the object),
that means that the user is currently following the dataset.
'''
@classmethod
def _follower_class(cls):
return ckan.model.User
@classmethod
def _object_class(cls):
return ckan.model.Package
示例9: setup_db
import sqlalchemy
from meta import Table, Column, UnicodeText, ForeignKey, mapper, metadata
__all__ = ['package_search_table']
def setup_db(event, schema_item, engine):
sql = 'ALTER TABLE package_search ADD COLUMN search_vector tsvector'
res = engine.execute(sql)
res.close()
package_search_table = Table('package_search', metadata,
Column('package_id', UnicodeText, ForeignKey('package.id'), primary_key=True),
)
class PackageSearch(object):
pass
# We need this mapper so that Package can delete orphaned package_search rows
mapper(PackageSearch, package_search_table, properties={})
package_search_table.append_ddl_listener('after-create', setup_db)
示例10:
res_dict = ckan.lib.dictization.table_dictize(self, context={"model": model})
return activity.ActivityDetail(activity_id, self.id, u"Resource", activity_type, {"resource": res_dict})
## Mappers
meta.mapper(
Resource,
resource_table,
properties={
"package": orm.relation(
Package,
# all resources including deleted
# formally package_resources_all
backref=orm.backref(
"resources_all",
collection_class=ordering_list("position"),
cascade="all, delete",
order_by=resource_table.c.position,
),
)
},
order_by=[resource_table.c.package_id],
extension=[vdm.sqlalchemy.Revisioner(resource_revision_table), extension.PluginMapperExtension()],
)
## VDM
vdm.sqlalchemy.modify_base_object_mapper(Resource, core.Revision, core.State)
ResourceRevision = vdm.sqlalchemy.create_object_version(meta.mapper, Resource, resource_revision_table)
示例11: add_user_to_authorization_group
q = q.filter(AuthorizationGroup.users.contains(user))
return q.count() == 1
def add_user_to_authorization_group(user, authorization_group, role):
assert not user_in_authorization_group(user, authorization_group)
from authz import add_user_to_role
meta.Session.add(authorization_group)
authorization_group.users.append(user)
add_user_to_role(user, role, authorization_group)
def remove_user_from_authorization_group(user, authorization_group):
assert user_in_authorization_group(user, authorization_group)
from authz import remove_user_from_role, AuthorizationGroupRole
meta.Session.add(authorization_group)
authorization_group.users.remove(user)
q = meta.Session.query(AuthorizationGroupRole)
q = q.filter_by(authorization_group=authorization_group,
user=user)
for agr in q:
remove_user_from_role(user, agr.role, authorization_group)
meta.mapper(AuthorizationGroup, authorization_group_table, properties={
'users': orm.relation(user.User, lazy=True, secondary=authorization_group_user_table,
backref=orm.backref('authorization_groups', lazy=True))
},
order_by=authorization_group_table.c.name)
meta.mapper(AuthorizationGroupUser, authorization_group_user_table)
示例12: GroupExtra
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",
),
)
},
order_by=[group_extra_table.c.group_id, group_extra_table.c.key],
extension=[vdm.sqlalchemy.Revisioner(group_extra_revision_table)],
)
vdm.sqlalchemy.modify_base_object_mapper(GroupExtra, core.Revision, core.State)
GroupExtraRevision = vdm.sqlalchemy.create_object_version(meta.mapper, GroupExtra, group_extra_revision_table)
def _create_extra(key, value):
return GroupExtra(key=unicode(key), value=value)
示例13: Table
__all__ = ['Rating', 'MIN_RATING', 'MAX_RATING']
MIN_RATING = 1.0
MAX_RATING = 5.0
rating_table = Table('rating', meta.metadata,
Column('id', types.UnicodeText, primary_key=True, default=_types.make_uuid),
Column('user_id', types.UnicodeText, ForeignKey('user.id')),
Column('user_ip_address', types.UnicodeText), # alternative to user_id if not logged in
Column('package_id', types.UnicodeText, ForeignKey('package.id')),
Column('rating', types.Float),
Column('created', types.DateTime, default=datetime.datetime.now),
)
class Rating(domain_object.DomainObject):
pass
meta.mapper(Rating, rating_table,
properties={
'user': orm.relation(user.User,
backref=orm.backref('ratings',
cascade='all, delete, delete-orphan'
)),
'package': orm.relation(_package.Package,
backref=orm.backref('ratings',
cascade='all, delete, delete-orphan'
)),
},
)
示例14: search
)
if capacity:
q = q.filter(model.Member.capacity == capacity)
return q.all()
if "_groups" not in self.__dict__:
self._groups = q.all()
groups = self._groups
if group_type:
groups = [g for g in groups if g.type == group_type]
return groups
@classmethod
def search(cls, querystr, sqlalchemy_query=None):
"""Search name, fullname, email and openid. """
if sqlalchemy_query is None:
query = meta.Session.query(cls)
else:
query = sqlalchemy_query
qstr = "%" + querystr + "%"
query = query.filter(
or_(cls.name.ilike(qstr), cls.fullname.ilike(qstr), cls.openid.ilike(qstr), cls.email.ilike(qstr))
)
return query
meta.mapper(
User, user_table, properties={"password": synonym("_password", map_column=True)}, order_by=user_table.c.name
)
示例15: Activity
class Activity(domain_object.DomainObject):
def __init__(self, user_id, object_id, revision_id, activity_type,
data=None):
self.id = _types.make_uuid()
self.timestamp = datetime.datetime.now()
self.user_id = user_id
self.object_id = object_id
self.revision_id = revision_id
self.activity_type = activity_type
if data is None:
self.data = {}
else:
self.data = data
meta.mapper(Activity, activity_table)
class ActivityDetail(domain_object.DomainObject):
def __init__(self, activity_id, object_id, object_type, activity_type,
data=None):
self.activity_id = activity_id
self.object_id = object_id
self.object_type = object_type
self.activity_type = activity_type
if data is None:
self.data = {}
else:
self.data = data
meta.mapper(ActivityDetail, activity_detail_table, properties = {