• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python orm.Mapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中ming.orm.Mapper的典型用法代码示例。如果您正苦于以下问题:Python Mapper类的具体用法?Python Mapper怎么用?Python Mapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Mapper类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     self.datastore = DS.DataStore(
         'mim:///', database='test_db')
     self.session = ORMSession(bind=self.datastore)
     class BasicMapperExtension(MapperExtension):
         def after_insert(self, instance, state):
             assert 'clean'==state.status
         def before_insert(self, instance, state):
             assert 'new'==state.status
         def before_update(self, instance, state):
             assert 'dirty'==state.status
         def after_update(self, instance, state):
             assert 'clean'==state.status
     class Basic(MappedClass):
         class __mongometa__:
             name='basic'
             session = self.session
             extensions = [BasicMapperExtension]
         _id = FieldProperty(S.ObjectId)
         a = FieldProperty(int)
         b = FieldProperty([int])
         c = FieldProperty(dict(
                 d=int, e=int))
     Mapper.compile_all()
     self.Basic = Basic
     self.session.remove(self.Basic)
开发者ID:terrasea,项目名称:ming,代码行数:26,代码来源:test_declarative.py


示例2: setUp

 def setUp(self):
     self.datastore = DS.DataStore(
         'mim:///', database='test_db')
     self.session = ThreadLocalORMSession(Session(bind=self.datastore))
     class Parent(MappedClass):
         class __mongometa__:
             name='parent'
             session = self.session
         _id = FieldProperty(S.ObjectId)
     Mapper.compile_all()
     self.Parent = Parent
     self.create_app =  TestApp(MingMiddleware(self._wsgi_create_object))
     self.remove_app =  TestApp(MingMiddleware(self._wsgi_remove_object))
     self.remove_exc =  TestApp(MingMiddleware(self._wsgi_remove_object_exc))
开发者ID:terrasea,项目名称:ming,代码行数:14,代码来源:test_middleware.py


示例3: command

 def command(self):
     from allura import model as M
     main_session_classes = [M.main_orm_session, M.repository_orm_session,
             M.task_orm_session]
     if asbool(self.config.get('activitystream.recording.enabled', False)):
         from activitystream.storage.mingstorage import activity_orm_session
         main_session_classes.append(activity_orm_session)
     self.basic_setup()
     main_indexes = defaultdict(lambda: defaultdict(list))  # by db, then collection name
     project_indexes = defaultdict(list)  # by collection name
     base.log.info('Collecting indexes...')
     for m in Mapper.all_mappers():
         mgr = m.collection.m
         cname = mgr.collection_name
         cls = m.mapped_class
         if cname is None:
             base.log.info('... skipping abstract class %s', cls)
             continue
         base.log.info('... for class %s', cls)
         if session(cls) in main_session_classes:
             idx = main_indexes[session(cls)][cname]
         else:
             idx = project_indexes[cname]
         idx.extend(mgr.indexes)
     base.log.info('Updating indexes for main DB')
     for odm_session, db_indexes in main_indexes.iteritems():
         db = odm_session.impl.db
         for name, indexes in db_indexes.iteritems():
             self._update_indexes(db[name], indexes)
     base.log.info('Updating indexes for project DB')
     db = M.project_doc_session.db
     base.log.info('... DB: %s', db)
     for name, indexes in project_indexes.iteritems():
         self._update_indexes(db[name], indexes)
     base.log.info('Done updating indexes')
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:35,代码来源:show_models.py


示例4: command

    def command(self):
        from allura import model as M
#        self.basic_setup()

        existing_thumbs = 0
        base.log.info('Collecting application attachment classes')
        package_model_map = {}
        for m in Mapper.all_mappers():
            sess = m.session
            cls = m.mapped_class
            if issubclass(cls, M.BaseAttachment):
                if sess is M.project_orm_session:
                    package = cls.__module__.split('.', 1)[0]
                    l = package_model_map.get(package, [])
                    l.append(cls)
                    package_model_map[package] = l

        if len(self.args) > 1:
            projects = M.Project.query.find({'shortname': self.args[1]})
        else:
            projects = M.Project.query.find()
        for p in projects:
            base.log.info('=' * 20)
            base.log.info("Processing project '%s'", p.shortname)
            c.project = p

            if self.options.force:
                existing_thumbs += M.BaseAttachment.query.find({'type': 'thumbnail'}).count()
                base.log.info('Removing %d current thumbnails (per --force)', existing_thumbs)
                M.BaseAttachment.query.remove({'type': 'thumbnail'})

            # ProjectFile's live in main collection (unlike File's)
            # M.ProjectFile.query.find({'app_config_id': None, 'type': 'attachment'}).all()

            for app in p.app_configs:
                base.log.info("Processing application '%s' mounted at '%s' of type '%s'", app.options['mount_label'], app.options['mount_point'], app.tool_name)

                # Any application may contain DiscussionAttachment's, it has discussion_id field
                self.process_att_of_type(M.DiscussionAttachment, {'app_config_id': app._id, 'discussion_id': {'$ne': None}})

                # Otherwise, we'll take attachment classes belonging to app's package
                ep = iter_entry_points('allura', app.tool_name).next()
                app_package = ep.module_name.split('.', 1)[0]
                if app_package == 'allura':
                    # Apps in allura known to not define own attachment types
                    continue

                classes = package_model_map.get(app_package, [])
                for cls in classes:
                    self.process_att_of_type(cls, {'app_config_id': app._id, 'discussion_id': None})

                base.log.info('-' * 10)

        base.log.info('Recreated %d thumbs', self.created_thumbs)
        if self.options.force:
            if existing_thumbs != self.created_thumbs:
                base.log.warning('There were %d thumbs before --force operation started, but %d recreated', existing_thumbs, self.created_thumbs)

        ThreadLocalORMSession.flush_all()
