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


Python SearchType.get_related_types方法代码示例

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


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

示例1: get_child_codes

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_related_types [as 别名]
    def get_child_codes(self, parent_collection_code, search_type):
        '''
        All of the children's codes down the relationship tree of the collection 
        will be returned.
        '''

        from pyasm.biz import Project
        project = Project.get()
        sql = project.get_sql()
        impl = project.get_database_impl()
        search_codes = []

        parts = search_type.split("/")
        collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1])

        # Check if connection between asset and asset_in_asset is in place
        if collection_type not in SearchType.get_related_types(search_type):
            return search_codes

        stmt = impl.get_child_codes_cte(collection_type, search_type, parent_collection_code)

        results = sql.do_query(stmt)
        for result in results:
            result = "".join(result)
            search_codes.append(result)

        return search_codes
开发者ID:mincau,项目名称:TACTIC,代码行数:29,代码来源:global_search_trigger.py

示例2: delete_sobject

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_related_types [as 别名]
    def delete_sobject(my, sobject):

        search_type = sobject.get_base_search_type()

        # this is used by API method delete_sobject
        auto_discover = my.kwargs.get("auto_discover")
        
        values = my.kwargs.get("values")
        if values:
            related_types = values.get("related_types")
        elif auto_discover:
            related_types = SearchType.get_related_types(search_type, direction="children")
        else:
            related_types = None

        # always delete notes and task and snapshot
        #if not related_types:
        #    related_types = ['sthpw/note', 'sthpw/task', 'sthpw/snapshot']
        #related_types = my.schema.get_related_search_types(search_type)
        if related_types:
            for related_type in related_types:
                if not related_type or related_type == search_type:
                    continue

                # snapshots take care of sthpw/file in the proper manner, so
                # skip them here
                if related_type == 'sthpw/file':
                    continue

                related_sobjects = sobject.get_related_sobjects(related_type)
                for related_sobject in related_sobjects:
                    if related_type == 'sthpw/snapshot':
                        my.delete_snapshot(related_sobject)
                    else:
                        related_sobject.delete()


        # implicitly remove "directory" files associated with the sobject
        search = Search("sthpw/file")
        search.add_op("begin")
        search.add_filter("file_name", "")
        search.add_null_filter("file_name")
        search.add_op("or")
        search.add_parent_filter(sobject)
        file_objects = search.get_sobjects()
        for file_object in file_objects:
            base_dir = Environment.get_asset_dir()
            relative_dir = file_object.get("relative_dir")
            lib_dir = "%s/%s" % (base_dir, relative_dir)
            print "removing: ", lib_dir
            FileUndo.rmdir(lib_dir)
            file_object.delete()


        # finally delete the sobject
        print "deleting: ", sobject.get_search_key()
        if search_type == 'sthpw/snapshot':
            my.delete_snapshot(sobject)
        else:
            sobject.delete()
开发者ID:davidsouthpaw,项目名称:TACTIC,代码行数:62,代码来源:delete_wdg.py

示例3: delete_sobject

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_related_types [as 别名]
    def delete_sobject(self, sobject):

        search_type = sobject.get_base_search_type()

        # this is used by API method delete_sobject
        auto_discover = self.kwargs.get("auto_discover")
        
        values = self.kwargs.get("values")
        if values:
            related_types = values.get("related_types")
        elif auto_discover:
            related_types = SearchType.get_related_types(search_type, direction="children")
        else:
            related_types = None

        return self.do_delete(sobject, related_types)
开发者ID:mincau,项目名称:TACTIC,代码行数:18,代码来源:delete_wdg.py

