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


Python Xml.append_child方法代码示例

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


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

示例1: add_attr_access

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def add_attr_access(self, search_type, attr, level):
        # find the group
        group_xpath = "rules/group[@key='%s']" % (search_type)
        group = self.xml.get_node(group_xpath)
        if group == None:
            # add the group (default to view)
            group_level = "view"
            group = self.add_sobject_access(search_type,group_level)


        # get the attr rule
        rule_xpath = "rules/group[@key='%s']/rule[@key='%s']" % (search_type,attr)
        rule = self.xml.get_node(rule_xpath )
        if rule != None:
            # if nothing has changed, continue
            access = Xml.get_attribute(rule,"access")
            if level == access:
                raise CommandExitException()
        else:
            rule = self.xml.create_element("rule")
            rule.setAttributeNS(None,"key",attr)

            #group.appendChild(rule)
            Xml.append_child(group, rule)

            #self.root.appendChild(group)
            Xml.append_child(self.root, group)


        # set the access level
        rule.setAttributeNS(None,"type","attr")
        rule.setAttributeNS(None,"access",level)
开发者ID:mincau,项目名称:TACTIC,代码行数:34,代码来源:add_user_to_group_cmd.py

示例2: get_by_code

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def get_by_code(cls, code, allow_default=False):
        '''it is fatal not to have a pipeline, so put a default'''
        if not code:
            return None

        # first look at project specific pipeline
        pipeline = Search.get_by_code("config/pipeline", code)

        if not pipeline:
            pipeline = super(Pipeline,cls).get_by_code(code)

        if not pipeline and code == 'task':
            # Create a default task pipeline
            pipeline = SearchType.create("sthpw/pipeline")
            pipeline.set_value("code", "task")
            from pyasm.biz import Task
            xml = Task.get_default_task_xml()
            pipeline.set_value("pipeline", xml)
            pipeline.set_pipeline(xml)
            pipeline.set_value("search_type", "sthpw/task")
            #pipeline.commit()


        if not pipeline and allow_default:
            search = Search(cls)
            search.add_filter('code', 'default')
            pipeline = search.get_sobject()
            if not pipeline:
                
                pipeline = cls.create('default',  \
                    'default pipeline', '')

                xml = pipeline.get_xml_value("pipeline")

                # create a default process for the table
                root = xml.get_root_node()
                element = xml.create_element("process")
                Xml.set_attribute(element,"name", "default_process")
                Xml.append_child(root, element)

                pipeline.set_value('pipeline', xml.get_xml())
                pipeline.commit()
                
                # set the pipeline
                pipeline.set_pipeline(pipeline.get_value('pipeline'))
                Environment.add_warning("pipeline autogenerated", \
                    "[default] pipeline has just been created.")
        # Sometimes, a pipeline is instantiated without calling set_pipeline()
        # to be looked into
        if pipeline and not pipeline.get_processes():
            pipeline.set_pipeline(pipeline.get_value('pipeline'))
        return pipeline
开发者ID:funic,项目名称:TACTIC,代码行数:54,代码来源:pipeline.py

示例3: execute

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def execute(my):

        class_names = my.kwargs.get("class_names")
        attrs_list = my.kwargs.get("attrs_list")
        kwargs_list = my.kwargs.get("kwargs_list")

        xml = Xml()
        xml.create_doc("config")
        root = xml.get_root_node()

        view = xml.create_element("tab")
        xml.append_child(root, view)

        for class_name, attrs, kwargs in zip(class_names, attrs_list, kwargs_list):

            element = xml.create_element("element")
            xml.append_child(view, element)

            for key, value in attrs.items():
                xml.set_attribute(element, key, value)

            display = xml.create_element("display")
            xml.append_child(element, display)

            xml.set_attribute(display, "class", class_name)

            for key, value in kwargs.items():
                attr = xml.create_text_element(key, value, node=display)
                xml.append_child(display, attr)

        xml_string = xml.to_string()

        from pyasm.web import WidgetSettings
        WidgetSettings.set_value_by_key("tab", xml_string)
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:36,代码来源:page_nav_container_wdg.py