开发者ID:jekatgithub,项目名称:incubator-allura,代码行数:59,代码来源:rethumb.py


示例5: build_model_inheritance_graph

def build_model_inheritance_graph():
    graph = dict((m.mapped_class, ([], [])) for m in Mapper.all_mappers())
    for cls, (parents, children)  in graph.iteritems():
        for b in cls.__bases__:
            if b not in graph: continue
            parents.append(b)
            graph[b][1].append(cls)
    return graph
开发者ID:johnsca,项目名称:incubator-allura,代码行数:8,代码来源:show_models.py


示例6: command

 def command(self):
     from allura import model as M
     self.basic_setup()
     main_indexes = defaultdict(lambda: defaultdict(list))  # by db, then collection name
     project_indexes = defaultdict(list)  # by collection name
     base.log.info('Collecting indexes...')
     for m in Mapper.all_mappers():
         mgr = m.collection.m
         cname = mgr.collection_name
         cls = m.mapped_class
         if cname is None:
             base.log.info('... skipping abstract class %s', cls)
             continue
         base.log.info('... for class %s', cls)
         if session(cls) in (
             M.main_orm_session, M.repository_orm_session, M.task_orm_session):
             idx = main_indexes[session(cls)][cname]
         else:
             idx = project_indexes[cname]
         idx.extend(mgr.indexes)
     base.log.info('Updating indexes for main DB')
     for odm_session, db_indexes in main_indexes.iteritems():
         db = odm_session.impl.db
         for name, indexes in db_indexes.iteritems():
             self._update_indexes(db[name], indexes)
     base.log.info('Updating indexes for project DBs')
     configured_dbs = set()
     for projects in utils.chunked_find(M.Project):
         for p in projects:
             db = p.database_uri
             if db in configured_dbs: continue
             configured_dbs.add(db)
             c.project = p
             db = M.project_doc_session.db
             base.log.info('... DB: %s', db)
             for name, indexes in project_indexes.iteritems():
                 self._update_indexes(db[name], indexes)
     if not configured_dbs:
         # e.g. during bootstrap with no projects
         db = M.project_doc_session.db
         base.log.info('... default DB: %s', db)
         for name, indexes in project_indexes.iteritems():
             self._update_indexes(db[name], indexes)
     base.log.info('Done updating indexes')
开发者ID:johnsca,项目名称:incubator-allura,代码行数:44,代码来源:show_models.py


示例7: html_text

    @property
    def html_text(self):
        """A markdown processed version of the page text"""
        return g.markdown_wiki.cached_convert(self, 'text')

    def authors(self):
        """All the users that have edited this page"""
        def uniq(users):
            t = {}
            for user in users:
                t[user.username] = user.id
            return t.values()
        user_ids = uniq([r.author for r in self.history().all()])
        return User.query.find({'_id': {'$in': user_ids}}).all()

    def delete(self):
        Shortlink.query.remove(dict(ref_id=self.index_id()))
        self.deleted = True
        suffix = " {:%Y-%m-%d %H:%M:%S.%f}".format(datetime.utcnow())
        self.title += suffix


class WikiAttachment(BaseAttachment):
    ArtifactType = Page

    class __mongometa__:
        polymorphic_identity = 'WikiAttachment'
    attachment_type = FieldProperty(str, if_missing='WikiAttachment')

Mapper.compile_all()
开发者ID:AsylumCorp,项目名称:incubator-allura,代码行数:30,代码来源:wiki.py



注:本文中的ming.orm.Mapper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python orm.ThreadLocalORMSession类代码示例发布时间:2022-05-27
下一篇:
Python orm.state函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap