コード例 #1
0
 def handle_config(self):
     '''for search type display config'''
     web = WebContainer.get_web()
     WidgetDbConfig.append(self.search_type,
                           self.view,
                           self.element_name,
                           config_xml=self.config_xml)
コード例 #2
0
 def handle_config(my):
     '''for search type display config'''
     web = WebContainer.get_web()
     WidgetDbConfig.append(my.search_type,
                           my.view,
                           my.element_name,
                           config_xml=my.config_xml)
コード例 #3
0
ファイル: custom_view_wdg.py プロジェクト: rajubuddha/TACTIC
    def execute(my):
        web = WebContainer.get_web()
        view = web.get_form_value("create_view_name")
        if not view:
            print("WARNING: Create View name not found")
            return

        search_type = web.get_form_value("search_type")
        project = web.get_form_value("project")

        description = web.get_form_value("new_description")

        # TODO: where to get the template view from?
        #copy_from_template = web.get_form_value("copy_from_template")

        # get the current custom view
        #print "keys: ", web.get_form_keys()
        template_view = web.get_form_value("template_view")
        if template_view:
            current_view = template_view
        else:
            current_view = "custom"

        config = WidgetDbConfig.get_by_search_type(search_type, current_view)
        if not config:
            # create a new one
            config = WidgetDbConfig.create(search_type, current_view)

        # clean up view so that it has legal characters for xml
        title = view
        view = Common.get_filesystem_name(view)

        # get the config file
        new_config = WidgetDbConfig.create(search_type, view)

        xml = config.get_value("config")
        if xml:
            xml = xml.replace("<%s" % current_view, "<%s" % view)
            xml = xml.replace("/%s>" % current_view, "/%s>" % view)
            xml = xml.replace("<%s/>" % current_view, "<%s/>" % view)
        new_config.set_value("config", xml)
        new_config.commit()

        auto_create_edit = web.get_form_value('auto_create_edit') == 'on'
        # auto-create the edit config
        if auto_create_edit:
            search = Search("sthpw/widget_config")
            search.add_filter("search_type", search_type)
            search.add_filter("view", "edit")
            edit_config = search.get_sobject()
            if not edit_config:
                edit_config = WidgetDbConfig.create(search_type, "edit")

        my.description = "Created view [%s] for search_type [%s]" % (
            view, search_type)
コード例 #4
0
ファイル: custom_view_wdg.py プロジェクト: 0-T-0/TACTIC
    def execute(my):
        web = WebContainer.get_web()
        view = web.get_form_value("create_view_name")
        if not view:
            print("WARNING: Create View name not found")
            return

        search_type = web.get_form_value("search_type")
        project = web.get_form_value("project")

        description = web.get_form_value("new_description")

        # TODO: where to get the template view from?
        #copy_from_template = web.get_form_value("copy_from_template")

        # get the current custom view
        #print "keys: ", web.get_form_keys()
        template_view = web.get_form_value("template_view")
        if template_view:
            current_view = template_view
        else:
            current_view = "custom"

        config = WidgetDbConfig.get_by_search_type(search_type, current_view)
        if not config:
            # create a new one
            config = WidgetDbConfig.create(search_type, current_view)

        # clean up view so that it has legal characters for xml
        title = view
        view = Common.get_filesystem_name(view)

        # get the config file
        new_config = WidgetDbConfig.create(search_type, view)

        xml = config.get_value("config")
        if xml:
            xml = xml.replace("<%s" % current_view, "<%s" % view)
            xml = xml.replace("/%s>" % current_view, "/%s>" % view)
            xml = xml.replace("<%s/>" % current_view, "<%s/>" % view)
        new_config.set_value("config", xml)
        new_config.commit()

        auto_create_edit = web.get_form_value('auto_create_edit') == 'on'
        # auto-create the edit config
        if auto_create_edit:    
            search = Search("sthpw/widget_config")
            search.add_filter("search_type", search_type)
            search.add_filter("view", "edit")
            edit_config = search.get_sobject()
            if not edit_config:
                edit_config = WidgetDbConfig.create(search_type, "edit") 

        my.description = "Created view [%s] for search_type [%s]" % (view, search_type)
コード例 #5
0
ファイル: simple_search_wdg.py プロジェクト: zieglerm/TACTIC
    def get_config(self):

        self.view = self.kwargs.get("search_view")
        config = self.kwargs.get("search_config")

        if not self.view:
            self.view = 'custom_filter'
        #view = "custom_filter"

        project_code = Project.extract_project_code(self.search_type)

        search = Search("config/widget_config", project_code=project_code)
        search.add_filter("view", self.view)
        search.add_filter("search_type", self.base_search_type)
        config_sobjs = search.get_sobjects()

        from pyasm.search import WidgetDbConfig
        config_sobj = WidgetDbConfig.merge_configs(config_sobjs)

        if config_sobj:
            #config_xml = config_sobj.get("config")
            config_xml = config_sobj.get_xml().to_string()
            config_xml = config_xml.replace("&lt;", "<")
            config_xml = config_xml.replace("&gt;", ">")
            config_xml = Common.run_mako(config_xml)

        elif config:
            config_xml = '''
            <config>
            <custom_filter>%s
            </custom_filter>
            </config>
            ''' % config
        else:
            config_xml = '''
            <config>
            <custom_filter>
            </custom_filter>
            </config>
            '''
            # use the one defined in the default config file
            file_configs = WidgetConfigView.get_configs_from_file(
                self.base_search_type, self.view)
            if file_configs:
                config = file_configs[0]
                xml_node = config.get_view_node()
                if xml_node is not None:
                    xml = Xml(config.get_xml().to_string())
                    config_xml = '<config>%s</config>' % xml.to_string(
                        node=xml_node)

        from pyasm.widget import WidgetConfig
        config = WidgetConfig.get(view=self.view, xml=config_xml)

        return config
コード例 #6
0
ファイル: simple_search_wdg.py プロジェクト: mincau/TACTIC
    def get_config(self):


        self.view = self.kwargs.get("search_view")
        config = self.kwargs.get("search_config")

        if not self.view:
            self.view = 'custom_filter'
        #view = "custom_filter"

        project_code = Project.extract_project_code(self.search_type)

        search = Search("config/widget_config", project_code=project_code )
        search.add_filter("view", self.view)
        search.add_filter("search_type", self.base_search_type)
        config_sobjs = search.get_sobjects()

        from pyasm.search import WidgetDbConfig
        config_sobj = WidgetDbConfig.merge_configs(config_sobjs)

        if config_sobj:
            #config_xml = config_sobj.get("config")
            config_xml = config_sobj.get_xml().to_string()
            config_xml = config_xml.replace("&lt;", "<")
            config_xml = config_xml.replace("&gt;", ">")
            config_xml = Common.run_mako(config_xml)

        elif config:
            config_xml = '''
            <config>
            <custom_filter>%s
            </custom_filter>
            </config>
            ''' % config
        else:
            config_xml = '''
            <config>
            <custom_filter>
            </custom_filter>
            </config>
            '''
            # use the one defined in the default config file
            file_configs = WidgetConfigView.get_configs_from_file(self.base_search_type, self.view)
            if file_configs:
                config = file_configs[0]
                xml_node = config.get_view_node()
                if xml_node is not None:
                    xml = Xml(config.get_xml().to_string())
                    config_xml = '<config>%s</config>' %xml.to_string(node=xml_node)

            
        from pyasm.widget import WidgetConfig
        config = WidgetConfig.get(view=self.view, xml=config_xml)

        return config