示例4: _get_main_config

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def _get_main_config(self, view, process_names):
        '''get the main config for this table layout'''
        xml = Xml()
        xml.create_doc("config")
        root = xml.get_root_node()
        view_node = xml.create_element(view)
        #root.appendChild(view_node)
        xml.append_child(root, view_node)
        
        for idx, process_name in enumerate(process_names):
            element  = xml.create_element('element')
            Xml.set_attribute(element, 'name', process_name)
            #view_node.appendChild(element)
            xml.append_child(view_node, element)
            display =   xml.create_element('display')
            if self.element_class:
                Xml.set_attribute(display, 'class',self.element_class)
            else:
                Xml.set_attribute(display, 'class', "tactic.ui.app.NoteTableElementWdg")
            #element.appendChild(display)
            xml.append_child(element, display)

            op_element = xml.create_data_element('parent_key', self.search_key)
            xml.append_child(display, op_element)
            

        config_xml = xml.to_string()
        widget_config = WidgetConfig.get(view=view, xml = config_xml)
        widget_config_view = WidgetConfigView('sthpw/note', view, [widget_config])

        return widget_config_view
开发者ID:mincau,项目名称:TACTIC,代码行数:33,代码来源:note_wdg.py

示例5: dump

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def dump(my, plugin_code, project_code, search_types):

        xml = Xml()
        my.xml = xml

        xml.create_doc("manifest")
        manifest_node = xml.get_root_node()
        xml.set_attribute(manifest_node, "code", plugin_code)

        # DUMP the data
        for search_type in search_types:

            data_node = xml.create_element("search_type")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "code", search_type)

            # This exports the data
            """
            data_node = xml.create_element("sobject")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "search_type", search_type)

            # find the currval 
            st_obj = SearchType.get(search_type)
            # have to call nextval() to initiate this sequence in the session in psql since Postgres 8.1
            seq_id = st_obj.sequence_nextval()
            
            seq_id = st_obj.sequence_currval()

            seq_id -= 1
            if seq_id > 0:
                st_obj.sequence_setval(seq_id)
            xml.set_attribute(data_node, "seq_max", seq_id)
            """
            


        print xml.to_string()

        # create a virtual plugin
        plugin = SearchType.create("sthpw/plugin")
        plugin.set_value("version", "1.0.0")
        plugin.set_value("code", "%s_project" % project_code)

        base_dir = "./templates"
        creator = PluginCreator( base_dir=base_dir, plugin=plugin, manifest=xml.to_string() )
        creator.execute()
开发者ID:0-T-0,项目名称:TACTIC,代码行数:49,代码来源:schema_dump_cmd.py

示例6: _add_access

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def _add_access(self, type, key, level):

        # find if a rule for this already exists
        rule = self.xml.get_node("rules/group[@key='%s']" % key)
        if rule != None:
            # if nothing has changed, continue
            access = Xml.get_attribute(rule,"access")
            if level == access:
                raise CommandExitException()
        else:
            rule = self.xml.create_element("group")
            rule.setAttributeNS(None,"key",key)

        # set the access level
        rule.setAttributeNS(None,"type",type)
        rule.setAttributeNS(None,"access",level)
        #self.root.appendChild(rule)
        Xml.append_child(self.root, rule)

        return rule
开发者ID:mincau,项目名称:TACTIC,代码行数:22,代码来源:add_user_to_group_cmd.py

示例7: _get_edit_config

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
 def _get_edit_config(self, view, process_names):
     xml = Xml()
     xml.create_doc("config")
     root = xml.get_root_node()
     view_node = xml.create_element(view)
     #root.appendChild(view_node)
     xml.append_child(root, view_node)
     for idx, process_name in enumerate(process_names):
         element  = xml.create_element('element')
         Xml.set_attribute(element, 'name', process_name)
         #view_node.appendChild(element)
         xml.append_child(view_node, element)
         display =   xml.create_element('display')
         Xml.set_attribute(display, 'class', "pyasm.widget.TextAreaWdg")
         #element.appendChild(display)
         xml.append_child(element, display)
     
     config_xml = xml.to_string()
     widget_config = WidgetConfig.get(view=view, xml = config_xml)
     widget_config_view = WidgetConfigView('sthpw/note', view, [widget_config])
     return widget_config_view