示例4: get_display

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_related_types [as 别名]
    def get_display(self):
        top = self.top
        self.set_as_panel(top)
        top.add_class("spt_delete_top")
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_border()
        top.add_style("width: 400px")
        top.add_border()


        search_key = self.kwargs.get("search_key")
        search_keys = self.kwargs.get("search_keys")
        if search_key:
            sobject = Search.get_by_search_key(search_key)
            sobjects = [sobject]
            search_keys = [search_key]
        elif search_keys:
            sobjects = Search.get_by_search_keys(search_keys)
            sobject = sobjects[0]

        if not sobjects or not sobject:
            msg =  "%s not found" %search_key
            return msg
        search_type = sobject.get_base_search_type()

        if search_type in ['sthpw/project', 'sthpw/search_object']:
            msg = 'You cannot delete these items with this tool'
            return msg


        self.search_keys = search_keys


        title = DivWdg()
        top.add(title)

        icon = IconWdg("WARNING", IconWdg.WARNING)
        icon.add_style("float: left")
        title.add(icon)

        if len(self.search_keys) > 1:
            title.add("Delete %s Items" % len(self.search_keys))
        else:
            title.add("Delete Item [%s]" % (sobject.get_code()))
        title.add_style("font-size: 20px")
        title.add_style("font-weight: bold")
        title.add_style("padding: 10px")

        title.add("<hr/>")

        content = DivWdg()
        top.add(content)
        content.add_style("margin: 5px 10px 20px 10px")


        content.add("The item to be deleted has a number of dependencies as described below:<br/>", 'heading')

        # find all the relationships
        related_types = SearchType.get_related_types(search_type, direction='children') 
       
        items_div = DivWdg()
        content.add( items_div )
        items_div.add_style("padding: 10px")
        valid_related_ctr = 0
        for related_type in related_types:
            if related_type == "*":
                print("WARNING: related_type is *")
                continue
            if related_type == search_type:
                continue
            if related_type in ['sthpw/search_object','sthpw/search_type']:
                continue

            item_div = self.get_item_div(sobjects, related_type)
            if item_div:
                items_div.add(item_div)
                valid_related_ctr += 1


        

        if valid_related_ctr > 0:
            #icon = IconWdg("Note", "BS_NOTE")
            #icon.add_style("float: left")
            #content.add( icon )
            content.add("<div><b>By selecting the above, the corresponding related items will be deleted as well.</b></div>")
            content.add("<br/>"*2)
        else:
            # changed the heading to say no dependencies
            content.add("The item to be deleted has no dependencies.<br/>", 'heading')


        num_items = len(self.search_keys)
        if num_items == 1:
            verb = "is 1 item"
        else:
            verb = "are %s items" % num_items
        content.add("There %s to be deleted" % verb)
        content.add("<br/>"*2)
#.........这里部分代码省略.........
开发者ID:mincau,项目名称:TACTIC,代码行数:103,代码来源:delete_wdg.py

示例5: update_collection_keywords

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_related_types [as 别名]
    def update_collection_keywords(self, mode, base_search_type, input):
        '''
        When there is an entry being added or removed in the asset_in_asset table
        (ie. adding asset to collection, removing asset from collection, or deleting 
        a collection), the "collection" data set in the keywords_data needs to be
        updated.
        '''

        # this is only for collections types
        stype_obj = SearchType.get(base_search_type)
        if stype_obj.get_value('type') != 'collection':
            return


        asset_in_asset_sobject = input.get("sobject")
        asset_stypes = SearchType.get_related_types(base_search_type, direction="parent")
        if not asset_stypes:
            return


        asset_stype = asset_stypes[0]

        parent_code = asset_in_asset_sobject.get("parent_code")
        search_code = asset_in_asset_sobject.get("search_code")
        
        parent_sobject = Search.get_by_code(asset_stype, parent_code)
        child_sobject = Search.get_by_code(asset_stype, search_code)
        
        collection_keywords_dict = {}
        parent_collection_keywords_dict = {}

        # Existing "collection" keywords in child's keywords_data
        child_keywords_data = child_sobject.get_json_value("keywords_data", {})
        if isinstance(child_keywords_data, basestring):
            raise TacticException("Invalid data found in keywords_data for %s. Please notify site administrator to correct it."%child_sobject.get_code())

       
        # check for old data structure with only keywords filled and initialize if necessary
        if not child_keywords_data:
            user_keywords = child_sobject.get_value('user_keywords')
            original_keywords = child_sobject.get_value('keywords')
            if original_keywords and not user_keywords:
                # initiatize keywords_data in this case
                child_keywords_data['user'] = original_keywords
                child_sobject.set_value('user_keywords', original_keywords)


        # Existing "collection" keywords in parent's keywords_data
        parent_keywords_data = parent_sobject.get_json_value("keywords_data", {})

        # keywords of parent
        parent_collection_keywords = parent_keywords_data.get('user')
        
        if 'collection' in child_keywords_data:
            collection_keywords_dict = child_keywords_data.get('collection')

        if 'collection' in parent_keywords_data:
            parent_collection_keywords_dict = parent_keywords_data.get('collection')

        if mode == "insert":
            # Add parent's user defined keywords
            if parent_collection_keywords:
                collection_keywords_dict[parent_code] = parent_collection_keywords

            # Also append parent's "collection" keywords_data
            collection_keywords_dict.update(parent_collection_keywords_dict)

            # Find all children that has [search_code] in their collection's keys
            # and update
            child_codes = self.get_child_codes(search_code, asset_stype)

            if child_codes:
                child_nest_sobjects = Search.get_by_code(asset_stype, child_codes)
                for child_nest_sobject in child_nest_sobjects:
                    
                    child_nest_collection_keywords_data = child_nest_sobject.get_json_value("keywords_data", {})
                    child_nest_collection_keywords = child_nest_collection_keywords_data['collection']
                    child_nest_collection_keywords.update(collection_keywords_dict)

                    child_nest_sobject.set_json_value("keywords_data", child_nest_collection_keywords_data)
                    child_nest_sobject.commit(triggers=False)
                    self.set_searchable_keywords(child_nest_sobject)
        
        elif mode == "delete":

            child_codes = []
            if parent_code in collection_keywords_dict:
                # Remove "collection" keywords_data from child with key matching parent_code
                del collection_keywords_dict[parent_code]

                # Also need to remove parent's "collection" keywords_data from child
                for key in parent_collection_keywords_dict.keys():
                    del collection_keywords_dict[key]

                child_codes = self.get_child_codes(search_code, asset_stype)
            
            if child_codes:
                child_nest_sobjects = Search.get_by_code(asset_stype, child_codes)
                for child_nest_sobject in child_nest_sobjects:
                    child_nest_collection_keywords_data = child_nest_sobject.get_json_value("keywords_data", {})