コード例 #7
0
ファイル: column_edit_wdg.py プロジェクト: 0-T-0/TACTIC
    def execute(my):

        search_type = my.kwargs.get("search_type")
        column_info = SearchType.get_column_info(search_type)

        values = my.kwargs.get("values")

        # get the definition config for this search_type
        from pyasm.search import WidgetDbConfig
        config = WidgetDbConfig.get_by_search_type(search_type, "definition")
        if not config:
            config = SearchType.create("config/widget_config")
            config.set_value("search_type", search_type)
            config.set_value("view", "definition")
            config.commit()
            config._init()

        for data in values:

            name = data.get("name")
            name = name.strip()
            if name == '':
                continue

            try:
                name.encode('ascii')
            except UnicodeEncodeError:
                raise TacticException('Column name needs to be in English. Non-English characters can be used in Title when performing [Edit Column Definition] afterwards.')


            if column_info.get(name):
                raise CommandException("Column [%s] is already defined" % name)

            format = data.get("format")
            fps = data.get("fps")
            data_type = data.get("data_type")

            from pyasm.command import ColumnAddCmd
            cmd = ColumnAddCmd(search_type, name, data_type)
            cmd.execute()
            #(my, search_type, attr_name, attr_type, nullable=True):


            class_name = 'tactic.ui.table.FormatElementWdg'
            options = {
                'format': format,
                'type': data_type,
                'fps': fps
            }


            # add a new widget to the definition
            config.append_display_element(name, class_name, options=options)

        config.commit_config()
コード例 #8
0
ファイル: copy_config_cmd.py プロジェクト: rajubuddha/TACTIC
    def execute(my):
        project_type = "prod"

        # copy all of the widget configs from the prod definition and put
        # them into the database
        xml = Xml(string=test_xml)

        search_type = "SideBarWdg"
        view = "cow"
        config = WidgetDbConfig.create(search_type, view, data=xml.to_string())
        '''
コード例 #9
0
ファイル: edit_wdg.py プロジェクト: nuxping/TACTIC
    def get_config(my):
        # look in the db first
        configs = []
        config = WidgetDbConfig.get_by_search_type(my.search_type, my.view)
        get_edit_def = False
        if config:
            configs.append(config)
            get_edit_def = True
            config = WidgetDbConfig.get_by_search_type(my.search_type,
                                                       "edit_definition")
            if config:
                configs.append(config)

        #if my.mode == 'insert':
        #    config = WidgetDbConfig.get_by_search_type(my.search_type, "insert")
        #    if config:
        #        configs.append(config)
        # look for a definition
        #config = WidgetDbConfig.get_by_search_type(my.search_type, "edit")
        #if config:
        #    configs.append(config)

        file_configs = WidgetConfigView.get_configs_from_file(
            my.search_type, my.view)
        configs.extend(file_configs)

        file_configs = WidgetConfigView.get_configs_from_file(
            my.search_type, "edit")
        configs.extend(file_configs)

        #TODO: add edit_definition
        #file_configs = WidgetConfigView.get_configs_from_file(my.search_type, "edit_definition")
        #configs.extend(file_configs)
        if not get_edit_def:
            config = WidgetDbConfig.get_by_search_type(my.search_type,
                                                       "edit_definition")
            if config:
                configs.append(config)

        config = WidgetConfigView(my.search_type, my.view, configs)
        return config
コード例 #10
0
ファイル: copy_config_cmd.py プロジェクト: mincau/TACTIC
    def execute(self):
        project_type = "prod"

        # copy all of the widget configs from the prod definition and put
        # them into the database
        xml = Xml(string=test_xml)

        search_type = "SideBarWdg"
        view = "cow"
        config = WidgetDbConfig.create(search_type, view, data=xml.to_string())

        '''
コード例 #11
0
ファイル: column_edit_wdg.py プロジェクト: rajubuddha/TACTIC
    def execute(my):

        search_type = my.kwargs.get("search_type")
        column_info = SearchType.get_column_info(search_type)

        values = my.kwargs.get("values")

        # get the definition config for this search_type
        from pyasm.search import WidgetDbConfig
        config = WidgetDbConfig.get_by_search_type(search_type, "definition")
        if not config:
            config = SearchType.create("config/widget_config")
            config.set_value("search_type", search_type)
            config.set_value("view", "definition")
            config.commit()
            config._init()

        for data in values:

            name = data.get("name")
            name = name.strip()
            if name == '':
                continue

            try:
                name.encode('ascii')
            except UnicodeEncodeError:
                raise TacticException(
                    'Column name needs to be in English. Non-English characters can be used in Title when performing [Edit Column Definition] afterwards.'
                )

            if column_info.get(name):
                raise CommandException("Column [%s] is already defined" % name)

            format = data.get("format")
            fps = data.get("fps")
            data_type = data.get("data_type")

            from pyasm.command import ColumnAddCmd
            cmd = ColumnAddCmd(search_type, name, data_type)
            cmd.execute()
            #(my, search_type, attr_name, attr_type, nullable=True):

            class_name = 'tactic.ui.table.FormatElementWdg'
            options = {'format': format, 'type': data_type, 'fps': fps}

            # add a new widget to the definition
            config.append_display_element(name, class_name, options=options)

        config.commit_config()
コード例 #12
0
ファイル: edit_wdg.py プロジェクト: funic/TACTIC
    def get_config(my):
        # look in the db first
        configs = []
        config = WidgetDbConfig.get_by_search_type(my.search_type, my.view)
        get_edit_def = False
        if config:
            configs.append(config)
            get_edit_def = True
            config = WidgetDbConfig.get_by_search_type(my.search_type, "edit_definition")
            if config:
                configs.append(config)

        #if my.mode == 'insert':
        #    config = WidgetDbConfig.get_by_search_type(my.search_type, "insert")
        #    if config:
        #        configs.append(config)
        # look for a definition
        #config = WidgetDbConfig.get_by_search_type(my.search_type, "edit")
        #if config:
        #    configs.append(config)

        file_configs = WidgetConfigView.get_configs_from_file(my.search_type, my.view)
        configs.extend(file_configs)

        file_configs = WidgetConfigView.get_configs_from_file(my.search_type, "edit")
        configs.extend(file_configs)

        #TODO: add edit_definition    
        #file_configs = WidgetConfigView.get_configs_from_file(my.search_type, "edit_definition")
        #configs.extend(file_configs)
        if not get_edit_def:
            config = WidgetDbConfig.get_by_search_type(my.search_type, "edit_definition")
            if config:
                configs.append(config)
    
        config = WidgetConfigView(my.search_type, my.view, configs)
        return config