开发者ID:mincau,项目名称:TACTIC,代码行数:23,代码来源:note_wdg.py

示例8: handle_basic_mode

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def handle_basic_mode(my):

        doc = my.xml.create_doc("config")
        root = my.xml.get_root_node()
        
        db_columns = my.get_columns()

        if "code" in db_columns:
            columns = ["preview", "code"]
        elif "name" in db_columns:
            columns = ["preview", "name"]
        elif "id" in db_columns:
            columns = ["preview", "id"]


        table = my.xml.create_element("table")
        Xml.append_child(root, table)
        for column in ["preview", "code"]:
            element = my.xml.create_element("element")
            Xml.set_attribute(element, "name", column)
            Xml.append_child(table, element)

        # create the edit
        edit = my.xml.create_element("edit")
        Xml.append_child(root, edit)

        for column in ["preview", "code"]:
            element = my.xml.create_element("element")
            Xml.set_attribute(element, "name", column)
            Xml.append_child(edit, element)


        # create the manual publish view
        publish = my.xml.create_element("publish")
        Xml.append_child(root, publish)
        element = my.xml.create_element("element")
        Xml.set_attribute(element, "name", "image")
        Xml.append_child(publish, element)
        dis_element = my.xml.create_element("display")
        Xml.set_attribute(dis_element, "class", "ThumbInputWdg")
        act_element = my.xml.create_element("action")
        Xml.set_attribute(act_element, "class", "NullAction")
        Xml.append_child(element, dis_element)
        Xml.append_child(element, act_element)

        element = my.xml.create_element("element")
        Xml.set_attribute(element, "name", "publish_files")
        Xml.append_child(publish, element)
        dis_element = my.xml.create_element("display")
        Xml.set_attribute(dis_element, "class", "UploadWdg")
        # add options
        option = my.xml.create_text_element('names','publish_icon|publish_main')
        Xml.append_child(dis_element, option)
        option = my.xml.create_text_element('required','false|true')
        Xml.append_child(dis_element, option)

        act_element = my.xml.create_element("action")
        Xml.set_attribute(act_element, "class", "MultiUploadAction")
        # add options
        option = my.xml.create_text_element('names','publish_icon|publish_main')
        Xml.append_child(act_element, option)
        option = my.xml.create_text_element('types','icon_main|main')
        Xml.append_child(act_element, option)
        Xml.append_child(element, dis_element)
        Xml.append_child(element, act_element)

        value = my.xml.to_string()
        my.xml = Xml()
        my.xml.read_string(value)
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:71,代码来源:sobject_default_config.py

