当前位置: 首页>>代码示例>>Python>>正文


Python Search.add_relationship_filters方法代码示例

本文整理汇总了Python中pyasm.search.Search.add_relationship_filters方法的典型用法代码示例。如果您正苦于以下问题:Python Search.add_relationship_filters方法的具体用法?Python Search.add_relationship_filters怎么用?Python Search.add_relationship_filters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyasm.search.Search的用法示例。


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

示例1: handle_snapshots

# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_relationship_filters [as 别名]
    def handle_snapshots(my):


        path = "__snapshot_files.spt"
        path = "%s/%s" % (my.plugin_dir, path)
        print "Writing: ", path
        # write out an empty file
        #f = open(path, 'w')

        fmode = 'w'
        if os.path.exists(path):
            fmode = 'a'
        f = codecs.open(path, fmode, 'utf-8')
        f.close()


        # get all of the latest snapshots for this plugin
        search = Search("sthpw/snapshot")
        search.add_parent_filter(my.plugin)
        search.add_filter("is_latest", True)
        snapshots = search.get_sobjects()

        if not snapshots:
            return

        # dump out these snapshots
        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects(snapshots)
        dumper.dump_tactic_inserts(path, mode='sobject')

        # get all of the files for all of the snapshots and copy the director
        # structure


        # get all of the latest snapshots for this plugin
        search = Search("sthpw/file")
        search.add_relationship_filters(snapshots)
        files = search.get_sobjects()

        # dump out these snapshots
        dumper = TableDataDumper()
        dumper.set_delimiter("#-- Start Entry --#", "#-- End Entry --#")
        dumper.set_include_id(False)
        dumper.set_sobjects(files)
        dumper.dump_tactic_inserts(path, mode='sobject')

        new_dir = "%s/files" % (my.plugin_dir)
        if not os.path.exists(new_dir):
            os.makedirs(new_dir)

        for snapshot in snapshots:
            paths = snapshot.get_all_lib_paths(mode="lib")
            for path in paths:
                file_name = os.path.basename(path)
                new_path = "%s/%s" % (new_dir, file_name)

                shutil.copy(path, new_path)
开发者ID:talha81,项目名称:TACTIC-DEV,代码行数:61,代码来源:plugin.py

示例2: alter_search

# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_relationship_filters [as 别名]
    def alter_search(self, search):

        expression = self.kwargs.get("column")
        if not expression:
            expression = self.values.get("%s_column" % self.prefix)
        if not expression:
            return
        parts = expression.split(".")
        search_types = parts[:-1]
        column = parts[-1]

        # go through the hierarchy
        sobjects = None
        search2 = None
        if len(search_types) > 1:
            search_types.reverse()
            for search_type in search_types:
                if sobjects == None:
                    self._alter_search(search, column)
                else:
                    search2 = Search(search_type)
                    search2.add_relationship_filters(sobjects)
                    sobjects = search2.get_sobjects()

                if not sobjects:
                    # if the trail ends, then set the null filter and exit
                    search.set_null_filter()
                    return


        elif not search_types:
            self._alter_search(search, column)
            return
        else:
            search_type = search_types[0]

            # get all the sobjects at the appropriate hierarchy
            search2 = Search(search_type)
            self._alter_search(search2, column)
            sobjects = search2.get_sobjects()

        if search2:
            search.add_relationship_search_filter(search2)
        elif sobjects:
            search.add_relationship_filters(sobjects)
        else:
            search.set_null_filter()
开发者ID:mincau,项目名称:TACTIC,代码行数:49,代码来源:type_filter_element_wdg.py

示例3: get_by_sobjects

# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_relationship_filters [as 别名]
    def get_by_sobjects(sobjects, process=None, order=True):

        if not sobjects:
            return []


        # quickly go through the sobjects to determine if their search types
        # are the same
        multi_stypes = False
        for sobject in sobjects:
            if sobject.get_search_type() != sobjects[0].get_search_type():
                multi_stypes = True
                break

        
        search = Search( Task.SEARCH_TYPE )
        if multi_stypes:
            # sort this into a dictionary and make multiple calls to 
            # search.add_relationship_filters
            # use the first sobject as a sample
            sobjects_dict = {}
            for sobject in sobjects:
                st = sobject.get_search_type()
                sobj_list = sobjects_dict.get(st)
                if sobj_list == None:
                    sobjects_dict[st] = [sobject]
                else:
                    sobj_list.append(sobject)

        
            search.add_op('begin')
            for key, sobj_list in sobjects_dict.items():
                search.add_op('begin')
                search.add_relationship_filters(sobj_list)
                search.add_op('and')
            search.add_op('or')



        else:

            from pyasm.biz import Schema
            schema = Schema.get()

            # FIXME: why doesn't the ops work here?
            filters = []
            search.add_relationship_filters(sobjects)
            """
            for sobject in sobjects:
                search_type = sobject.get_search_type()
                attrs = schema.get_relationship_attrs("sthpw/task", search_type)
                attrs = schema.resolve_relationship_attrs(attrs, "sthpw/task", search_type)
                search_code = sobject.get_value(attrs.get("to_col"))
                #search_code = sobject.get_value("code")
                #search.add_filter('search_type', search_type)
                #search.add_filter('search_id', search_id, quoted=False)
                #search.add_op("and")
                if attrs.get("from_col") == "search_code":
                    filters.append("search_type = '%s' and search_code = '%s'" % (search_type, search_code))
                else:
                    filters.append("search_type = '%s' and search_id = %s" % (search_type, search_code))
            search.add_where(" or ".join(filters))
            """

        search.add_order_by("search_type")

        search.add_order_by("search_code")
        search.add_order_by("search_id")



        # get the pipeline of the sobject
        pipeline = Pipeline.get_by_sobject(sobject)
        if order:
            if pipeline:
                process_names = pipeline.get_process_names(True)
                search.add_enum_order_by("process", process_names)
            else:
                search.add_order_by("process")

            search.add_order_by("id")

        if process:
           
            if isinstance(process, basestring):
                search.add_filter("process", process)
            else:
                search.add_filters("process", process)

        tasks = search.get_sobjects()
        return tasks
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:93,代码来源:task.py