#.........这里部分代码省略.........
开发者ID:mincau,项目名称:TACTIC,代码行数:103,代码来源:global_search_trigger.py

示例6: get_display

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_related_types [as 别名]
    def get_display(my):
        top = my.top
        my.set_as_panel(top)
        top.add_class("spt_delete_top")
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_border()
        top.add_style("width: 300px")
        top.add_border()


        search_key = my.kwargs.get("search_key")
        search_keys = my.kwargs.get("search_keys")
        if search_key:
            sobject = Search.get_by_search_key(search_key)
            sobjects = [sobject]
            search_keys = [search_key]
        elif search_keys:
            sobjects = Search.get_by_search_keys(search_keys)
            sobject = sobjects[0]

        if not sobjects:
            msg =  "%s not found" %search_key
            return msg
        search_type = sobject.get_base_search_type()

        if search_type in ['sthpw/project', 'sthpw/search_object']:
            msg = 'You cannot delete these items with this tool'
            return msg


        my.search_keys = search_keys


        title = DivWdg()
        top.add(title)
        title.add_color("background", "background", -10)
        if my.search_keys:
            title.add("Delete %s Items" % len(my.search_keys))
        else:
            title.add("Delete Item [%s]" % (sobject.get_code()))
        title.add_style("font-size: 14px")
        title.add_style("font-weight: bold")
        title.add_style("padding: 10px")

        content = DivWdg()
        top.add(content)
        content.add_style("padding: 10px")


        content.add("The item to be deleted has a number of dependencies as described below:<br/>", 'heading')

        # find all the relationships
        related_types = SearchType.get_related_types(search_type, direction='children') 
       
        items_div = DivWdg()
        content.add( items_div )
        items_div.add_style("padding: 10px")
        valid_related_ctr = 0
        for related_type in related_types:
            if related_type == "*":
                print "WARNING: related_type is *"
                continue
            if related_type == search_type:
                continue
            if related_type in ['sthpw/search_object','sthpw/search_type']:
                continue

            item_div = my.get_item_div(sobjects, related_type)
            if item_div:
                items_div.add(item_div)
                valid_related_ctr += 1


        

        if valid_related_ctr > 0:
            icon = IconWdg("WARNING", IconWdg.WARNING)
            icon.add_style("float: left")
            content.add( icon )
            content.add("<div><b>WARNING: By selecting the related items above, you can delete them as well when deleting this sObject.</b></div>")
            content.add("<br/>"*2)
        else:
            # changed the heading to say no dependencies
            content.add("The item to be deleted has no dependencies.<br/>", 'heading')


        content.add("There are %s items to be deleted" % len(my.search_keys))
        content.add("<br/>"*2)

        content.add("Do you wish to continue deleting?")
        content.add("<br/>"*2)

        button_div = DivWdg()
        button_div.add_styles('width: 300px; height: 50px')
        button = ActionButtonWdg(title="Delete")
        button_div.add(button)
        content.add(button_div)
        button.add_style("float: left")

#.........这里部分代码省略.........
开发者ID:davidsouthpaw,项目名称:TACTIC,代码行数:103,代码来源:delete_wdg.py


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