コード例 #13
0
    def get_display(my):

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_gradient("background", "background", 0, -5)
        #top.add_style("height: 550px")

        top.add_class("spt_reports_top")
        my.set_as_panel(top)

        inner = DivWdg()
        top.add(inner)


        title = DivWdg()
        title.add("Reports")
        title.add_style("font-size: 18px")
        title.add_style("font-weight: bold")
        title.add_style("text-align: center")
        title.add_style("padding: 10px")
        title.add_style("margin: -10px -10px 0px -10px")

        inner.add(title)
        title.add_gradient("background", "background3", 5, -10)


        from tactic.ui.widget import TitleWdg
        subtitle = TitleWdg(name_of_title='List of Built in Reports',help_alias='main')
        inner.add(subtitle)
        inner.add("<br/>")

        button_div = DivWdg()
        inner.add(button_div)
        button_div.add_class("spt_buttons_top")
        button_div.add_style("margin-top: -5px")
        button_div.add_style("margin-bottom: 30px")
        button_div.add_border()

        button_div.add_style("margin-top: -15px")
        button_div.add_style("margin-bottom: 0px")
        button_div.add_style("width: 100%")
        button_div.add_style("height: 33px")
        button_div.add_color("background", "background2")
        button_div.add_style("margin-left: auto")
        button_div.add_style("margin-right: auto")


        button = SingleButtonWdg(title="Collapse", icon=IconWdg.HOME)
        button_div.add(button)
        button.add_style("float: left")
        button.add_style("left: 5px")
        button.add_style("top: 5px")


        # FIXME: get home for the user
        #home = 'tactic.ui.startup.ContentCreatorWdg'
        home = 'tactic.ui.startup.MainWdg'


        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tab.set_main_body_tab();
            var class_name = 'tactic.ui.startup.MainWdg';
            var kwargs = {
                help_alias: 'main'
                };
            spt.tab.add_new("_startup", "Startup", class_name, kwargs);

            '''
        } )



        """
        button = SingleButtonWdg(title="Collapse", icon=IconWdg.ARROW_UP)
        button_div.add(button)
        button.add_class("spt_collapse")
        inner.add(button_div)
        button.add_style("float: left")
        button.add_style("left: 5px")
        button.add_style("top: 5px")

        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_reports_top");
            var element = top.getElement(".spt_reports_list");

            var buttons = bvr.src_el.getParent(".spt_buttons_top");
            expand = buttons.getElement(".spt_expand");
            new Fx.Tween(element).start('margin-top', "-400px");
            expand.setStyle("display", "");
            bvr.src_el.setStyle("display", "none");
            '''
        } )

        button = SingleButtonWdg(title="Expand", icon=IconWdg.ARROW_DOWN)
        button.add_style("display: none")
        button.add_class("spt_expand")
        button_div.add(button)
        button.add_style("left: 5px")
        button.add_style("top: 5px")
        inner.add(button_div)
        button.add_style("float: left")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_reports_top");
            var element = top.getElement(".spt_reports_list");

            var buttons = bvr.src_el.getParent(".spt_buttons_top");
            collapse = buttons.getElement(".spt_collapse");
            new Fx.Tween(element).start('margin-top', "0px");
            collapse.setStyle("display", "");
            bvr.src_el.setStyle("display", "none");
            '''
        } )
        """



        reports = []

        # read the config file
        from pyasm.widget import WidgetConfig
        tmp_path = __file__
        dir_name = os.path.dirname(tmp_path)
        file_path="%s/../config/reports-conf.xml" % (dir_name)
        config = WidgetConfig.get(file_path=file_path, view="definition")

        category = my.kwargs.get('category')

        # get all of the configs from the database
        if not category or category in ["custom_reports", "custom_charts"]:
            search = Search("config/widget_config")
            search.add_op("begin")
            if category == "custom_reports":
                search.add_filter("widget_type", "report")
            elif category == "custom_charts":
                search.add_filter("widget_type", "chart")
            elif not category:
                search.add_filters("widget_type", ["chart","report"])

            search.add_op("or")
            db_configs = search.get_sobjects()
        else:
            db_configs = []


        element_names = my.kwargs.get("element_names")
        if element_names is None:
            element_names = config.get_element_names()



        project = Project.get()

        for element_name in element_names:
            key = {'project': project.get_code(), 'element': element_name}
            key2 = {'project': project.get_code(), 'element': '*'}
            key3 = {'element': element_name}
            key4 = {'element': '*'}
            keys = [key, key2, key3, key4]
            if not top.check_access("link", keys, "view", default="deny"):
                continue

            attrs = config.get_element_attributes(element_name)
            report_data = {}
            kwargs = config.get_display_options(element_name)
            class_name = kwargs.get('class_name')

            # the straight xml definition contains the sidebar class_name
            # with LinkWdg ... we shouldn't use this, so build the
            # element from scratch
            #xml = config.get_element_xml(element_name)
            from pyasm.search import WidgetDbConfig
            xml = WidgetDbConfig.build_xml_definition(class_name, kwargs)

            report_data['class_name'] = class_name
            report_data['kwargs'] = kwargs
            report_data['title'] = attrs.get("title")
            report_data['description'] = attrs.get("description")
            report_data['image'] = attrs.get("image")
            report_data['xml'] = xml

            reports.append(report_data)



        for db_config in db_configs:
            element_name = db_config.get_value("view")
            key = {'project': project.get_code(), 'element': element_name}
            key2 = {'project': project.get_code(), 'element': '*'}
            key3 = {'element': element_name}
            key4 = {'element': '*'}
            keys = [key, key2, key3, key4]
            if not top.check_access("link", keys, "view", default="deny"):
                continue

            report_data = {}
            view = db_config.get_value("view")
            kwargs = {
                'view': view
            }
            parts = view.split(".")
            title = Common.get_display_title(parts[-1])

            xml = db_config.get_value("config")

            report_data['class_name'] = "tactic.ui.panel.CustomLayoutWdg"
            report_data['kwargs'] = kwargs
            report_data['title'] = title
            report_data['description'] = title
            report_data['image'] = None
            report_data['xml'] = xml
            report_data['widget_type'] = db_config.get_value("widget_type")
            if report_data['widget_type'] == 'report':
                report_data['category'] = "custom_reports"
            elif report_data['widget_type'] == 'chart':
                report_data['category'] = "custom_charts"


            reports.append(report_data)





        """
        report_data = {
            'title': 'Tasks Completed This Week',
            'class_name': 'tactic.ui.panel.ViewPanelWdg',
            'kwargs': {
                    'search_type': 'sthpw/task',
                    'view': 'table'
                },
        }
        reports.append(report_data)
        """
        if category == 'list_item_reports' or not category:
            search_types = Project.get().get_search_types()
            for search_type in search_types:
                base_key = search_type.get_base_key()

                key = {'project': project.get_code(), 'code': base_key}
                key2 = {'project': project.get_code(), 'code': '*'}
                key3 = {'code': base_key}
                key4 = {'code': '*'}
                keys = [key, key2, key3, key4]
                if not top.check_access("search_type", keys, "view", default="deny"):
                    continue


                if not SearchType.column_exists(base_key, "pipeline_code"):
                    continue

                thumb_div = DivWdg()
                image = thumb_div
                thumb_div.add_border()
                thumb_div.set_box_shadow("1px 1px 1px 1px")
                thumb_div.add_style("width: 60px")

                thumb = ThumbWdg()
                thumb_div.add(thumb)
                thumb.set_sobject(search_type)
                thumb.set_icon_size(60)

                report_data = {
                    'title': '%s Workflow Status' % search_type.get_title(),
                    'description': 'Number of items in each process',
                    'class_name': 'tactic.ui.report.stype_report_wdg.STypeReportWdg',
                    'kwargs': {
                        'search_type': base_key
                    },
                    'image': thumb_div
                }
                reports.append(report_data)

 
                report_data = {
                    'title': '%s Labor Cost Report' % search_type.get_title(),
                    'description': 'Labor Cost Breakdown for each Item',
                    'class_name': 'tactic.ui.panel.ViewPanelWdg',
                    'kwargs': {
                        'search_type': search_type.get_code(),
                        'view': "table",
                        'show_header': False,
                        'mode': 'simple',
                        'element_names': "preview,code,title,cost_breakdown,bid_hours,bid_cost,actual_hours,actual_cost,overbudget,variance"
                    },
                    'image': IconWdg("", IconWdg.REPORT_03)
                }
                reports.append(report_data)



        table2 = Table()
        inner.add(table2)
        table2.add_style("width: 100%")


        categories_div = DivWdg()
        td = table2.add_cell(categories_div)
        td.add_style("vertical-align: top")
        td.add_style("width: 200px")
        td.add_color("background", "background3")
        td.add_border()

        #categories_div.add_style("margin: -1px 0px 0px -1px")
        categories_div.add_style("padding-top: 10px")
        #categories_div.add_style("float: left")
        categories_div.add_color("color", "color3")


        categories = config.get_all_views()
        categories.insert(-1, "list_item_reports")
        categories.insert(-1, "custom_charts")
        categories.insert(-1, "custom_reports")

        table_div = DivWdg()
        td = table2.add_cell(table_div)
        td.add_style("vertical-align: top")
        table_div.add_class("spt_reports_list")
        table_div.add_border()
        table_div.add_color("background", "background", -5)

        table_div.add_style("min-height: 500px")



        for i, category in enumerate(categories):

            if i == len(categories) - 1:
                categories_div.add("<hr/>")


            config.set_view(category)
            element_names = config.get_element_names()

            if category == "definition":
                title = "All Reports"
            else:
                title = Common.get_display_title(category)


            category_div = DivWdg()
            categories_div.add(category_div)
            category_div.add(title)
            category_div.add_style("padding: 5px")
            category_div.add_class("hand")

            category_div.add_behavior( {
            'type': 'click_up',
            'category': category,
            'element_names': element_names,
            'class_name': Common.get_full_class_name(my),
            'cbjs_action': '''
            var kwargs = {
                is_refresh: true,
                category: bvr.category,
                element_names: bvr.element_names
            }

            //spt.panel.refresh(top, kwargs);
            var top = bvr.src_el.getParent(".spt_reports_top");
            spt.panel.load(top, bvr.class_name, kwargs);
            '''
            } )

            bgcolor = category_div.get_color("background3", -10)
            category_div.add_behavior( {
            'type': 'mouseover',
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.bgcolor);
            '''
            } )
            category_div.add_behavior( {
            'type': 'mouseout',
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "");
            '''
            } )








        # create a bunch of panels
        table = Table()
        table_div.add(table)
        table.add_color("color", "color")
        table.add_style("margin-top: 20px")
        table.center()
        table_div.add_style("margin: -3px -3px -1px -2px")


        if not reports:
            tr = table.add_row()
            td = table.add_cell()
            td.add("There are no reports defined.")
            td.add_style("padding: 50px")

            if my.kwargs.get("is_refresh") in ['true', True]:
                return inner
            else:
                return top



        for i, report in enumerate(reports):

            #if i == 0 or i%4 == 0:
            if i%3 == 0:
                tr = table.add_row()

            td = table.add_cell()
            td.add_style("vertical-align: top")
            td.add_style("padding: 3px")
            title = report
            #description = '''The schema is used to layout the basic components of your project.  Each component represents a list of items that you use in your business everyday.'''

            description = report.get("title")

            # Each node will contain a list of "items" and will be stored as a table in the database.'''

            class_name = report.get("class_name")
            kwargs = report.get("kwargs")
            title = report.get("title")
            description = report.get("description")
            widget_type = report.get("widget_type")

            image = report.get("image")
            icon = report.get("icon")
            xml = report.get("xml")

            if image:
                div = DivWdg()
                if isinstance(image, basestring):
                    image = image.upper()
                    image = eval("IconWdg('', IconWdg.%s)" % image)
                    div.add_style("margin-left: 15px")
                    div.add_style("margin-top: 5px")
                else:
                    image = image
                div.add(image)
                image = div

            elif icon:
                icon = icon.upper()
                image = eval("IconWdg('', IconWdg.%s)" % icon)

            else:
                div = DivWdg()
                """
                import random
                num = random.randint(0,3)
                if num == 1:
                    image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_01)
                elif num == 2:
                    image = IconWdg("Bar Chart", IconWdg.GRAPH_LINE_01)
                else:
                    image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_02)
                """

                if widget_type == "chart":
                    image = IconWdg("Chart", IconWdg.GRAPH_BAR_02)
                else:
                    image = IconWdg("No Image", IconWdg.WARNING)
                div.add_style("margin-left: 15px")
                div.add_style("margin-top: 5px")
                div.add(image)
                image = div


            behavior = {
            'type': 'click_up',
            'title': title,
            'class_name': class_name,
            'kwargs': kwargs,
            'cbjs_action': '''

            spt.tab.set_main_body_tab();
            //var top = bvr.src_el.getParent(".spt_reports_top");
            //spt.tab.set_tab_top(top);
            spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs);
            '''
            }
            schema_wdg = my.get_section_wdg(title, description, image, behavior)

            schema_wdg.add_behavior( {
            'type': 'load',
            'title': title,
            'class_name': class_name,
            'xml': xml,
            'kwargs': kwargs,
            'cbjs_action': '''
                var report_top = bvr.src_el;
                report_top.kwargs = bvr.kwargs;
                report_top.class_name = bvr.class_name;
                report_top.element_name = bvr.title;
                report_top.xml = bvr.xml;
            '''
            } )

            td.add(schema_wdg)


        inner.add("<br/>")



        #from tactic.ui.container import TabWdg
        #tab = TabWdg(show_add=False)
        #inner.add(tab)

        if my.kwargs.get("is_refresh") in ['true', True]:
            return inner
        else:
            return top
コード例 #14
0
ファイル: custom_property_wdg.py プロジェクト: 0-T-0/TACTIC
    def execute(my):

        web = WebContainer.get_web()

        # get command line options
        search_type = my.kwargs.get("search_type")
        assert search_type

        view = my.kwargs.get("view")
        if not view:
            view = get_template_view()



        # check if this is advanced mode
        mode = web.get_form_value("custom_mode")
        if not mode:
            mode = 'simple'

        if mode == 'xml':
            config_string = web.get_form_value("config_xml")

            # handle the "default" view
            view = DEFAULT_VIEW
            config = WidgetDbConfig.get_by_search_type(search_type, view)
            if not config:
                config = WidgetDbConfig.create(search_type, view)

            xml = Xml()
            xml.read_string(config_string)
            element_name = xml.get_value("element/@name")
            element_name = element_name.strip()
            assert element_name

            type = xml.get_value("element/@type")
            if not type:
                class_name = xml.get_value("element/display/@class")

                if not class_name:
                    raise TacticException("Either a type or class name needs to be defined in config xml.")

            config.append_xml_element(element_name,config_string)
            config.commit_config()

            # create the required columns
            widget = config.get_display_widget(element_name)
            columns = widget.get_required_columns()

            if columns:
                print "WARNING: need to create columns: ", columns

            my.info['element_name'] = element_name

            return



        type = web.get_form_value("custom_type")
        description = web.get_form_value("custom_description")
        if not description:
            description = "No descripton"

        title = web.get_form_value("custom_title")



        name = web.get_form_value("custom_name")
        name = name.strip()
        if not name:
            raise TacticException("No name specified")


        add_to_current_view = web.get_form_value("add_to_current_view")
        add_to_edit_view = web.get_form_value("add_to_edit_view")
        is_searchable = web.get_form_value("is_searchable")

        # create the column
        if type not in ['button', 'empty']:
            cmd = ColumnAddCmd(search_type, name, type)
            cmd.execute()

        
        # create the type
        class_name = None
        options = {}
        # this is actually element attrs
        element_options = {}
        edit_class_name = None
        edit_options = {}
        edit_attrs = {}

        element_type = type

        # Date Range is not used any more in the UI"
        if type == "Date Range":
            class_name = "GanttWdg"
            options["start_date_column"] = "%s_start_date" % name
            options["end_deate_column"] = "%s_end_date" % name

        elif type == "date":
            class_name = "DateWdg"
            #edit_class_name = "CalendarWdg"

            element_type = 'timestamp'
            edit_attrs['type'] = 'timestamp'
            edit_class_name = ""
            add_to_edit_view = True

        elif type == "foreign_key":
            class_name = ""
            edit_class_name = "SelectWdg"
            foreign_search_type = web.get_form_value("foreign_key_search_select")
            edit_options["query"] = '%s|code|code' % foreign_search_type

            # turn on add to edit view
            add_to_edit_view = True

        elif type == "button":
            class_name = "tactic.ui.table.ButtonElementWdg"
            script = web.get_form_value("option_script_select")
            if script:
                options['script'] = script
            icon = web.get_form_value("option_icon_select")
            if icon:
                options['icon'] = icon


            edit_class_name = ""

            # This does not have a type
            element_type = None


        elif type == "empty":
            element_type = None
            pass


        elif type == "list":
            class_name = ""
            edit_class_name = "SelectWdg"
            list_values = web.get_form_value("list_values")
            edit_options['values'] = list_values

            add_to_edit_view = True

        element_options['type'] = element_type
        element_options['title'] = title
        

        # handle the "default" view
        view = DEFAULT_VIEW
        config = WidgetDbConfig.get_by_search_type(search_type, view)
        if not config:
            config = WidgetDbConfig.create(search_type, view)
        config.append_display_element(name, class_name, options=options, \
                element_attrs=element_options)
        config.commit_config()


        # get the config file
        if add_to_current_view:
            config = WidgetDbConfig.get_by_search_type(search_type, view)

            if not config:
                # if it doesn't exist, the check to see, if there is a hard
                # coded view out there
                predefined_config = WidgetConfigView.get_by_search_type(search_type, view)
                xml = predefined_config.get_xml()

                # create a new db one
                config = WidgetDbConfig.create(search_type, view)

                if xml:
                    config.set_value("config", xml.to_string())
                    config._init()

            config.append_display_element(name)
            config.commit_config()

        # TODO: Need to make this searchable using simple search ?????
        if is_searchable:
            element_options['searchable'] = 'true'

        # handle the "edit"
        if add_to_edit_view and view != "edit":
            config = WidgetDbConfig.get_by_search_type(search_type, "edit")
            if not config:
                config = WidgetDbConfig.create(search_type, "edit")
            config.append_display_element(name, edit_class_name, edit_options,element_attrs=edit_attrs)
            config.commit_config()


        """
        # this sType has been deprecated
        sobject = SearchType.create("prod/custom_property")
        sobject.set_value("search_type", search_type)
        sobject.set_value("name", name)
        sobject.set_value("description", description)
        sobject.commit()
        """

        # set some information
        my.description = "Added Property [%s] of type [%s] to [%s]" % \
            (name, type, search_type)

        my.info['element_name'] = name
コード例 #15
0
    def execute(my):
        web = WebContainer.get_web()
        alter_mode = my.kwargs.get("alter_mode")
        title = my.kwargs.get("title")
        config_mode = web.get_form_value("config_mode")
        view = web.get_form_value('view')
        constraint = web.get_form_value("config_constraint")
        data_type = ''

        if config_mode == "advanced":
            config_string = web.get_form_value("config_xml")
            if config_string:
                xml = Xml()
                xml.read_string(config_string)
                node = xml.get_root_node()
                data_type = xml.get_attribute(node, "data_type")
                nullable = xml.get_attribute(node,
                                             "nullable") in ['true', 'True']

        else:
            data_type = web.get_form_value("config_data_type")
            if data_type == 'Other...':
                data_type = web.get_form_value("config_data_type_custom")
            cb = CheckboxWdg("config_nullable")
            nullable = cb.is_checked()

        # if advanced is selected in the Widget Column view, data_type is ''
        # read from UI
        if not data_type and view == 'definition':
            data_type = web.get_form_value("config_data_type")
            if data_type == 'Other...':
                data_type = web.get_form_value("config_data_type_custom")
            cb = CheckboxWdg("config_nullable")
            nullable = cb.is_checked()

        column_name = web.get_form_value("column_name")
        search_type = web.get_form_value("target_search_type")
        if alter_mode == ManageSearchTypeDetailWdg.REMOVE_COLUMN:
            cmd = ColumnDropCmd(search_type, column_name)
            Command.execute_cmd(cmd)
            # delete widget config from definition view
            widget_config = WidgetDbConfig.get_by_search_type(
                search_type, 'definition')
            if widget_config:
                config = WidgetConfig.get(
                    'definition', xml=widget_config.get_xml_value('config'))
                config.remove_xml_element(column_name)
                new_xml = config.get_xml().to_string()
                widget_config.set_value("config", new_xml)
                widget_config.commit()
                # set cache to {}
                from pyasm.common import Container

                Container.put("WidgetConfigView:config_cache", {})
                #Container.put("WidgetConfig:config_cache", {})
        elif alter_mode == ManageSearchTypeDetailWdg.MODIFY_COLUMN:
            cmd = ColumnAlterCmd(search_type, column_name, data_type, nullable)
            Command.execute_cmd(cmd)
            element_options = {}
            element_options['type'] = data_type
            if title:
                element_options['title'] = title

            # handle the "default" view
            # update the widget config data type in the xml
            view = my.DEFAULT_VIEW
            config = WidgetDbConfig.get_by_search_type(search_type, view)
            if config:
                config.append_display_element(column_name, options={}, \
                    element_attrs=element_options)
                config.commit_config()

        elif alter_mode == ManageSearchTypeDetailWdg.ADD_COLUMN:
            cmd = ColumnAddCmd(search_type, column_name, data_type, nullable)
            Command.execute_cmd(cmd)

        if constraint:
            # add constraint
            from pyasm.command import ColumnAddIndexWdg
            cmd = ColumnAddIndexWdg()
            cmd.execute()
        else:
            # remove constraint
            pass
コード例 #16
0
    def execute(my):

        web = WebContainer.get_web()
        actions = web.get_form_values("table_action_hidden")
        if not actions:
            clear = web.get_form_value("Clear")
            if clear:
                actions = ["clear"]

        if not actions:
            return

        search_type = web.get_form_value("search_type")
        assert search_type

        view = web.get_form_value("view")
        if not view:
            view = web.get_form_value("filter|view")
        if not view:
            view = get_template_view()
       
        for action in actions:

            parts = action.split("|")
            action = parts[0]

            if action not in ['add', 'remove', 'clear', 'move_left', 'move_right']:
                print "WARNING: action [%s] not known" % action
                return

            # get the view config 
            search = Search("sthpw/widget_config")
            search.add_filter("search_type", search_type)
            search.add_filter("view", view)
            config = search.get_sobject()
            if not config:
                config = WidgetDbConfig.create(search_type, view)

            

            
            if action == "add":
                elem_name = parts[1]

                # FIXME: these should be coded as defaults somewhere
                options = {}
                cls_name = None
                if elem_name == "notes":
                    cls_name = "DiscussionWdg"
                    options['context'] = 'default'
                elif elem_name == "thumb_publish":
                    cls_name = "pyasm.prod.web.ThumbPublishWdg"


                config.append_display_element(elem_name, cls_name, options)
                config.commit_config()

                # handle some defaults
                if elem_name in PREDEFINED_ELEMENTS and \
                        elem_name not in PREDEFINED_EDIT_ELEMENTS:
                    continue

                #edit_config.append_display_element(elem_name)
                #edit_config.commit_config()

                my.description = "Added [%s] to [%s] view" % (elem_name, view)

            elif action == "remove":
                elem_name = parts[1]
                config.remove_display_element(elem_name)
                config.commit_config()

                #edit_config.remove_display_element(elem_name)
                #edit_config.commit_config()

                my.description = "Removed [%s] from [%s] view" % (elem_name, view)

            elif action == "clear":
                config.clear()
                config.commit_config()

                # TODO: not sure what to do about the edit config on clear??

                my.description = "Cleared view [%s]" % (view)


            elif action == "move_left":
                elem_name = parts[1]
                config.move_element_left(elem_name)
                config.commit_config()
                my.description = "Removed [%s] to the left" % elem_name

            elif action == "move_right":
                elem_name = parts[1]
                config.move_element_right(elem_name)
                config.commit_config()
                my.description = "Removed [%s] to the right" % elem_name


            elif action == "order_by":
                print "order by!!!"
コード例 #17
0
 def handle_config(self):
     '''for search type display config'''
     web = WebContainer.get_web()
     WidgetDbConfig.append(self.search_type, self.view, self.element_name, config_xml=self.config_xml)
コード例 #18
0
def query_search_types_extended(project_code, namespace):
    """
    This crazy stuff made to execute queries on server
    All needed info is getting almost half time faster
    :return:
    """
    # TODO remove query, and dig deeper to get more info about pipelines, processes, stypes
    # from pyasm.search import Search
    # from pyasm.biz import Pipeline
    #
    # search_type = 'cgshort/scenes'
    # search = Search("sthpw/pipeline")
    # search.add_filter("search_type", search_type)
    # pipelines = search.get_sobjects()
    #
    # return str(pipelines)
    import json
    from pyasm.biz import Project
    api = server.server
    get_sobject_dict = api.get_sobject_dict

    prj = Project.get_by_code(project_code)

    stypes = prj.get_search_types()

    from pyasm.widget import WidgetConfigView
    from pyasm.search import WidgetDbConfig
    from pyasm.biz import Project

    all_stypes = []
    for stype in stypes:
        stype_dict = get_sobject_dict(stype)
        stype_dict['column_info'] = stype.get_column_info(stype.get_code())
        all_stypes.append(stype_dict)

        # getting views for columns viewer
        views = ['table', 'definition', 'color', 'edit', 'edit_definition']
        definition = {}
        full_search_type = Project.get_full_search_type(stype)
        for view in views:

            db_config = WidgetDbConfig.get_by_search_type(
                full_search_type, view)
            if db_config:
                config = db_config.get_xml()
            else:
                config_view = WidgetConfigView.get_by_search_type(stype, view)
                config = config_view.get_config()

            definition[view] = config.to_string()

        stype_dict['definition'] = definition

    # getting pipeline process
    # stypes_codes = []
    # for stype in all_stypes:
    #     stypes_codes.append(stype['code'])
    # stypes_codes.append('sthpw/task')
    search_type = 'sthpw/pipeline'
    # filters = [('search_type', stypes_codes)] - THIS IS VALID CODE
    # filters = [('project_code', 'is', 'NULL'), ('project_code', 'like', project_code)]
    filters = []  # temporary
    stypes_pipelines = server.query(search_type, filters, return_sobjects=True)

    # getting processes info
    pipelines = []
    for stype in stypes_pipelines:
        stypes_dict = stype.get_sobject_dict()

        processes = []
        for process in stype.get_process_names():
            process_sobject = stype.get_process_sobject(process)
            if process_sobject:
                processes.append(api.get_sobject_dict(process_sobject))

        task_processes = []
        for process in stype.get_processes():
            process_obj = process.get_task_pipeline()
            if process_obj != 'task':
                task_processes.append(process_obj)

        stypes_dict['tasks_processes'] = task_processes
        stypes_dict['stypes_processes'] = processes
        pipelines.append(stypes_dict)

    # getting project schema
    schema = server.query('sthpw/schema', [('code', project_code)])

    result = {'schema': schema, 'pipelines': pipelines, 'stypes': all_stypes}

    return json.dumps(result, separators=(',', ':'))
コード例 #19
0
    def execute(my):
        web = WebContainer.get_web()
        if not web.get_form_value("Insert/Next") and not web.get_form_value("Insert/Exit"):
            return


        search_type = web.get_form_value("search_type")
        view = web.get_form_value("view")
        project = web.get_form_value("project")
        name = web.get_form_value("new_custom_name")
        if not name:
            raise TacticException("No name specified")
        type = web.get_form_value("new_custom_type")
        description = web.get_form_value("new_description")
        add_to_current_view = web.get_form_value("add_to_current_view")
        add_to_edit_view = web.get_form_value("add_to_edit_view")

        assert search_type

        if not view:
            view = get_template_view()

        # create the column
        cmd = ColumnAddCmd(search_type, name, type)
        cmd.execute()

        # create the type
        class_name = None
        options = {}
        edit_class_name = None
        edit_options = {}

        if type == "Date Range":
            class_name = "GanttWdg"
            options["start_date_column"] = "%s_start_date" % name
            options["end_date_column"] = "%s_end_date" % name
        elif type == "Date":
            class_name = "DateWdg"
            edit_class_name = "CalendarWdg"
        elif type == "Checkbox":
            class_name = "CheckTableElementWdg"
            edit_class_name = "CheckboxWdg"
        elif type == "Foreign Key":
            class_name = ""
            edit_class_name = "SelectWdg"
            foreign_search_type = web.get_form_value("foreign_key_search_select")
            edit_options["query"] = '%s|code|code' % foreign_search_type
        elif type == "List":
            class_name = ""
            edit_class_name = "SelectWdg"
            list_values = web.get_form_value("list_values")
            edit_options['values'] = list_values




        # get the config file
        if add_to_current_view:
            config = WidgetDbConfig.get_by_search_type(search_type, view)
            if not config:
                config = WidgetDbConfig.create(search_type, view)
            config.append_display_element(name)
            config.commit_config()

        # handle the "default" view
        view = DEFAULT_VIEW
        config = WidgetDbConfig.get_by_search_type(search_type, view)
        if not config:
            config = WidgetDbConfig.create(search_type, view)
        config.append_display_element(name, class_name, options)
        config.commit_config()


        # handle the "edit"
        if add_to_edit_view and view != "edit":
            config = WidgetDbConfig.get_by_search_type(search_type, "edit")
            if not config:
                config = WidgetDbConfig.create(search_type, "edit")
            config.append_display_element(name, edit_class_name, edit_options)
            config.commit_config()


        # create the sobject for now
        sobject = SObjectFactory.create("prod/custom_property")
        sobject.set_value("search_type", search_type)
        sobject.set_value("name", name)
        sobject.set_value("description", description)
        sobject.commit()


        my.description = "Added Property [%s] of type [%s] to [%s]" % \
            (name, type, search_type)
コード例 #20
0
    def execute(self):
        web = WebContainer.get_web()
        alter_mode = self.kwargs.get("alter_mode")
        title = self.kwargs.get("title")
        config_mode = web.get_form_value("config_mode")
        view = web.get_form_value('view')
        constraint = web.get_form_value("config_constraint")
        data_type = ''

        if config_mode == "advanced" :
            config_string = web.get_form_value("config_xml")
            if config_string:
                xml = Xml()
                xml.read_string(config_string)
                node = xml.get_root_node()
                data_type = xml.get_attribute(node, "data_type")
                nullable = xml.get_attribute(node, "nullable") in ['true','True']
            
        else:
            data_type = web.get_form_value("config_data_type")
            if data_type == 'Other...':
                data_type = web.get_form_value("config_data_type_custom")
            cb = CheckboxWdg("config_nullable")
            nullable = cb.is_checked()

        # if advanced is selected in the Widget Column view, data_type is ''
        # read from UI
        if not data_type and view == 'definition':
            data_type = web.get_form_value("config_data_type")
            if data_type == 'Other...':
                data_type = web.get_form_value("config_data_type_custom")
            cb = CheckboxWdg("config_nullable")
            nullable = cb.is_checked()


        column_name = web.get_form_value("column_name")
        search_type = web.get_form_value("target_search_type")
        if alter_mode == ManageSearchTypeDetailWdg.REMOVE_COLUMN:
            cmd = ColumnDropCmd(search_type, column_name)
            Command.execute_cmd(cmd)
            # delete widget config from definition view
            widget_config = WidgetDbConfig.get_by_search_type(search_type, 'definition')
            if widget_config:
                config = WidgetConfig.get('definition', xml=widget_config.get_xml_value('config'))
                config.remove_xml_element(column_name)
                new_xml = config.get_xml().to_string()
                widget_config.set_value("config", new_xml)
                widget_config.commit()
                # set cache to {}
                from pyasm.common import Container
                 
                Container.put("WidgetConfigView:config_cache", {})
                #Container.put("WidgetConfig:config_cache", {})
        elif alter_mode == ManageSearchTypeDetailWdg.MODIFY_COLUMN:
            cmd = ColumnAlterCmd(search_type, column_name, data_type, nullable)
            Command.execute_cmd(cmd)
            element_options = {}
            element_options['type'] = data_type
            if title:
            	element_options['title'] = title
        

            # handle the "default" view
            # update the widget config data type in the xml
            view = self.DEFAULT_VIEW
            config = WidgetDbConfig.get_by_search_type(search_type, view)
            if config:
                config.append_display_element(column_name, options={}, \
                    element_attrs=element_options)
                config.commit_config()

        elif alter_mode == ManageSearchTypeDetailWdg.ADD_COLUMN:
            cmd = ColumnAddCmd(search_type, column_name, data_type, nullable)
            Command.execute_cmd(cmd)


        if constraint:
            # add constraint
            from pyasm.command import ColumnAddIndexWdg
            cmd = ColumnAddIndexWdg()
            cmd.execute()
        else:
            # remove constraint
            pass
コード例 #21
0
ファイル: custom_view_wdg.py プロジェクト: 0-T-0/TACTIC
    def execute(my):
        web = WebContainer.get_web()
        if not web.get_form_value("Insert/Next") and not web.get_form_value("Insert/Exit"):
            return


        search_type = web.get_form_value("search_type")
        view = web.get_form_value("view")
        project = web.get_form_value("project")
        name = web.get_form_value("new_custom_name")
        if not name:
            raise TacticException("No name specified")
        type = web.get_form_value("new_custom_type")
        description = web.get_form_value("new_description")
        add_to_current_view = web.get_form_value("add_to_current_view")
        add_to_edit_view = web.get_form_value("add_to_edit_view")

        assert search_type

        if not view:
            view = get_template_view()

        # create the column
        cmd = ColumnAddCmd(search_type, name, type)
        cmd.execute()

        # create the type
        class_name = None
        options = {}
        edit_class_name = None
        edit_options = {}

        if type == "Date Range":
            class_name = "GanttWdg"
            options["start_date_column"] = "%s_start_date" % name
            options["end_date_column"] = "%s_end_date" % name
        elif type == "Date":
            class_name = "DateWdg"
            edit_class_name = "CalendarWdg"
        elif type == "Checkbox":
            class_name = "CheckTableElementWdg"
            edit_class_name = "CheckboxWdg"
        elif type == "Foreign Key":
            class_name = ""
            edit_class_name = "SelectWdg"
            foreign_search_type = web.get_form_value("foreign_key_search_select")
            edit_options["query"] = '%s|code|code' % foreign_search_type
        elif type == "List":
            class_name = ""
            edit_class_name = "SelectWdg"
            list_values = web.get_form_value("list_values")
            edit_options['values'] = list_values




        # get the config file
        if add_to_current_view:
            config = WidgetDbConfig.get_by_search_type(search_type, view)
            if not config:
                config = WidgetDbConfig.create(search_type, view)
            config.append_display_element(name)
            config.commit_config()

        # handle the "default" view
        view = DEFAULT_VIEW
        config = WidgetDbConfig.get_by_search_type(search_type, view)
        if not config:
            config = WidgetDbConfig.create(search_type, view)
        config.append_display_element(name, class_name, options)
        config.commit_config()


        # handle the "edit"
        if add_to_edit_view and view != "edit":
            config = WidgetDbConfig.get_by_search_type(search_type, "edit")
            if not config:
                config = WidgetDbConfig.create(search_type, "edit")
            config.append_display_element(name, edit_class_name, edit_options)
            config.commit_config()


        # create the sobject for now
        sobject = SObjectFactory.create("prod/custom_property")
        sobject.set_value("search_type", search_type)
        sobject.set_value("name", name)
        sobject.set_value("description", description)
        sobject.commit()


        my.description = "Added Property [%s] of type [%s] to [%s]" % \
            (name, type, search_type)
コード例 #22
0
ファイル: custom_view_wdg.py プロジェクト: 0-T-0/TACTIC
    def execute(my):

        web = WebContainer.get_web()
        actions = web.get_form_values("table_action_hidden")
        if not actions:
            clear = web.get_form_value("Clear")
            if clear:
                actions = ["clear"]

        if not actions:
            return

        search_type = web.get_form_value("search_type")
        assert search_type

        view = web.get_form_value("view")
        if not view:
            view = web.get_form_value("filter|view")
        if not view:
            view = get_template_view()
       
        for action in actions:

            parts = action.split("|")
            action = parts[0]

            if action not in ['add', 'remove', 'clear', 'move_left', 'move_right']:
                print "WARNING: action [%s] not known" % action
                return

            # get the view config 
            search = Search("sthpw/widget_config")
            search.add_filter("search_type", search_type)
            search.add_filter("view", view)
            config = search.get_sobject()
            if not config:
                config = WidgetDbConfig.create(search_type, view)

            

            
            if action == "add":
                elem_name = parts[1]

                # FIXME: these should be coded as defaults somewhere
                options = {}
                cls_name = None
                if elem_name == "notes":
                    cls_name = "DiscussionWdg"
                    options['context'] = 'default'
                elif elem_name == "thumb_publish":
                    cls_name = "pyasm.prod.web.ThumbPublishWdg"


                config.append_display_element(elem_name, cls_name, options)
                config.commit_config()

                # handle some defaults
                if elem_name in PREDEFINED_ELEMENTS and \
                        elem_name not in PREDEFINED_EDIT_ELEMENTS:
                    continue

                #edit_config.append_display_element(elem_name)
                #edit_config.commit_config()

                my.description = "Added [%s] to [%s] view" % (elem_name, view)

            elif action == "remove":
                elem_name = parts[1]
                config.remove_display_element(elem_name)
                config.commit_config()

                #edit_config.remove_display_element(elem_name)
                #edit_config.commit_config()

                my.description = "Removed [%s] from [%s] view" % (elem_name, view)

            elif action == "clear":
                config.clear()
                config.commit_config()

                # TODO: not sure what to do about the edit config on clear??

                my.description = "Cleared view [%s]" % (view)


            elif action == "move_left":
                elem_name = parts[1]
                config.move_element_left(elem_name)
                config.commit_config()
                my.description = "Removed [%s] to the left" % elem_name

            elif action == "move_right":
                elem_name = parts[1]
                config.move_element_right(elem_name)
                config.commit_config()
                my.description = "Removed [%s] to the right" % elem_name


            elif action == "order_by":
                print "order by!!!"
コード例 #23
0
ファイル: search_wdg.py プロジェクト: zieglerm/TACTIC
    def init(self):

        self.user_override = self.kwargs.get('user_override') in ['true', True]

        custom_search_view = self.kwargs.get('custom_search_view')
        if not custom_search_view or not custom_search_view.strip():
            custom_search_view = 'search'

        # create a search for this search widget
        self.search_type = self.kwargs.get('search_type')

        self.search = self.kwargs.get("search")
        if not self.search:
            self.search = Search(self.search_type)
        self.config = None

        # determine whether or not to use the last search.  If any kind of
        # state has been set, then ignore the last_search
        self.use_last_search = True
        parent_key = self.kwargs.get('parent_key')
        state = self.kwargs.get('state')
        if parent_key or state or self.kwargs.get('use_last_search') in [False, 'false']:
            self.use_last_search = False
       
        self.prefix_namespace = self.kwargs.get('prefix_namespace')


        # NOTE: this is still hard coded
        self.prefix = 'main_body'
        # if we are asking for a specific saved search
        save = self.kwargs.get('save')


        self.view = self.kwargs.get('view')

        # get the config from a specific location

        # if the view is specified, use this view with the values
        # specified explicitly in this view
        self.config = None

        # see if a filter is explicitly passed in
        filter = self.kwargs.get('filter')
        self.limit = self.kwargs.get('limit')
        self.run_search_bvr = self.kwargs.get('run_search_bvr')

        # get from search view
     
        # filter can be either dict(data) or a list or
        # xml(filter wdg definition)
        if filter:
            if type(filter) == types.DictType:
                self.config = self.get_default_filter_config()
                filter_data = FilterData([filter])
                filter_data.set_to_cgi()
            elif type(filter) == types.ListType:
                self.config = self.get_default_filter_config()
                filter_data = FilterData(filter)
                filter_data.set_to_cgi()
        
            else:
                
                try:
                    filter_data = None

                    # TODO: remove this. This is for backward compatibilty
                    self.config = WidgetConfig.get(xml=filter, view='filter')
                    filter_data = FilterData.get()
                    if not filter_data.get_data():
                        # use widget settings
                        key = SearchWdg._get_key(self.search_type, self.view)

                        data = WidgetSettings.get_value_by_key(key)
                        if data:
                            filter_data = FilterData(data)
                        filter_data.set_to_cgi()

                except XmlException as e:
                    print("WARNING: non-xml filter detected!!")

        
        # NOTE: this is only used to maintain backwards compatibility
        # plus it is needed for link_search: which contains the filter_config (old way of doing it)
        if not self.config:# and self.view:
            """
            if ':' in self.view: # avoid view of a SearchWdg like link_search:<search_type>:<view>
                search_view = custom_search_view
            else:
                search_view = self.view
            """
            search_view = custom_search_view
            config_view = WidgetConfigView.get_by_search_type(self.search_type, view=search_view)
            # get the self.config first for the display of SearchWdg
            # then get the filter data below if there is any
            if config_view.get_config().has_view(search_view):
                self.config = config_view.get_config()   

            try:
                search = Search('config/widget_config')
                search.add_filter("view", self.view)
                search.add_filter("search_type", self.search_type)
                config_sobjs = search.get_sobjects()
                from pyasm.search import WidgetDbConfig
                config_sobj = WidgetDbConfig.merge_configs(config_sobjs)
                #config_sobj = config_sobjs[0]
            except SearchException as e:
                print("WARNING: ", e)
                config_sobj = None


            if config_sobj:
                config_xml = config_sobj.get_xml_value("config")

                if not config_view.get_config().has_view(self.view):
                    # make sure it does have the old way of storing filter
                    # elements instead of just filter data
                    if config_xml.get_nodes("config/filter/element"):
                        self.config = WidgetConfig.get(xml=config_xml, view='filter')
                    
                #self.config = self.get_default_filter_config()

                # set the form variables for the filters
                data = config_xml.get_value("config/filter/values")
                # link_search with specific search params takes precesdence
                # TODO: make a distinction between search definition and alter
                # search data provided by user
                if data and not self.user_override:
                    filter_data = FilterData(data)
                    filter_data.set_to_cgi()
                else:    
                    self.set_filter_data(self.search_type, self.view)

            else:
                if self.use_last_search: 
                    self.set_filter_data(self.search_type, self.view)
        if not self.config:
            # get the approprate filter definition
            self.config = self.get_default_filter_config()
            if self.use_last_search: 
                self.set_filter_data(self.search_type, self.view)


        if not self.config:
            return


        self.num_filters_enabled = 0

        # create the filters
        self.filters = []
        security = Environment.get_security()
        element_names = self.config.get_element_names()
        #element_names = ["Keywords", "Related"]

        for element_name in element_names:
            filter = self.config.get_display_widget(element_name)

            if filter and filter.is_visible():
                self.filters.append(filter)

        # make sure there is at least one filter defined
        #assert self.filters

        # just for drawing purpose
        if self.kwargs.get('skip_search') == True:
            return

        try:
            self.alter_search()
            self.set_persistent_value()

        except SearchInputException as e:
            self.clear_search_data(self.search_type)
            raise SearchInputException("%s If this problem persists, this view may contain invalid data in &lt; values &gt;. Clean up the data in Widget Config for the view [%s]."%( e.__str__(), self.view)) 
        except:
            self.clear_search_data(self.search_type)
            raise
コード例 #24
0
    def execute(self):

        web = WebContainer.get_web()

        # get command line options
        search_type = self.kwargs.get("search_type")
        assert search_type

        view = self.kwargs.get("view")
        if not view:
            view = get_template_view()

        # check if this is advanced mode
        mode = web.get_form_value("custom_mode")
        if not mode:
            mode = 'simple'

        if mode == 'xml':
            config_string = web.get_form_value("config_xml")

            # handle the "default" view
            view = DEFAULT_VIEW
            config = WidgetDbConfig.get_by_search_type(search_type, view)
            if not config:
                config = WidgetDbConfig.create(search_type, view)

            xml = Xml()
            xml.read_string(config_string)
            element_name = xml.get_value("element/@name")
            element_name = element_name.strip()
            assert element_name

            type = xml.get_value("element/@type")
            if not type:
                class_name = xml.get_value("element/display/@class")

                if not class_name:
                    raise TacticException(
                        "Either a type or class name needs to be defined in config xml."
                    )

            config.append_xml_element(element_name, config_string)
            config.commit_config()

            # create the required columns
            widget = config.get_display_widget(element_name)
            columns = widget.get_required_columns()

            if columns:
                print("WARNING: need to create columns: ", columns)

            self.info['element_name'] = element_name

            return

        type = web.get_form_value("custom_type")
        description = web.get_form_value("custom_description")
        if not description:
            description = "No descripton"

        title = web.get_form_value("custom_title")

        name = web.get_form_value("custom_name")
        name = name.strip()
        if not name:
            raise TacticException("No name specified")

        add_to_current_view = web.get_form_value("add_to_current_view")
        add_to_edit_view = web.get_form_value("add_to_edit_view")
        is_searchable = web.get_form_value("is_searchable")

        # create the column
        if type not in ['button', 'empty']:
            cmd = ColumnAddCmd(search_type, name, type)
            cmd.execute()

        # create the type
        class_name = None
        options = {}
        # this is actually element attrs
        element_options = {}
        edit_class_name = None
        edit_options = {}
        edit_attrs = {}

        element_type = type

        # Date Range is not used any more in the UI"
        if type == "Date Range":
            class_name = "GanttWdg"
            options["start_date_column"] = "%s_start_date" % name
            options["end_deate_column"] = "%s_end_date" % name

        elif type == "date":
            class_name = "DateWdg"
            #edit_class_name = "CalendarWdg"

            element_type = 'timestamp'
            edit_attrs['type'] = 'timestamp'
            edit_class_name = ""
            add_to_edit_view = True

        elif type == "foreign_key":
            class_name = ""
            edit_class_name = "SelectWdg"
            foreign_search_type = web.get_form_value(
                "foreign_key_search_select")
            edit_options["query"] = '%s|code|code' % foreign_search_type

            # turn on add to edit view
            add_to_edit_view = True

        elif type == "button":
            class_name = "tactic.ui.table.ButtonElementWdg"
            script = web.get_form_value("option_script_select")
            if script:
                options['script'] = script
            icon = web.get_form_value("option_icon_select")
            if icon:
                options['icon'] = icon

            edit_class_name = ""

            # This does not have a type
            element_type = None

        elif type == "empty":
            element_type = None
            pass

        elif type == "list":
            class_name = ""
            edit_class_name = "SelectWdg"
            list_values = web.get_form_value("list_values")
            edit_options['values'] = list_values

            add_to_edit_view = True

        element_options['type'] = element_type
        element_options['title'] = title

        # handle the "default" view
        view = DEFAULT_VIEW
        config = WidgetDbConfig.get_by_search_type(search_type, view)
        if not config:
            config = WidgetDbConfig.create(search_type, view)
        config.append_display_element(name, class_name, options=options, \
                element_attrs=element_options)
        config.commit_config()

        # get the config file
        if add_to_current_view:
            config = WidgetDbConfig.get_by_search_type(search_type, view)

            if not config:
                # if it doesn't exist, the check to see, if there is a hard
                # coded view out there
                predefined_config = WidgetConfigView.get_by_search_type(
                    search_type, view)
                xml = predefined_config.get_xml()

                # create a new db one
                config = WidgetDbConfig.create(search_type, view)

                if xml:
                    config.set_value("config", xml.to_string())
                    config._init()

            config.append_display_element(name)
            config.commit_config()

        # TODO: Need to make this searchable using simple search ?????
        if is_searchable:
            element_options['searchable'] = 'true'

        # handle the "edit"
        if add_to_edit_view and view != "edit":
            config = WidgetDbConfig.get_by_search_type(search_type, "edit")
            if not config:
                config = WidgetDbConfig.create(search_type, "edit")
            config.append_display_element(name,
                                          edit_class_name,
                                          edit_options,
                                          element_attrs=edit_attrs)
            config.commit_config()
        """
        # this sType has been deprecated
        sobject = SearchType.create("prod/custom_property")
        sobject.set_value("search_type", search_type)
        sobject.set_value("name", name)
        sobject.set_value("description", description)
        sobject.commit()
        """

        # set some information
        self.description = "Added Property [%s] of type [%s] to [%s]" % \
            (name, type, search_type)

        self.info['element_name'] = name
コード例 #25
0
 def handle_config(my):
     """for search type display config"""
     web = WebContainer.get_web()
     WidgetDbConfig.append(my.search_type, my.view, my.element_name, config_xml=my.config_xml)