示例4: _test_schema

# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_relationship_filters [as 别名]

#.........这里部分代码省略.........
        # add bunch of dummy initial tasks to the person
        initial_tasks = Task.add_initial_tasks(my.person, 'task')

        # check status_log static trigger
        single_task = initial_tasks[0]
        from pyasm.search import Search

        to_status = Search.eval('@GET(sthpw/status_log.to_status)', sobjects=[single_task], single=True)
        my.assertEquals(to_status, "Assignment")
        single_task.set_value('status', "Test Done")
        single_task.commit(triggers=True)
        

        ExpressionParser.clear_cache() 
        to_status = Search.eval("@GET(sthpw/status_log['@ORDER_BY','id desc'].to_status)", sobjects=[single_task], single=True)
        
        my.assertEquals(to_status, "Test Done")

        # get tasks with get_all_children()
        tasks = my.person.get_all_children("sthpw/task")
        my.assertEquals(len(initial_tasks), len(tasks) )

        
        # get notes with get_all_children()
        Note.create(my.person, "test note", context='default')
        Note.create(my.person, "test note2", context='default2')
        notes = my.person.get_all_children("sthpw/note")
        my.assertEquals(2, len(notes) )

        #relationship
        schema = Schema.get()
        if Project.get_by_code('sample3d'):
            relationship = schema.get_relationship('prod/asset','sthpw/snapshot')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

            relationship = schema.get_relationship('prod/asset','sthpw/task')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

            relationship = schema.get_relationship('prod/shot','sthpw/note')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

        relationship = schema.get_relationship('sthpw/file','sthpw/snapshot')
        my.assertEquals(relationship, 'code')
        relationship = schema.get_relationship('sthpw/project_type','sthpw/project')
        my.assertEquals(relationship, 'code')

        relationship = schema.get_relationship('unittest/car','unittest/house')
        my.assertEquals(relationship, None)

        # test parent filter search in sample3d
        if Project.get_by_code('sample3d'):
            from pyasm.prod.biz import *
            Project.set_project('sample3d')

            shot = Shot.get_by_code('RC_001_001')
            if not shot:
                shot = Shot.create('RC_001_001', 'Some test shot')
            asset = SearchType.create('prod/asset')
            asset.set_value('code','unittest010')
            asset.set_value('name','unittest010')
            asset.commit()
            for x in xrange(3):
                ShotInstance.create(shot, asset, 'unittest_veh_001', unique=False) 
            
            instances = ShotInstance.get_by_shot_and_asset(shot, asset)
            parent_type = 'prod/shot'
            parent_search = Search(parent_type)
            parent_search.add_filter('code','RC_001_001')
        
            search = Search('prod/shot_instance') 
            search.add_filter('asset_code', asset.get_code())
            # we want the base here
            sobject_type = search.get_search_type_obj().get_base_key()

            schema = Schema.get()
            relationship = schema.get_relationship(sobject_type, parent_type)
            parents = parent_search.get_sobjects()
            if parents:
                if relationship in ["code", "id", "search_type"]:
                    search.add_relationship_filters(parents) 
                    
            sobjects = search.get_sobjects()
            my.assertEquals(len(instances), len(sobjects))

            
            relationship_attrs = schema.get_relationship_attrs('sthpw/transaction_log','sthpw/sobject_log')
            rev_relationship_attrs = schema.get_relationship_attrs('sthpw/sobject_log','sthpw/transaction_log')
            for attrs in [ relationship_attrs,  rev_relationship_attrs]:
                my.assertEquals(attrs.get('from_col'), 'transaction_log_id')
                my.assertEquals(attrs.get('to_col'), 'id')
                my.assertEquals(attrs.get('from'), 'sthpw/sobject_log')
                my.assertEquals(attrs.get('to'), 'sthpw/transaction_log')
                my.assertEquals(attrs.get('relationship'), 'id')
                my.assertEquals(attrs.get('disabled'), None)


        Project.set_project('unittest')
开发者ID:funic,项目名称:TACTIC,代码行数:104,代码来源:biz_test.py


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