示例9: export_template

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def export_template(my):

        xml = Xml()
        my.xml = xml

        xml.create_doc("manifest")
        manifest_node = xml.get_root_node()

        # Old implementation.  Code is now on the data node
        xml.set_attribute(manifest_node, "code", my.template_project_code)

        # dump the notification entries
        data_node = xml.create_element("data")
        xml.append_child(manifest_node, data_node)

        code_node = xml.create_element("code")
        xml.append_child(data_node, code_node)
        xml.set_node_value(code_node, my.template_project_code)

        version = my.kwargs.get("version") or ""
        version_node = xml.create_element("version")
        xml.append_child(data_node, version_node)
        xml.set_node_value(version_node, version)



        # dump the project entry
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/project['code','%s'])" % my.project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/project")
        xml.set_attribute(data_node, "unique", "true")

        # dump the project_type entry
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/project['code','%s'].sthpw/project_type)" % my.project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/project_type")
        xml.set_attribute(data_node, "unique", "true")


        # dump the schema entry
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/schema['code','%s'])" % my.project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/schema")
        xml.set_attribute(data_node, "unique", "true")

        # find the project template search types
        namespace = my.project_type
        if not namespace or namespace == "default":
            namespace = my.project_code
        project_search_types = Search.eval("@GET(sthpw/search_object['namespace','%s'].search_type)" % namespace)

        #project_types = Search.eval("@GET(sthpw/search_object['namespace','%s'].search_type)" % my.project_code)

        # just dump the definition for data
        for search_type in project_search_types:
            data_node = xml.create_element("search_type")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "code", search_type)


        search_types = [
            "config/custom_script",
            "config/widget_config",
            "config/naming",
            "config/client_trigger",
            "config/process",
            "config/trigger",
            "config/url",

            #"config/ingest_rule",
            #"config/ingest_session",
        ]

        for search_type in search_types:
            data_node = xml.create_element("sobject")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "search_type", search_type)

            # find the currval 
            st_obj = SearchType.get(search_type)
            # have to call nextval() to initiate this sequence in the session in psql since Postgres 8.1
            seq_id = SearchType.sequence_nextval(search_type)
            
            seq_id = SearchType.sequence_currval(search_type)

            seq_id -= 1
            if seq_id > 0:
                SearchType.sequence_setval(search_type, seq_id)
            xml.set_attribute(data_node, "seq_max", seq_id)
            
            #xml.set_attribute(data_node, "path", "data.spt")


       



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

示例10: execute

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
    def execute(self):

        import datetime
        now = datetime.datetime.now()
        version = now.strftime("%Y%m%d_%H%M%S")


        project_code = self.kwargs.get("project_code")
        if project_code:
            project = Project.get_by_code(project_code)
        else:
            project = Project.get()
        project_code = project.get_code()

        server_code = self.kwargs.get("server")
        assert server_code

        if not isinstance(server_code, basestring):
            server_code = server_code.get_value("code")


        base_dir = self.kwargs.get('base_dir')
        ticket = Environment.get_ticket()
        tmp_dir = "%s/sync_%s" % (Environment.get_tmp_dir(), ticket)
        if not os.path.exists(tmp_dir):
            os.makedirs(tmp_dir)


        server = Search.get_by_code("sthpw/sync_server", server_code)
        if server.get_value("sync_mode") == "file":
            if not base_dir:
                base_dir = server.get_value("base_dir")

        else:
            raise Exception("sync mode [%s] not support" % sync_mode)
            # FIXME: not sure if this is valid anymore
            asset_dir = Environment.get_asset_dir()
            base_dir = "%s/_temp" % asset_dir


        # create the project template
        from tactic.command import ProjectTemplateCreatorCmd
        cmd = ProjectTemplateCreatorCmd(project_code=project_code, version=version, base_dir=tmp_dir)
        cmd.execute()

        project_path = cmd.get_zip_path()


        # create zip of the project files
        from pyasm.common import ZipUtil
        zip_util = ZipUtil()
        asset_dir = Environment.get_asset_dir()
        project_dir = "%s/%s" % (asset_dir, project_code)

        zip_dir = "%s/%s" % (tmp_dir, project_code)
        file_path = "%s-files-%s.zip" % (zip_dir, version)

        if os.path.exists(file_path):
            os.unlink(file_path)
        zip_util.zip_dir2(project_dir, zip_path=file_path)




        # create a manifest for all the data in the project.
        xml = Xml()
        self.xml = xml

        xml.create_doc("manifest")
        manifest_node = xml.get_root_node()
        xml.set_attribute(manifest_node, "code", "%s-data" % project_code)

        search_types = project.get_search_types()

        # just dump the data
        for search_type in search_types:
            data_node = xml.create_element("sobject")
            xml.append_child(manifest_node, data_node)
            xml.set_attribute(data_node, "search_type", search_type.get_value("search_type"))


        # dump the note entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/note['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/note")


        # dump the task entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/task['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/task")


        # dump the snapshot entries
        data_node = xml.create_element("sobject")
        xml.append_child(manifest_node, data_node)
        xml.set_attribute(data_node, "expression", "@SOBJECT(sthpw/snapshot['project_code','%s'])" % project_code)
        xml.set_attribute(data_node, "search_type", "sthpw/snapshot")
#.........这里部分代码省略.........
开发者ID:mincau,项目名称:TACTIC,代码行数:103,代码来源:sync_settings_wdg.py

示例11: PageNavContainerWdg

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]

#.........这里部分代码省略.........
            </application>
            </config>
            '''
        return config









    def set_state(self, panel_name, widget_class, options, values):
        '''this is called by side_bar.js mostly'''

        # set the class name
        display_node = self.config_xml.get_node("config/application/element[@name='%s']/display" % (panel_name) )
        self.config_xml.set_attribute(display_node, "class", widget_class)

        # remove all the old options
        #display_node = self.config_xml.get_node("config/application/element[@name='%s']/display" % panel_name )
        for child_node in self.config_xml.get_children(display_node):
            self.config_xml.remove_child(display_node, child_node)

        # set the options
        for name, value in options.items():
            node = self.config_xml.get_node("config/application/element[@name='%s']/display/%s" % (panel_name, name) )

            if isinstance( value, basestring ):
                #print("WARNING: set application: skipping [%s] with value [%s]" % (name, value))
                #continue
                element = self.config_xml.create_text_element(name, value)
                self.config_xml.append_child(display_node, element)

            elif isinstance( value, dict): # if it is a dictionary
                # TODO: run recursively.. supports 2 level only now
                sub_element = self.config_xml.create_element(name)
                self.config_xml.append_child(display_node, element)
                for name2, value2 in value.items():
                    if isinstance(value2, dict):
                        sub_element2 = self.config_xml.create_element(name2)
                        self.config_xml.append_child(sub_element, sub_element2)
                        for name3, value3 in value2.items():
                            element = self.config_xml.create_text_element(name3, value3)
                            self.config_xml.append_child(sub_element2, element)
                    else:        
                        element = self.config_xml.create_text_element(name2, value2)
                        self.config_xml.append_child(sub_element, element)
                    
                
        # web value node
        value_node = self.config_xml.get_node("config/application/element[@name='%s']/web" % (panel_name) )
        if value_node != None:
            for child_node in self.config_xml.get_children(value_node):
                self.config_xml.remove_child(value_node, child_node)
        else: # create it
            value_node = self.config_xml.create_element('web')
            element_node = self.config_xml.get_node("config/application/element[@name='%s']" % (panel_name) )
            self.config_xml.append_child(element_node, value_node)

        # set the values
        for name, value in values.items():
            node = self.config_xml.get_node("config/application/element[@name='%s']/web/%s" % (panel_name, name) )

            if not isinstance(value, basestring):
开发者ID:mincau,项目名称:TACTIC,代码行数:70,代码来源:page_nav_container_wdg.py

示例12: SObjectDefaultConfig

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
class SObjectDefaultConfig(Base):
    '''An artificial config file is made if none are found'''

    def __init__(self, search_type, view, config_base=None, mode="columns"):

        self.search_type = search_type

        if view:
            self.view = view
        else:
            self.view = config_base
        if not self.view:
            self.view = "table"

        # bit of protection ... : have been known to show up in view names
        self.view = self.view.replace(":", '_')

        #mode = "basic"

        self.xml = Xml()

        if mode == 'columns':
            self.handle_columns_mode()
        else:
            self.handle_basic_mode()


    def get_columns(self, required_only=False):
        if self.search_type == 'sthpw/virtual':
            return []

        search_type_obj = SearchType.get(self.search_type)
        table = search_type_obj.get_table()

        from pyasm.biz import Project
        db_resource = Project.get_db_resource_by_search_type(self.search_type)
        database_name = db_resource.get_database()
        db = DbContainer.get(db_resource)

        # table may not exist
        try:
            all_columns = db.get_columns(table)
            columns = []
            if required_only:
                nullables = db.get_column_nullables(table)
                for column in all_columns:
                    null_ok = nullables.get(column)
                    if not null_ok:
                        columns.append(column)

                # if there are no required columns
                if not columns:
                    columns = all_columns 
                
            else:
                columns = all_columns 
        except SqlException:
            Environment.add_warning('missing table', 'Table [%s] does not exist in database [%s]' %(table, database_name))
            return  []

        return columns




    def handle_basic_mode(self):

        doc = self.xml.create_doc("config")
        root = self.xml.get_root_node()
        
        db_columns = self.get_columns()

        if "code" in db_columns:
            columns = ["preview", "code"]
        elif "name" in db_columns:
            columns = ["preview", "name"]
        elif "id" in db_columns:
            columns = ["preview", "id"]


        table = self.xml.create_element("table")
        Xml.append_child(root, table)
        for column in ["preview", "code"]:
            element = self.xml.create_element("element")
            Xml.set_attribute(element, "name", column)
            Xml.append_child(table, element)

        # create the edit
        edit = self.xml.create_element("edit")
        Xml.append_child(root, edit)

        for column in ["preview", "code"]:
            element = self.xml.create_element("element")
            Xml.set_attribute(element, "name", column)
            Xml.append_child(edit, element)


        # create the manual publish view
        publish = self.xml.create_element("publish")
        Xml.append_child(root, publish)
#.........这里部分代码省略.........
开发者ID:mincau,项目名称:TACTIC,代码行数:103,代码来源:sobject_default_config.py

示例13: SyncFilter

# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import append_child [as 别名]
class SyncFilter(object):

    def __init__(self, **kwargs):
        self.kwargs = kwargs

        self.log = self.kwargs.get("transaction")
        self.rules = self.kwargs.get("rules")
        self.message = ""


    def execute(self):
        log = self.log
        rules = self.rules

        # Give rules.  Only notes will get through
        # we need heirarchical rules.  This will ensure that only notes
        # for project/assets will pass
        # Here, the second one is much more difficult to do.
        rulesXXX = '''
        <rule group='heirarchy' key='project/asset.sthpw/note' access='allow'/>
        <rule group='heirarchy' key="project/asset.sthpw/note['assigned','beth']" access='allow'/>"
        '''

        access_manager = AccessManager()
        access_manager.add_xml_rules(rules)


        # filter out project
        namespace = log.get_value("namespace")
        key1 = { 'code': namespace }
        key2 = { 'code': '*' }
        keys = [key1, key2]
        if not access_manager.check_access("project", keys, "allow", default="deny"):
            self.filtered_xml = Xml()
            self.filtered_xml.read_string("<transaction/>")
            self.message = "Transaction prevented due to project restriction"
            return


        # filter the transaction against the security model
        xml = log.get_xml_value("transaction")

        self.filtered_xml = Xml()
        self.filtered_xml.create_doc("transaction")
        root2 = self.filtered_xml.get_root_node()

        nodes = xml.get_nodes("transaction/*")
        num_nodes = len(nodes)
        count = 0


        for node in nodes:
            if Xml.get_node_name(node) ==  "sobject":
                search_type = xml.get_attribute(node, "search_type")
                parts = search_type.split("?")
                search_type = parts[0]

                # filter search types
                key1 = { 'code': search_type }
                key2 = { 'code': "*" }
                keys = [ key1, key2 ]
                if not access_manager.check_access("search_type", keys, "allow", default="deny"):
                    continue

                # check hierachical rule
                parent_type = xml.get_attribute(node, "parent_type")
                key = "%s.%s" % (parent_type, search_type)
                
                self.filtered_xml.append_child(root2, node)
                count += 1
                
            else:
                self.filtered_xml.append_child(root2, node)
                count += 1

        if len(nodes) != 0 and len(self.filtered_xml.get_nodes("transaction/*")) == 0:
            self.message = "All actions filtered due to security restrictions (%s actions)" % num_nodes



    def get_filtered_xml(self):
        return self.filtered_xml

    def get_message(self):
        return self.message
开发者ID:mincau,项目名称:TACTIC,代码行数:87,代码来源:sync_filter.py


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