def get_config(cls, search_type, view, default=None, personal=False):
        # personal doesn't mean much here since this is only for Project view definition
        """
        if view == "__column__":
            xml == '''
            <config>
                <element name="tttt" type="__database__"/>
                <element name="uuuu" type="__database__"/>
                <element name="vvvv" type="__database__"/>
            </config>
            '''
        """
        widget_config = None
        config_view = None
        widget_config_list = []

        # get all the configs relevant to this search_type
        configs = []

        from pyasm.widget import WidgetConfigView
        if view == "definition":
            if default:
                try:
                    default_config_view = WidgetConfigView.get_by_search_type(
                        search_type, view, use_cache=False, local_search=True)

                    user_config_view = WidgetConfigView.get_by_search_type(
                        search_type, view)

                    #merge the user config view from db into the default config view in xml file
                    default_config = default_config_view.get_definition_config(
                    )
                    user_config = user_config_view.get_definition_config()
                    if user_config:
                        user_element_names = user_config.get_element_names()
                        # make sure it's unique, there is a new validate function for
                        # WidgetDbConfig to ensure that also
                        user_element_names = Common.get_unique_list(
                            user_element_names)
                        for elem in user_element_names:
                            user_node = user_config.get_element_node(elem)
                            default_config.append_xml_element(elem,
                                                              node=user_node)
                except SqlException, e:
                    print "Search ERROR: ", e.__str__()
                    default_config = None

                if default_config:
                    default_config.get_xml().clear_xpath_cache()
                    widget_config_list = [default_config]

            else:
                config_view = WidgetConfigView.get_by_search_type(
                    search_type, view, use_cache=True)
    def get_config(cls, search_type, view, default=None, personal=False):
        # personal doesn't mean much here since this is only for Project view definition
        """
        if view == "__column__":
            xml == '''
            <config>
                <element name="tttt" type="__database__"/>
                <element name="uuuu" type="__database__"/>
                <element name="vvvv" type="__database__"/>
            </config>
            '''
        """
        widget_config = None
        config_view = None
        widget_config_list = []

        # get all the configs relevant to this search_type
        configs = []

        from pyasm.widget import WidgetConfigView

        if view == "definition":
            if default:
                try:
                    default_config_view = WidgetConfigView.get_by_search_type(
                        search_type, view, use_cache=False, local_search=True
                    )

                    user_config_view = WidgetConfigView.get_by_search_type(search_type, view)

                    # merge the user config view from db into the default config view in xml file
                    default_config = default_config_view.get_definition_config()
                    user_config = user_config_view.get_definition_config()
                    if user_config:
                        user_element_names = user_config.get_element_names()
                        # make sure it's unique, there is a new validate function for
                        # WidgetDbConfig to ensure that also
                        user_element_names = Common.get_unique_list(user_element_names)
                        for elem in user_element_names:
                            user_node = user_config.get_element_node(elem)
                            default_config.append_xml_element(elem, node=user_node)
                except SqlException, e:
                    print "Search ERROR: ", e.__str__()
                    default_config = None

                if default_config:
                    default_config.get_xml().clear_xpath_cache()
                    widget_config_list = [default_config]

            else:
                config_view = WidgetConfigView.get_by_search_type(search_type, view, use_cache=True)
Esempio n. 3
0
    def execute(self):

        search_keys = self.kwargs.get("search_keys")
        if not search_keys:
            return

        element_name = self.kwargs.get("element_name")

        # get all of the sobjects
        sobjects = Search.get_by_search_keys(search_keys)
        if not sobjects:
            return

        from pyasm.widget import WidgetConfigView
        search_type = sobjects[0].get_base_search_type()
        view = "definition"

        config = WidgetConfigView.get_by_search_type(search_type, view)

        # TEST
        widget = config.get_display_widget(element_name)
        for sobject in sobjects:
            widget.set_sobject(sobject)
            value = widget.get_text_value()
            sobject.set_value(element_name, value)
            sobject.commit()
Esempio n. 4
0
    def _get_main_config(my, 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 my.element_class:
                Xml.set_attribute(display, 'class', my.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', my.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
Esempio n. 5
0
    def execute(my):

        search_keys = my.kwargs.get("search_keys")
        if not search_keys:
            return

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

        # get all of the sobjects
        sobjects = Search.get_by_search_keys(search_keys)
        if not sobjects:
            return

        from pyasm.widget import WidgetConfigView

        search_type = sobjects[0].get_base_search_type()
        view = "definition"

        config = WidgetConfigView.get_by_search_type(search_type, view)

        # TEST
        widget = config.get_display_widget(element_name)
        for sobject in sobjects:
            widget.set_sobject(sobject)
            value = widget.get_text_value()
            sobject.set_value(element_name, value)
            sobject.commit()
Esempio n. 6
0
    def execute(self):

        self.search_type = self.kwargs.get('search_type')
        self.element_name = self.kwargs.get('element_name')
        #print "Calculating aggregate: ", self.search_type, self.element_name

        self.view = self.kwargs.get('view')
        if not self.view:
            self.view = 'definition'

        config = WidgetConfigView.get_by_search_type(
            search_type=self.search_type, view=self.view)
        widget = config.get_display_widget(self.element_name)

        # calculate all of the values
        search = Search(self.search_type)
        sobjects = search.get_sobjects()
        widget.set_sobjects(sobjects)
        widget.kwargs['use_cache'] = "false"

        for i, sobject in enumerate(sobjects):
            widget.set_current_index(i)
            value = widget.get_text_value()

            print sobject.get_code(), "value [%s]: " % value

            # all cache columns need are named with a c_ preceeding it
            # s_status
            # c_element_name
            #
            # this_month -> c_this_month
            #column = "c_%s" % self.element_name
            #sobject.set_value(column, value)
            sobject.set_value(self.element_name, value)
            sobject.commit()
Esempio n. 7
0
    def execute(my):

        my.search_type = my.kwargs.get('search_type')
        my.element_name = my.kwargs.get('element_name')
        #print "Calculating aggregate: ", my.search_type, my.element_name

        my.view = my.kwargs.get('view')
        if not my.view:
            my.view = 'definition'

        config = WidgetConfigView.get_by_search_type(search_type=my.search_type, view=my.view)
        widget = config.get_display_widget(my.element_name)

        # calculate all of the values
        search = Search(my.search_type)
        sobjects = search.get_sobjects()
        widget.set_sobjects(sobjects)
        widget.kwargs['use_cache'] = "false"

        for i, sobject in enumerate(sobjects):
            widget.set_current_index(i)
            value = widget.get_text_value()

            print sobject.get_code(), "value [%s]: " %value

            # all cache columns need are named with a c_ preceeding it
            # s_status
            # c_element_name
            #
            # this_month -> c_this_month
            #column = "c_%s" % my.element_name
            #sobject.set_value(column, value)
            sobject.set_value(my.element_name, value)
            sobject.commit()
Esempio n. 8
0
    def execute(self):
        sobject = self.sobject

        search_type = sobject.get_search_type_obj()
        config = WidgetConfigView.get_by_search_type(search_type, "custom")
        if not config:
            return

        self.element_names = config.get_element_names()

        # create all of the handlers
        action_handlers = []

        for element_name in (self.element_names):
            action_handler_class = \
                config.get_action_handler(element_name)

            if action_handler_class == "":
                action_handler_class = "DatabaseAction"

            action_handler = WidgetConfig.create_widget(action_handler_class)
            action_handler.set_name(element_name)
            action_handler.set_input_prefix("edit")

            action_options = config.get_action_options(element_name)
            for key, value in action_options.items():
                action_handler.set_option(key, value)
            action_handlers.append(action_handler)

        # set the sobject for each action handler
        for action_handler in action_handlers:
            action_handler.set_sobject(sobject)
            if action_handler.check():
                action_handler.execute()
Esempio n. 9
0
    def get_config(cls,
                   config_search_type,
                   view,
                   default=False,
                   personal=False):
        config = WidgetConfigView.get_by_search_type(config_search_type, view)

        return config
Esempio n. 10
0
    def append(cls, search_type, view, name, class_name=None, display_options={}, element_attrs={}, config_xml=None, login=None):
        '''append an element with display class and options to the specified widget config'''
        assert view
        config_search_type = "config/widget_config"

        search = Search(config_search_type)
        search.add_filter("search_type", search_type)
        search.add_filter("view", view)
        search.add_filter("login", login)
        db_config = search.get_sobject()
        config_exists = True
        view_node = None
        if not db_config:
            db_config = SearchType.create(config_search_type)
            db_config.set_value("search_type", search_type )
            db_config.set_value("view", view )
            if login:
                db_config.set_value("login", login)

            config_exists = False

        # maintain the config variable here to mean WidgetConfig
        from pyasm.widget import WidgetConfigView
        if not config_exists and search_type not in ["SideBarWdg"]:
            config_view = WidgetConfigView.get_by_search_type(search_type, view)            
            #xml = config.get_xml()
            configs = config_view.get_configs()
            if configs:
                config = configs[0]
                view_node = config.get_view_node()
                config_exists = True
        
        if not config_exists:
            xml = db_config.get_xml_value("config", "config")
            db_config._init()
            root = xml.get_root_node()
            # build a new config
            view_node = xml.create_element(view)
            #root.appendChild(view_node)
            xml.append_child(root, view_node)
        else:   
            xml = db_config.get_xml_value("config", "config")
            root = xml.get_root_node()
            # it could be passed in thru a widget_config already
            if view_node is None:
                view_node = db_config.get_view_node()
            #root.appendChild(view_node)
            xml.append_child(root, view_node)

            db_config._init()

        if config_xml:
            db_config.append_xml_element( name, config_xml)
        else:
            db_config.append_display_element(name, class_name, options=display_options, element_attrs=element_attrs)
        db_config.commit_config()

        return db_config
Esempio n. 11
0
    def get_config(my):
        # TEST
        config_xml = '''
        <config>
        <custom_filter>
          <element name='asset_library'>
            <display class='SelectWdg'>
                <query>prod/asset_library|code|code</query>
                <empty>true</empty>
            </display>
          </element>
          <element name='pipeline_code'>
            <display class='SelectWdg'>
                <query>sthpw/pipeline|code|code</query>
                <empty>true</empty>
            </display>
          </element>
        </custom_filter>
        </config>
        '''

        my.view = my.kwargs.get("search_view")
        if not my.view:
            my.view = 'custom_filter'
        #view = "custom_filter"
        project_code = Project.extract_project_code(my.search_type)
        search = Search("config/widget_config", project_code=project_code )
        search.add_filter("view", my.view)
        
       
        search.add_filter("search_type", my.base_search_type)
        config_sobj = search.get_sobject()
        if config_sobj:
            config_xml = config_sobj.get_value("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(my.base_search_type, my.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=my.view, xml=config_xml)

        return config
Esempio n. 12
0
    def append(cls, search_type, view, name, class_name=None, display_options={}, element_attrs={}, config_xml=None, login=None):
        '''append an element with display class and options to the specified widget config'''
        assert view
        config_search_type = "config/widget_config"

        search = Search(config_search_type)
        search.add_filter("search_type", search_type)
        search.add_filter("view", view)
        search.add_filter("login", login)
        db_config = search.get_sobject()
        config_exists = True
        view_node = None
        if not db_config:
            db_config = SearchType.create(config_search_type)
            db_config.set_value("search_type", search_type )
            db_config.set_value("view", view )
            if login:
                db_config.set_value("login", login)

            config_exists = False

        # maintain the config variable here to mean WidgetConfig
        from pyasm.widget import WidgetConfigView
        if not config_exists and search_type not in ["SideBarWdg"]:
            config_view = WidgetConfigView.get_by_search_type(search_type, view)            
            #xml = config.get_xml()
            configs = config_view.get_configs()
            if configs:
                config = configs[0]
                view_node = config.get_view_node()
                config_exists = True
        
        if not config_exists:
            xml = db_config.get_xml_value("config", "config")
            db_config._init()
            root = xml.get_root_node()
            # build a new config
            view_node = xml.create_element(view)
            #root.appendChild(view_node)
            xml.append_child(root, view_node)
        else:   
            xml = db_config.get_xml_value("config", "config")
            root = xml.get_root_node()
            # it could be passed in thru a widget_config already
            if view_node is None:
                view_node = db_config.get_view_node()
            #root.appendChild(view_node)
            xml.append_child(root, view_node)

            db_config._init()

        if config_xml:
            db_config.append_xml_element( name, config_xml)
        else:
            db_config.append_display_element(name, class_name, options=display_options, element_attrs=element_attrs)
        db_config.commit_config()

        return db_config
Esempio n. 13
0
    def get_config(my):
        # TEST
        config_xml = '''
        <config>
        <custom_filter>
          <element name='asset_library'>
            <display class='SelectWdg'>
                <query>prod/asset_library|code|code</query>
                <empty>true</empty>
            </display>
          </element>
          <element name='pipeline_code'>
            <display class='SelectWdg'>
                <query>sthpw/pipeline|code|code</query>
                <empty>true</empty>
            </display>
          </element>
        </custom_filter>
        </config>
        '''

        my.view = my.kwargs.get("search_view")
        if not my.view:
            my.view = 'custom_filter'
        #view = "custom_filter"
        project_code = Project.extract_project_code(my.search_type)
        search = Search("config/widget_config", project_code=project_code )
        search.add_filter("view", my.view)
        
       
        search.add_filter("search_type", my.base_search_type)
        config_sobj = search.get_sobject()
        if config_sobj:
            config_xml = config_sobj.get_value("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(my.base_search_type, my.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=my.view, xml=config_xml)

        return config
Esempio n. 14
0
    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
Esempio n. 15
0
    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
Esempio n. 16
0
    def get_info_wdg(my, sobject):

        div = DivWdg()
        div.add_style("margin: 10px 20px 20px 20px")
        div.add_style("padding: 20px")
        div.add_color("background", "background", -3)
        div.add_border()
        div.add_color("color", "color3")
        div.set_round_corners(5)

        div.add_style("height", "100%")
        div.add_style("position: relative")

        element_names = my.kwargs.get("element_names")
        if not element_names:
            element_names = [
                "code",
                "name",
                "description",
            ]
        else:
            element_names = element_names.split(",")

        view = "table"

        from pyasm.widget import WidgetConfigView
        search_type = sobject.get_search_type()
        config = WidgetConfigView.get_by_search_type(search_type, view)

        table = Table()
        table.add_style("height", "100%")
        div.add(table)
        for element_name in element_names:
            table.add_row()
            title = Common.get_display_title(element_name)
            td = table.add_cell("%s: " % title)
            td.add_style("width: 200px")
            td.add_style("padding: 5px")

            element = config.get_display_widget(element_name)
            element.set_sobject(sobject)
            element.preprocess()
            td = table.add_cell(element)
            td.add_style("padding: 5px")
            #value = sobject.get_value(element_name, no_exception=True) or "N/A"
            #table.add_cell(value)

        div.add("<br/>")
        from tactic.ui.widget import DiscussionWdg
        search_key = sobject.get_search_key()
        notes_wdg = DiscussionWdg(search_key=search_key)
        notes_wdg.set_sobject(sobject)
        div.add(notes_wdg)

        return div
Esempio n. 17
0
 def preprocess(self):
     sobject = self.get_current_sobject()
     if not sobject:
         self.columns = []
         return
     search_type = sobject.get_search_type_obj()
     config = WidgetConfigView.get_by_search_type(search_type, "custom")
     if not config:
         self.columns = []
     else:
         self.columns = config.get_element_names()
Esempio n. 18
0
    def get_info_wdg(my, sobject):

        div = DivWdg()
        div.add_style("margin: 10px 20px 20px 20px")
        div.add_style("padding: 20px")
        div.add_color("background", "background", -3)
        div.add_border()
        div.add_color("color", "color3")
        div.set_round_corners(5)

        div.add_style("height", "100%")
        div.add_style("position: relative")

        element_names = my.kwargs.get("element_names")
        if not element_names:
            element_names = ["code","name","description",]
        else:
            element_names = element_names.split(",")


        view = "table"

        from pyasm.widget import WidgetConfigView
        search_type = sobject.get_search_type()
        config = WidgetConfigView.get_by_search_type(search_type, view)


        table = Table()
        table.add_style("height", "100%")
        div.add(table)
        for element_name in element_names:
            table.add_row()
            title = Common.get_display_title(element_name)
            td = table.add_cell("%s: " % title)
            td.add_style("width: 200px")
            td.add_style("padding: 5px")


            element = config.get_display_widget(element_name)
            element.set_sobject(sobject)
            element.preprocess()
            td = table.add_cell(element)
            td.add_style("padding: 5px")
            #value = sobject.get_value(element_name, no_exception=True) or "N/A"
            #table.add_cell(value)

        div.add("<br/>")
        from tactic.ui.widget import DiscussionWdg
        search_key = sobject.get_search_key()
        notes_wdg = DiscussionWdg(search_key=search_key)
        notes_wdg.set_sobject(sobject)
        div.add(notes_wdg)

        return div
Esempio n. 19
0
 def preprocess(my):
     sobject = my.get_current_sobject() 
     if not sobject:
         my.columns = []
         return 
     search_type = sobject.get_search_type_obj()
     config = WidgetConfigView.get_by_search_type(search_type, "custom")
     if not config:
         my.columns = []
     else:
         my.columns = config.get_element_names()
Esempio n. 20
0
    def init_color_map(my):
        ''' initialize the color map for bg color and text color'''
        search_type = my.kwargs.get('search_type')
        
        if not search_type:
            search_type = 'sthpw/task'

        # get the color map
        from pyasm.widget import WidgetConfigView
        color_config = WidgetConfigView.get_by_search_type(search_type, "color")
        color_xml = color_config.configs[0].xml
        my.color_map = {}
        name = 'status'
        xpath = "config/color/element[@name='%s']/colors" % name
        text_xpath = "config/color/element[@name='%s']/text_colors" % name
        bg_color_node = color_xml.get_node(xpath)
        bg_color_map = color_xml.get_node_values_of_children(bg_color_node)

        text_color_node = color_xml.get_node(text_xpath)
        text_color_map = color_xml.get_node_values_of_children(text_color_node)
        
        # use old weird query language
        query = bg_color_map.get("query")
        query2 = bg_color_map.get("query2")
        if query:
            bg_color_map = {}

            search_type, match_col, color_col = query.split("|")
            search = Search(search_type)
            sobjects = search.get_sobjects()

            # match to a second table
            if query2:
                search_type2, match_col2, color_col2 = query2.split("|")
                search2 = Search(search_type2)
                sobjects2 = search2.get_sobjects()
            else:
                sobjects2 = []

            for sobject in sobjects:
                match = sobject.get_value(match_col)
                color_id = sobject.get_value(color_col)

                for sobject2 in sobjects2:
                    if sobject2.get_value(match_col2) == color_id:
                        color = sobject2.get_value(color_col2)
                        break
                else:
                    color = color_id


                bg_color_map[match] = color

        my.color_map[name] = bg_color_map, text_color_map
Esempio n. 21
0
    def init_color_map(self):
        ''' initialize the color map for bg color and text color'''
        search_type = self.kwargs.get('search_type')

        if not search_type:
            search_type = 'sthpw/task'

        # get the color map
        from pyasm.widget import WidgetConfigView
        color_config = WidgetConfigView.get_by_search_type(
            search_type, "color")
        color_xml = color_config.configs[0].xml
        self.color_map = {}
        name = 'status'
        xpath = "config/color/element[@name='%s']/colors" % name
        text_xpath = "config/color/element[@name='%s']/text_colors" % name
        bg_color_node = color_xml.get_node(xpath)
        bg_color_map = color_xml.get_node_values_of_children(bg_color_node)

        text_color_node = color_xml.get_node(text_xpath)
        text_color_map = color_xml.get_node_values_of_children(text_color_node)

        # use old weird query language
        query = bg_color_map.get("query")
        query2 = bg_color_map.get("query2")
        if query:
            bg_color_map = {}

            search_type, match_col, color_col = query.split("|")
            search = Search(search_type)
            sobjects = search.get_sobjects()

            # match to a second table
            if query2:
                search_type2, match_col2, color_col2 = query2.split("|")
                search2 = Search(search_type2)
                sobjects2 = search2.get_sobjects()
            else:
                sobjects2 = []

            for sobject in sobjects:
                match = sobject.get_value(match_col)
                color_id = sobject.get_value(color_col)

                for sobject2 in sobjects2:
                    if sobject2.get_value(match_col2) == color_id:
                        color = sobject2.get_value(color_col2)
                        break
                else:
                    color = color_id

                bg_color_map[match] = color

        self.color_map[name] = bg_color_map, text_color_map
Esempio n. 22
0
    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
Esempio n. 23
0
 def get_hint_text(cls, search_type, simple_search_view=''):
     '''Get the hint text for keyword search col defined from widget_config'''
     if simple_search_view:
         from pyasm.widget import WidgetConfigView
         config = WidgetConfigView.get_by_search_type(search_type, simple_search_view)
         # assume the keyword filter is named "keyword"
         options = config.get_display_options('keyword')
         hint_text = options.get('hint_text')
         if hint_text:
             return hint_text
     
     return ""
Esempio n. 24
0
    def get_hint_text(cls, search_type, simple_search_view=''):
        '''Get the hint text for keyword search col defined from widget_config'''
        if simple_search_view:
            from pyasm.widget import WidgetConfigView
            config = WidgetConfigView.get_by_search_type(
                search_type, simple_search_view)
            # assume the keyword filter is named "keyword"
            options = config.get_display_options('keyword')
            hint_text = options.get('hint_text')
            if hint_text:
                return hint_text

        return ""
Esempio n. 25
0
    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
Esempio n. 26
0
    def get_display(self):
        self.preprocess()

        sobject = self.get_current_sobject()

        view = self.get_option("view")
        if not view:
            view = "custom_view"

        search_type = sobject.get_search_type_obj()
        config = WidgetConfigView.get_by_search_type(search_type, view)
        widget_config_view = WidgetConfigView(search_type, view, [config])
        if not config:
            span = SpanWdg("None")
            span.add_style("color: #ccc")
            return span
        try:
            base = CustomConfigWdg(search_type, view, \
                config=widget_config_view, input_prefix="edit")

        except TacticException, e:
            span = SpanWdg("None")
            span.add_style("color: #ccc")
            return span
Esempio n. 27
0
    def get_search_col(cls, search_type, simple_search_view=''):
        '''Get the appropriate keyword search col based on column existence in this sType'''
        if simple_search_view:
            from pyasm.widget import WidgetConfigView
            config = WidgetConfigView.get_by_search_type(search_type, simple_search_view)
            # assume the keyword filter is named "keyword"
            options = config.get_display_options('keyword')
            column = options.get('column')
           
            if column:
                return column

        for col in cls.SEARCH_COLS:
            if SearchType.column_exists(search_type, col):
                return col

        return cls.SEARCH_COLS[-1]
    def get_search_col(cls, search_type, simple_search_view=''):
        '''Get the appropriate keyword search col based on column existence in this sType'''
        if simple_search_view:
            from pyasm.widget import WidgetConfigView
            config = WidgetConfigView.get_by_search_type(search_type, simple_search_view)
            # assume the keyword filter is named "keyword"
            options = config.get_display_options('keyword')
            column = options.get('column')
           
            if column:
                return column

        for col in cls.SEARCH_COLS:
            if SearchType.column_exists(search_type, col):
                return col

        return cls.SEARCH_COLS[-1]
Esempio n. 29
0
    def get_definitions(my, element_name):
        '''get all the definitions for this element'''
        search_type = my.kwargs.get("search_type")
        view = my.kwargs.get("view")
        config_view = WidgetConfigView.get_by_search_type(search_type, view)

        display_class = config_view.get_display_handler(element_name)
        element_attr = config_view.get_element_attributes(element_name)

        for config in config_view.get_configs():
            #print config
            view = config.get_view()
            file_path = config.get_file_path()
            if not file_path:
                file_path = "from Database"
            #print view, file_path

            xml = config.get_element_xml(element_name)
Esempio n. 30
0
    def preprocess(my):
        my.elements = my.kwargs.get("elements")
        if my.elements:
            my.elements = my.elements.split('|')
        else:
            my.elements = []

        # get the definition
        sobjects = my.sobjects
        if sobjects:
            sobject = sobjects[0]
            search_type = sobject.get_search_type()
            view = 'definition'

            from pyasm.widget import WidgetConfigView
            my.config = WidgetConfigView.get_by_search_type(search_type, view)
        else:
            my.config = None
Esempio n. 31
0
    def get_definitions(self, element_name):
        '''get all the definitions for this element'''
        search_type = self.kwargs.get("search_type")
        view = self.kwargs.get("view")
        config_view = WidgetConfigView.get_by_search_type(search_type, view)

        display_class = config_view.get_display_handler(element_name)
        element_attr = config_view.get_element_attributes(element_name)

        for config in config_view.get_configs():
            #print config
            view = config.get_view()
            file_path = config.get_file_path()
            if not file_path:
                file_path = "from Database"
            #print view, file_path

            xml = config.get_element_xml(element_name)
Esempio n. 32
0
    def preprocess(my):
        my.elements = my.kwargs.get("elements")
        if my.elements:
            my.elements = my.elements.split('|')
        else:
            my.elements = []

        # get the definition
        sobjects = my.sobjects
        if sobjects:
            sobject = sobjects[0]
            search_type = sobject.get_search_type()
            view = 'definition'

            from pyasm.widget import WidgetConfigView
            my.config = WidgetConfigView.get_by_search_type(search_type, view)
        else:
            my.config = None
Esempio n. 33
0
    def check(my):
        my.web = WebContainer.get_web()
        search_type = my.sobject.get_search_type_obj()
        
        config = WidgetConfigView.get_by_search_type(search_type, "insert", local_search=True)
        columns = config.get_element_names()

        if len(columns) != 3:
            raise TacticException('The command is expecting 3 fields only.')
      
        my.date = my.web.get_form_value('edit|%s' % columns[0])
        my.desc =  my.web.get_form_value('edit|%s'% columns[1])
        date = Date(db_date=my.date)
        my.year = date.get_year()
        my.week = date.get_week()
        my.project_code =  my.web.get_form_value('edit|%s'% columns[2])
         
        if not my.desc or not my.date or not my.project_code:
            raise UserException('One or more fields are empty.')
        Project.set_project(my.project_code)
        return True
Esempio n. 34
0
    def _get_edit_config(my, 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
Esempio n. 35
0
    def check(my):
        my.web = WebContainer.get_web()
        search_type = my.sobject.get_search_type_obj()

        config = WidgetConfigView.get_by_search_type(search_type,
                                                     "insert",
                                                     local_search=True)
        columns = config.get_element_names()

        if len(columns) != 3:
            raise TacticException('The command is expecting 3 fields only.')

        my.date = my.web.get_form_value('edit|%s' % columns[0])
        my.desc = my.web.get_form_value('edit|%s' % columns[1])
        date = Date(db_date=my.date)
        my.year = date.get_year()
        my.week = date.get_week()
        my.project_code = my.web.get_form_value('edit|%s' % columns[2])

        if not my.desc or not my.date or not my.project_code:
            raise UserException('One or more fields are empty.')
        Project.set_project(my.project_code)
        return True
Esempio n. 36
0
    def get_display(my):
        web = WebContainer.get_web()

        if web.get_form_value("Insert/Exit"):
            widget = Widget()
            iframe = WebContainer.get_iframe()
            widget.add( HtmlElement.script(iframe.get_off_script()) )
            widget.add( HtmlElement.script("window.parent.document.form.submit()") )
            return widget


        database = Project.get_project_code()
        search_type = web.get_form_value("search_type")
        assert search_type

        view = web.get_form_value("view")
        if not view:
            view = get_template_view()
        
        widget = DivWdg()

        WebContainer.register_cmd("pyasm.widget.CustomAddElementCbk")

        # remember some parameters
        widget.add( HiddenWdg("search_type", search_type) )
        widget.add( HiddenWdg("view", view) )

        # Get the definition widget and list all of the custom elements
        config = WidgetConfigView.get_by_search_type(search_type,DEFAULT_VIEW)
        element_names = config.get_element_names()

        # show current custom
        widget.add("<h3>Add Element for [%s]</h3>" % search_type)

        widget.add( my.get_new_custom_widget(view) )

        return widget
Esempio n. 37
0
    def get_display(my):
        web = WebContainer.get_web()

        if web.get_form_value("Insert/Exit"):
            widget = Widget()
            iframe = WebContainer.get_iframe()
            widget.add( HtmlElement.script(iframe.get_off_script()) )
            widget.add( HtmlElement.script("window.parent.document.form.submit()") )
            return widget


        database = Project.get_project_code()
        search_type = web.get_form_value("search_type")
        assert search_type

        view = web.get_form_value("view")
        if not view:
            view = get_template_view()
        
        widget = DivWdg()

        WebContainer.register_cmd("pyasm.widget.CustomAddElementCbk")

        # remember some parameters
        widget.add( HiddenWdg("search_type", search_type) )
        widget.add( HiddenWdg("view", view) )

        # Get the definition widget and list all of the custom elements
        config = WidgetConfigView.get_by_search_type(search_type,DEFAULT_VIEW)
        element_names = config.get_element_names()

        # show current custom
        widget.add("<h3>Add Element for [%s]</h3>" % search_type)

        widget.add( my.get_new_custom_widget(view) )

        return widget
Esempio n. 38
0
    def execute(my):
        sobject = my.sobject


        search_type = sobject.get_search_type_obj()
        config = WidgetConfigView.get_by_search_type(search_type, "custom")
        if not config:
            return

        my.element_names = config.get_element_names()

        # create all of the handlers
        action_handlers = []

        for element_name in (my.element_names):
            action_handler_class = \
                config.get_action_handler(element_name)

            if action_handler_class == "":
                action_handler_class = "DatabaseAction"
        

            action_handler = WidgetConfig.create_widget( action_handler_class )
            action_handler.set_name(element_name)
            action_handler.set_input_prefix("edit")

            action_options = config.get_action_options(element_name)
            for key, value in action_options.items():
                action_handler.set_option(key, value)
            action_handlers.append(action_handler)

        # set the sobject for each action handler
        for action_handler in action_handlers:
            action_handler.set_sobject(sobject)
            if action_handler.check():
                action_handler.execute()
Esempio n. 39
0
    def get_display(my):
        my.preprocess()

        sobject = my.get_current_sobject()

        view = my.get_option("view")
        if not view:
            view = "custom_view"

        search_type = sobject.get_search_type_obj()
        config = WidgetConfigView.get_by_search_type(search_type, view)
        widget_config_view = WidgetConfigView(search_type, view, [config])
        if not config:
            span = SpanWdg("None")
            span.add_style("color: #ccc")
            return span
        try:
            base = CustomConfigWdg(search_type, view, \
                config=widget_config_view, input_prefix="edit")
            
        except TacticException, e:
            span = SpanWdg("None")
            span.add_style("color: #ccc")
            return span
Esempio n. 40
0
    def get_display(my):

        my.sobject = my.get_sobject()

        top = DivWdg()
        top.add_class("spt_detail_top")
        top.add_color("background", "background")
        top.add_color("color", "color")

        if not my.sobject:
            top.add("No SObject defined for this widget")
            return top

        if my.parent:
            my.search_type = my.parent.get_base_search_type()
            my.search_key = SearchKey.get_by_sobject(my.parent)
            top.add_attr("spt_parent_key", my.search_key)
            my.pipeline_code = my.parent.get_value("pipeline_code",
                                                   no_exception=True)
            my.full_search_type = my.parent.get_search_type()
        else:
            my.pipeline_code = my.sobject.get_value("pipeline_code",
                                                    no_exception=True)
            my.search_type = my.sobject.get_base_search_type()
            my.search_key = SearchKey.get_by_sobject(my.sobject)
            my.full_search_type = my.sobject.get_search_type()

        if not my.pipeline_code:
            my.pipeline_code = 'default'

        top.add_style("text-align: left")
        my.set_as_panel(top)

        table = Table()
        #from tactic.ui.container import ResizableTableWdg
        #table = ResizableTableWdg()
        table.add_color("background", "background")
        table.add_color("color", "color")
        top.add(table)
        table.set_max_width()

        table.add_row()

        # left
        #td = table.add_cell(resize=False)
        td = table.add_cell()
        #td.add_style("padding: 10px")
        td.add_style("width: 200px")
        td.add_style("min-width: 200px")
        td.add_style("vertical-align: top")
        #td.add_border()
        #td.add_style("border-style: solid")
        #td.add_style("border-width: 1px 0 1px 1px")
        #td.add_color("border-color", "border")
        #td.add_color("background", "background", -10)

        if my.parent:
            code = my.parent.get_code()
        else:
            code = my.sobject.get_code()

        # add the tile
        title = DivWdg()
        td.add(title)
        title.add_gradient("background", "background3", 0, -10)
        title.add_style("height: 20px")
        title.add_style("padding: 4px")
        title.add_style("font-weight: bold")
        title.add_style("font-size: 1.4em")
        title.add("%s" % code)
        title.add_border()

        div = DivWdg()
        td.add(div)
        div.add_class("spt_sobject_detail_top")

        thumb_table = Table()
        div.add(thumb_table)
        thumb_table.add_row()

        thumb = ThumbWdg()
        # use a larger version for clearer display
        thumb.set_icon_type('web')

        # prefer to see the original image, then web
        thumb.set_option('image_link_order', 'main|web|icon')
        thumb.set_option("detail", "false")
        thumb.set_option("icon_size", "100%")

        td = thumb_table.add_cell(thumb)
        td.add_style("vertical-align: top")
        td.add_style("width: 240px")
        td.add_style("padding: 15px")

        if my.parent:
            thumb.set_sobject(my.parent)
        else:
            thumb.set_sobject(my.sobject)

        sobject_info_wdg = my.get_sobject_info_wdg()
        sobject_info_wdg.add_style("width: 200px")

        td.add(sobject_info_wdg)

        if my.search_type == 'sthpw/task' and not my.parent:
            pass
        else:
            sobject_info_wdg = my.get_sobject_detail_wdg()
            td = table.add_cell()
            td.add(sobject_info_wdg)
            td.add_style("vertical-align: top")
            td.add_style("overflow: hidden")

        # right
        td = table.add_cell()
        td.add_style("text-align: left")
        td.add_style("vertical-align: top")
        #td.add_color("background", "background", -10)
        td.add_class("spt_notes_wrapper")
        #td.add_border()

        # add the title
        title = DivWdg()
        td.add(title)
        title.add_gradient("background", "background3", 0, -10)
        title.add_style("height: 20px")
        title.add_style("padding: 4px")
        title.add_style("font-weight: bold")
        title.add("Notes")
        title.add_border()

        notes_div = DivWdg()
        td.add(notes_div)
        from tactic.ui.widget.discussion_wdg import DiscussionWdg
        discussion_wdg = DiscussionWdg(search_key=my.search_key,
                                       context_hidden=False,
                                       show_note_expand=False)
        notes_div.add(discussion_wdg)
        notes_div.add_style("min-width: 300px")
        notes_div.add_style("height: 200")
        notes_div.add_style("overflow-y: auto")
        notes_div.add_class("spt_resizable")

        # get the process
        if my.parent:
            process = my.sobject.get_value("process")
        else:
            process = ''

        # content
        tr = table.add_row()
        td = table.add_cell()
        td.add_attr("colspan", "5")
        #td.add_attr("colspan", "3")

        # create a state for tab.  The tab only passes a search key
        # parent key
        search_key = SearchKey.get_by_sobject(my.sobject)
        parent = my.sobject.get_parent()
        if parent:
            parent_key = parent.get_search_key()
        else:
            parent_key = ""

        state = {
            'search_key': search_key,
            'parent_key': parent_key,
            'process': process,
        }
        WebState.get().push(state)

        config_xml = my.get_config_xml()
        config = WidgetConfig.get(view="tab", xml=config_xml)

        if process:
            custom_view = "tab_config_%s" % process
        else:
            custom_view = "tab_config"
        search = Search("config/widget_config")
        search.add_filter("category", "TabWdg")
        search.add_filter("search_type", my.search_type)
        search.add_filter("view", custom_view)
        custom_config_sobj = search.get_sobject()
        if custom_config_sobj:
            custom_config_xml = custom_config_sobj.get_value("config")
            custom_config = WidgetConfig.get(view=custom_view,
                                             xml=custom_config_xml)
            config = WidgetConfigView(search_type='TabWdg',
                                      view=custom_view,
                                      configs=[custom_config, config])

        #menu = my.get_extra_menu()
        #tab = TabWdg(config=config, state=state, extra_menu=menu)
        tab = TabWdg(config=config,
                     state=state,
                     show_add=False,
                     show_remove=False,
                     tab_offset=5)
        tab.add_style("margin: 0px -2px -2px -2px")
        td.add(tab)
        td.add_style("padding-top: 10px")

        return top
Esempio n. 41
0
    def get_config(cls, config_search_type, view, default=False):

        config = None
        configs = []
        login = None
        defined_view = view

        # this is really for the predefined view that shouldn't go to the db
        # otherwise, it is a never ending cycle.
        if default:
            views = [defined_view, 'definition']
            cls.add_internal_config(configs, views)

        # special condition for children
        elif view in ['children']:
            tmp_path = __file__
            dir_name = os.path.dirname(tmp_path)
            file_path = "%s/../config/children-conf.xml" % (dir_name)
            config = WidgetConfig.get(file_path=file_path, view=defined_view)
            configs.append(config)

        elif view == "definition":
            # look for a definition in the database
            search = Search("config/widget_config")
            search.add_filter("search_type", config_search_type)
            search.add_filter("view", "definition")
            # lower the chance of getting some other definition files
            search.add_filter("login", None)
            config = search.get_sobject()
            if config:
                configs.append(config)
            # We should not allow redefinition of a predefined item
            # so it is fine to add internal config for definition
            # then look for a definition in the definition file
            cls.add_internal_config(configs, ['definition'])

        else:
            # first look in the database
            search = Search("config/widget_config")
            search.add_filter("search_type", config_search_type)
            search.add_filter("view", view)
            #search.add_filter("login", login)

            config = search.get_sobject()
            if config:
                configs.append(config)
            # then look for a file
            cls.add_internal_config(configs, [defined_view])

            # look for a definition in the database
            search = Search("config/widget_config")
            search.add_filter("search_type", config_search_type)
            search.add_filter("view", "definition")
            # lower the chance of getting some other definition files
            search.add_filter("login", None)
            config = search.get_sobject()
            if config:
                configs.append(config)

            # then look for a definition in the definition file
            cls.add_internal_config(configs, ['definition'])

        widget_config_view = WidgetConfigView(config_search_type, view,
                                              configs)
        return widget_config_view
Esempio n. 42
0
    def get_sobject_detail_wdg(my):
        div = DivWdg()
        #div.add_style("float: right")
        div.add_style("width: 100%")
        div.add_style("height: 100%")
        div.add_style("padding-top: 5px")


        """
        button_div.add_class("spt_left")
        div.add(button_div)
        button = IconButtonWdg(title="Show More Details", icon=IconWdg.RIGHT)
        button_div.add(button)
        button_div.add_style("position: absolute")
        button_div.add_style("margin-left: -30px")
        button_div.add_style("margin-top: -2px")
        button_div.add_style("display: none")

        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_detail_top");
        var detail = top.getElement(".spt_sobject_detail");
        spt.toggle_show_hide(detail);
        var left = top.getElement(".spt_left");
        spt.hide(left);
        var right = top.getElement(".spt_right");
        spt.show(right);
        '''
        } )


        button_div = DivWdg()
        button_div.add_class("spt_right")
        div.add(button_div)
        button = IconButtonWdg(title="Show More Details", icon=IconWdg.LEFT)
        button_div.add(button)
        button_div.add_style("position: absolute")
        button_div.add_style("margin-left: -30px")
        button_div.add_style("margin-top: -2px")
        #button_div.add_style("display: none")

        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_detail_top");
        var detail = top.getElement(".spt_sobject_detail");
        spt.toggle_show_hide(detail);
        var left = top.getElement(".spt_left");
        spt.show(left);
        var right = top.getElement(".spt_right");
        spt.hide(right);
        '''
        } )
        """



        info_div = DivWdg()
        div.add( info_div )
        #info_div.add_style("display: none")
        info_div.add_class("spt_sobject_detail")
        #info_div.add_style("width: 300px")
        info_div.add_style("padding: 30px 0px 30px 0px")

        info_table = Table()
        info_table.add_color("color", "color")
        info_div.add(info_table)


        edit_div = DivWdg()
        info_div.add(edit_div)
        edit_div.add_style("margin-top: -35px")
        edit_div.add_style("margin-left: 1px")
        edit_div.add_style("margin-right: -2px")
        #edit_div.add_style("overflow: scroll")
        edit_div.add_style("height: 100%")

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

        ignore = ["preview", "notes"]

        element_names = ['name','description','tasks']
        config = WidgetConfigView.get_by_search_type(search_type=my.full_search_type, view=view)
        config_element_names = config.get_element_names()
        for x in config_element_names:
            if x in ignore:
                continue
            if x not in element_names:
                element_names.append(x)



        # add the tile
        title = DivWdg()
        edit_div.add(title)
        title.add_gradient("background", "background3", 0, -10)
        title.add_style("height: 20px")
        title.add_style("padding: 4px")
        title.add_style("font-weight: bold")
        title.add("&nbsp")
        title.add_border()

        from tactic.ui.panel.edit_layout_wdg import EditLayoutWdg
        edit = EditLayoutWdg(search_type=my.full_search_type, mode='view', view="detail", search_key=my.search_key, width=400, title=' ', ignore=ignore, element_names=element_names)
        edit_div.add(edit)

        return div
Esempio n. 43
0
    def execute(my):
        assert my.search_type
        assert my.view
        assert my.file_path

        search = Search(my.search_type)
        if my.search_ids:
            search.add_enum_order_by("id", my.search_ids)
            search.add_filters("id", my.search_ids)
            sobjects = search.get_sobjects()
        elif my.search_keys:

            sobjects = Search.get_by_search_keys(my.search_keys, keep_order=True)
            """
            search_codes = [SearchKey.extract_code(i) for i in my.search_keys if SearchKey.extract_code(i) ]
            if search_codes:
                search.add_filters("code", search_codes)
            else:
                search_ids = [SearchKey.extract_id(i) for i in my.search_keys if SearchKey.extract_id(i) ]
                search.add_filters("id", search_ids)
            """
        else:
            sobjects = search.get_sobjects()

        from pyasm.widget import WidgetConfigView
        from pyasm.web import Widget
        config = WidgetConfigView.get_by_search_type(my.search_type, my.view)
        
        columns = []
        if my.column_names:
            columns = my.column_names
        # should allow exporting ids only
        """
        else:
            if not config:
                columns = search.get_columns()
            else:
                columns = config.get_element_names()
        """
        if my.include_id:
            columns.insert(0, "id")

        # create the csv file
        org_file = file(my.file_path, 'w')
        csvwriter = csv.writer(org_file, quoting=csv.QUOTE_NONNUMERIC)

        # write the titles
        csvwriter.writerow(columns)

        elements = my.get_elements(config, columns)
        display_option_dict = {}
        # this is for widgets that do preprocessing on all sobjects
        for idx, element in enumerate(elements):
            element.set_sobjects(sobjects)
            element.preprocess()
            display_options = config.get_display_options(columns[idx])
            display_option_dict[element] = display_options
            
        for idx, sobject in enumerate(sobjects):
            values = []
            
            for element in elements:
                
                element.set_current_index(idx)
                value = element.get_text_value()
                if isinstance(value, Widget):
                    value = value.get_buffer_display()
                elif isinstance(value, basestring):
                    if isinstance(value, unicode):
                        value = value.encode('UTF-8', 'ignore')
                else:
                    value = str(value)

                options = display_option_dict.get(element)
                if options.get('csv_force_string')=='true' and value:
                    value= '#FORCESTRING#%s'%value
                values.append( value )
            # write the values as list
            csvwriter.writerow(values)

        org_file.close()


        file2 = open(my.file_path, 'r')
        mod_file_path = '%s_mod' %my.file_path
        mod_file = open(mod_file_path, 'w')
        for line in file2:
            mod_line = re.sub(r'(\'|\"|)(#FORCESTRING#)', '=\\1', line)
            mod_file.write(mod_line)

        # new file
        file2.close()
        mod_file.close()

        #os.unlink(my.file_path)
        shutil.move(mod_file_path, my.file_path)
Esempio n. 44
0
class ManageSearchTypeDetailWdg(ManageSideBarDetailWdg):

    ADD_COLUMN = "Commit New Column"
    MODIFY_COLUMN = "Modify Column"
    REMOVE_COLUMN = "Remove Column"

    def get_config(self, search_type, view,  default=False, personal=False):
        config = ManageSearchTypeMenuWdg.get_config(search_type, view, default=default)
        return config


    def init(self):
        '''initialize the widget_config, and from there retrieve the schema_config'''
        web = WebContainer.get_web()
        self.search_type = self.kwargs.get('search_type')
        
        element_name = self.kwargs.get('element_name')
        self.view = self.kwargs.get('view')
        
        # FIXME: comment out the assert for now to avoid error screen
        if not self.view:
            self.view = 'table'
        #assert self.view

        self.config_xml = self.kwargs.get('config_xml')
        if not self.config_xml:
            self.config_xml = web.get_form_value('config_xml')
        
        self.default = self.kwargs.get('default') == 'True'

        cbk = ManageSearchTypeDetailCbk(search_type=self.search_type, view=self.view, \
                element_name=element_name)
        Command.execute_cmd(cbk)

        self.config_string = ""
        self.data_type_string = ""
        self.name_string = ""
        self.title_string = ""
        self.nullable_string = ""
        self.has_column = True


       
        if element_name:
            if self.config_xml:
                self.config_string = self.config_xml
                whole_config_string = "<config><%s>%s</%s></config>"%(self.view, self.config_xml, self.view)
                config = WidgetConfig.get(xml=whole_config_string, view=self.view)
                self.config = WidgetConfigView(self.search_type, self.view, [config])
            else:
                # don't pass in default here
                self.config = self.get_config(self.search_type, self.view)
                node = self.config.get_element_node(element_name)
                if node is not None:
                    config_xml = self.config.get_xml()
                    

                    self.config_string = config_xml.to_string(node)
                    self.title_string = config_xml.get_attribute(node, 'title')
            schema_config = SearchType.get_schema_config(self.search_type)
            
            attributes = schema_config.get_element_attributes(element_name)
            self.data_type_string = attributes.get("data_type")
            
            # double_precision is float
            if self.data_type_string == 'double precision':
                self.data_type_string = 'float'

            self.name_string = attributes.get("name")
            self.nullable_string = attributes.get("nullable")
            self.is_new_column = attributes.get("new") == 'True'

            # a database columnless widget
            if not self.name_string:
                self.has_column = False
                                
    def get_display(self):

        # add the detail widget
        detail_wdg = DivWdg(css='spt_detail_panel')
        if not self.name_string and not self.config_string:
            detail_wdg.add("<br/>"*3)
            detail_wdg.add('<- Click on an item on the left for modification.')
            detail_wdg.add_style("padding: 10px")
            detail_wdg.add_color("background", "background", -5)
            detail_wdg.add_style("width: 350px")
            detail_wdg.add_style("height: 400px")
            detail_wdg.add_border()

            return detail_wdg

        if self.kwargs.get("mode") == "empty":
            overlay = DivWdg()
            detail_wdg.add(overlay)

        detail_wdg.add_border()
        detail_wdg.add_color("color", "black")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_color("background", "background", -5)

        detail_wdg.set_id('search_type_detail')

        # put in the selection for simple or advanced
        select = SelectWdg("config_mode", label='Mode: ')
        select.set_persistence()
        values = ['simple', 'advanced']
        select.set_option("values", values)
        config_mode = select.get_value()
        #select.add_behavior({"type": "change", "cbjs_action": "spt.simple_display_toggle( spt.get_cousin(bvr.src_el, '.spt_detail_panel','.config_simple') )"})
        select.add_behavior({"type": "change", "cbjs_action": \
            "spt.simple_display_toggle( spt.get_cousin(bvr.src_el, '.spt_detail_panel','.config_advanced')); %s" %select.get_save_script()})

        select.add_class('spt_config_mode')

        title_div = DivWdg("Column Detail")
        title_div.add_class("maq_search_bar")
        detail_wdg.add(title_div)
        detail_wdg.add("<br/>")
        detail_wdg.add(select)
        detail_wdg.add(HtmlElement.br(2))

        #simple_mode_wdg = WidgetDetailSimpleModeWdg()
        #detail_wdg.add(simple_mode_wdg)
        #detail_wdg.add(HtmlElement.br(2))

        if self.is_new_column:
            detail_wdg.add( self.get_new_definition_wdg() )
        else:
            
            simple_wdg = self.get_simple_definition_wdg()
           
            simple_wdg.add_class("config_simple")
            detail_wdg.add( simple_wdg )
            adv_wdg = self.get_advanced_definition_wdg()
            adv_wdg.add_class("config_advanced")
            if config_mode == 'simple':
                adv_wdg.add_style('display: none')
            detail_wdg.add(HtmlElement.br(2))
            detail_wdg.add( adv_wdg )

        detail_wdg.add(HtmlElement.br(2))


        security_wdg = self.get_security_wdg()
        detail_wdg.add(security_wdg)


        # add hidden input for view for panel refreshing
        # we are only interested in whether it is project_view or definition
        # sub-views of project_view is not of our interest

        #if self.view != 'project_view':
        #    self.view = 'custom_definition'
        detail_wdg.add(HiddenWdg('view', self.view))


        return detail_wdg

    def get_advanced_definition_wdg(self):
        # add the advanced entry
        advanced = DivWdg()
        advanced.add_style("margin-top: 10px")
        advanced.add_style("padding: 10px")
        advanced.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add("Advanced - XML Column Definition")
        title.add_style("margin-top: -23")
        advanced.add(title)
        advanced.add("<br/>")

        input = TextAreaWdg("config_xml")
        input.set_id("config_xml")
        input.set_option("rows", "10")
        input.set_option("cols", "70")
        input.set_value(self.config_string)
        advanced.add(input)
        advanced.add(HtmlElement.br(2))

        button_div = DivWdg()
        button_div.add_style("text-align: center")
        

        button = ActionButtonWdg(title="Save Definition") 
        #button = ProdIconButtonWdg("Save Definition")
        button.add_event("onclick", "spt.custom_project.save_definition_cbk()")
        button_div.add(button)
        button_div.add_style("margin-left: 130px")
        advanced.add(button_div)

        return advanced

    def get_new_definition_wdg(self):
        detail_wdg = DivWdg()
        detail_wdg.add_style("color: black")
        detail_wdg.add_style("width: 350px")
        detail_wdg.add_style("margin-top: 10px")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add("Column Definition")
        title.add_style("margin-top: -22px")
        detail_wdg.add(title)


        # add a name entry
        title = SpanWdg()
        detail_wdg.add("Name: ")
        detail_wdg.add(title)
        input = SpanWdg()
        input.add_style('padding-top: 6px')
        input.set_id("config_element_name")
        text = TextWdg('column_name')
        text.set_value(self.name_string)
        input.add(text)
        detail_wdg.add(input)
        hidden = HiddenWdg('target_search_type', self.search_type)
        detail_wdg.add(hidden)

        detail_wdg.add(HtmlElement.br(2))

        # add data_type entry
        data_type = SpanWdg()
        default_data_types = ['varchar(256)','varchar', 'character', 'text', 'integer', 'float', 'boolean', 'timestamp', 'Other...']
        select = SelectWdg('config_data_type', label ='Data Type: ')
        #detail_wdg.add(": ")
        select.set_option('values', default_data_types )
        select.set_value(self.data_type_string)
        
        select.add_behavior({'type': 'change', 
            'cbjs_action': "if (bvr.src_el.value=='Other...') {spt.show('config_data_type_custom');}\
                    else {spt.hide('config_data_type_custom');}"})
        data_type.add(select) 

        text = TextWdg('config_data_type_custom')
        span = SpanWdg("Other: ", css='med')
        span.add(text)
        span.set_id('config_data_type_custom')
        span.add_style('display','none')
        text.set_value(self.data_type_string)

        data_type.add("<br/>")
        data_type.add(span)
        detail_wdg.add(data_type)
            
        detail_wdg.add("<br/>")
        # add a nullable entry
        nullable = DivWdg()
        checkbox = CheckboxWdg('config_nullable', label ='Allow null(empty) value: ')
        nullable.add(checkbox)

        if self.nullable_string in ['True', 'true']:
            checkbox.set_checked()
        
        detail_wdg.add(nullable)

        return detail_wdg

    def get_simple_definition_wdg(self):

        detail_wdg = DivWdg()
        detail_wdg.add_color("color", "color")
        detail_wdg.add_style("width: 350px")
        detail_wdg.add_style("margin-top: 10px")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_border()
        title = DivWdg()
        title.add_style("margin-top: -23px")
        detail_wdg.add(title)
        if not self.name_string:
            title.add('No database column')
            return detail_wdg
        
        title.add("Column Definition")
       


        # add a name entry
        detail_wdg.add("<br/>")
        title = SpanWdg()
        detail_wdg.add("Name: ")
        detail_wdg.add(title)
        input = SpanWdg()
        input.add_style('padding-top: 6px')
        input.set_id("config_element_name")
        input.add(HtmlElement.b(self.name_string))
        detail_wdg.add(input)
        hidden = HiddenWdg('column_name', self.name_string)
        detail_wdg.add(hidden)
        hidden = HiddenWdg('target_search_type', self.search_type)
        detail_wdg.add(hidden)

        detail_wdg.add(HtmlElement.br(2))

        # add data_type entry
        data_type = SpanWdg()
        default_data_types = ['varchar(256)','varchar', 'character', 'text', 'integer', 'float', 'boolean', 'timestamp', 'Other...']
        select = SelectWdg('config_data_type', label ='Data Type: ')
        #detail_wdg.add(": ")
        select.set_option('values', default_data_types )
        select.set_value(self.data_type_string)
        
        select.add_behavior({'type': 'change', 
            'cbjs_action': "if (bvr.src_el.value=='Other...') {spt.show('config_data_type_custom');}\
                    else {spt.hide('config_data_type_custom');}"})
        data_type.add(select) 

        text = TextWdg('config_data_type_custom')
        span = SpanWdg("Other: ", css='med')
        span.add(text)
        span.set_id('config_data_type_custom')
        span.add_style('display','none')
        text.set_value(self.data_type_string)

        data_type.add("<br/>")
        data_type.add(span)
        detail_wdg.add(data_type)
            
        detail_wdg.add("<br/>")
        # add a nullable entry
        nullable = SpanWdg()
        checkbox = CheckboxWdg('config_nullable', label ='Allow null(empty) value: ')
        #detail_wdg.add(": ")
        nullable.add(checkbox)
   

        if self.nullable_string in ['True', 'true']:
            checkbox.set_checked()
        
        detail_wdg.add(nullable)


        #constraint = DivWdg()
        #detail_wdg.add(constraint)
        #constraint.add_style("margin-top: 10px")
        #constraint.add("Constraint: ")
        #select = SelectWdg("config_constraint")
        #constraint.add(select)
        #select.set_option("values", "unique|indexed")
        #select.add_empty_option("-- None --")




        button_div = DivWdg()
        button_div.add_style("text-align: center")


        button_div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
spt.manage_search_type = {};

spt.manage_search_type.change_column_cbk = function(bvr) {
    var class_name = 'tactic.ui.panel.AlterSearchTypeCbk';
    var options ={
        'alter_mode': bvr.alter_mode,
        'title': bvr.title
    };

    try {
        var server = TacticServerStub.get();
        var panel = $('search_type_detail');
        if (! panel.getAttribute("spt_class_name") ) {
            panel = panel.getParent(".spt_panel");
        }
        var values = spt.api.Utility.get_input_values(panel);
        rtn = server.execute_cmd(class_name, options, values);
        if (bvr.alter_mode == 'Remove Column')
            spt.info("Column [" + bvr.column + "] has been deleted.");
        else if (bvr.alter_mode == 'Modify Column')
            spt.notify.show_message("Column [" + bvr.column + "] has been modified.");
    }
    catch (e) {
        spt.alert(spt.exception.handler(e));
    }
    var view = 'db_column';
    spt.panel.refresh("ManageSearchTypeMenuWdg_" + view);
    var view = 'definition';
    spt.panel.refresh("ManageSearchTypeMenuWdg_" + view);
}


            '''
        } )


        detail_wdg.add(button_div)
        button_div.add("<hr/><br/>")
        if self.is_new_column:
            button = ActionButtonWdg(title="Commit") 
            #button = ProdIconButtonWdg("Commit New Column")
            button.add_behavior({"type": "click_up", 
                "cbjs_action": "spt.manage_search_type.change_column_cbk(bvr)", \
                        
                        "alter_mode": self.ADD_COLUMN})
            button_div.add(button)
        else:

            table = Table()
            button_div.add(table)
            table.add_row()
            table.center()

            button = ActionButtonWdg(title="Modify") 
            #button = ProdIconButtonWdg("Modify Column")
            button.add_behavior({"type": "click_up", 
            "cbjs_action": '''spt.manage_search_type.change_column_cbk(bvr);
                           ''',
                    "alter_mode": self.MODIFY_COLUMN,
                    "column": self.name_string,
                    "title": self.title_string
                    })
            table.add_cell(button)

            button = ActionButtonWdg(title="Delete") 
            #button = ProdIconButtonWdg("Delete Column")
            #button.add_style('background-color: #BF462E')
            button.add_behavior({"type": "click_up", 
                "cbjs_action": '''
                
                var yes = function() {
                    spt.manage_search_type.change_column_cbk(bvr);
                    
                }
                spt.confirm("Are you sure you wish to delete this column?", yes) 
                ''',
                "alter_mode": self.REMOVE_COLUMN,
                "column": self.name_string
                
                })
            table.add_cell(button)
            button_div.add(HiddenWdg('delete_column'))
            button_div.add(HiddenWdg('modify_column'))

        return detail_wdg

    def get_security_wdg(self):
        return None
Esempio n. 45
0
    def init(my):
        my.is_refresh = my.kwargs.get("refresh")
        my.search_key = my.kwargs.get("search_key")
        my.ticket_key = my.kwargs.get("ticket")
        my.parent_key = my.kwargs.get("parent_key")
        my.expression = my.kwargs.get("expression")

        # This assumed parent can cause errors as it tries to find a
        # relationship between to stypes that don't exist ... or worse,
        # try to bind them when one stype does not have the sufficent columns
        # ie: pipeline_code
        #if not my.parent_key:
        #    project = Project.get()
        #    my.parent_key = project.get_search_key()


        my.code = my.kwargs.get("code")
        sobject = None
        if my.search_key:
            sobject = Search.get_by_search_key(my.search_key)
            my.search_id = sobject.get_id()
            my.search_type = sobject.get_base_search_type()
            if sobject.is_insert():
                my.mode = 'insert'
            else:
                my.mode = 'edit'

        elif my.expression:
            sobject = Search.eval(my.expression, single=True)
            my.search_id = sobject.get_id()
            my.search_type = sobject.get_base_search_type()
            my.mode = 'edit'


        elif my.ticket_key:
            from pyasm.security import Ticket, Login
            ticket = Ticket.get_by_valid_key(my.ticket_key)
            if not ticket:
                raise TacticException("No valid ticket")
            login_code = ticket.get_value("login")
            login = Login.get_by_code(login_code)
            my.search_type = "sthpw/login"
            my.search_id = login.get_id()
            my.mode = 'edit'

        elif my.code:
            my.search_type = my.kwargs.get("search_type")
            search = Search(my.search_type)
            search.add_filter("code", my.code)
            sobject = search.get_sobject()
            
            my.search_id = sobject.get_id()
            my.search_type = sobject.get_base_search_type()
            my.mode = 'edit'


        else:
            my.search_type = my.kwargs.get("search_type")
            my.search_id = my.kwargs.get("search_id")
            if not my.search_id:
                my.search_id = -1
            my.search_id = int(my.search_id)
            if my.search_id != -1:
                my.mode = "edit"
            else:
                my.mode = "insert"
                

        # explicit override
        if my.kwargs.get("mode"):
            my.mode = my.kwargs.get("mode")


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


        default_data = my.kwargs.get('default')
        
        if not default_data:
            default_data = {}
        elif isinstance(default_data, basestring):
            try:
                default_data = jsonloads(default_data)
            except:
                #may be it's regular dictionary
                try:
                    default_data = eval(default_data)
                except:
                    print "Warning: Cannot evaluate [%s]" %default_data
                    default_data = {}

        if sobject:
            my.set_sobjects([sobject], None)
        else:
            my.do_search()

        # TODO: get_config() is going the right direction (less features) but the more complicated method is biased 
        # towards edit and insert view.. and so it needs improvement as well

        if my.view not in ["insert", "edit"]:
            # try a new smaller way to get config only when an explicit view
            # is set
            my.config = my.get_config()
        else:
            my.config = WidgetConfigView.get_by_search_type(my.search_type, my.view, use_cache=False)

        # for inline config definitions
        config_xml = my.kwargs.get("config_xml")
        if config_xml:
            #from pyasm.common import Xml
            #xml = Xml()
            #xml.read_string(config_xml)
            #node = xml.get_node("config/%s" % my.view)
            #xml.set_attribute(node, "class", "tactic.ui.panel.EditWdg")
            #config = WidgetConfig.get(view=my.view, xml=xml)
            config_xml = config_xml.replace("&", "&amp;")

            config = WidgetConfig.get(view="tab", xml=config_xml)
            my.config.insert_config(0, config)

        
        my.skipped_element_names = []

        # if there is a layout view, then find the element names using that
        layout_view = my.kwargs.get("layout_view")
        if layout_view:
            layout_view = layout_view.replace("/", ".")
            search = Search("config/widget_config")
            search.add_filter("view", layout_view)
            layout_config = search.get_sobject()
             
            xml = layout_config.get_xml_value("config")
            my.element_names = xml.get_values("config//html//element/@name")
        else:
            my.element_names = my.config.get_element_names()

        ignore = my.kwargs.get("ignore")
        if isinstance(ignore, basestring):
            ignore = ignore.split("|")
        if not ignore:
            ignore = []

        my.element_titles = []
        my.element_descriptions = []
        for element_name in my.element_names:
            my.element_titles.append( my.config.get_element_title(element_name) )
            my.element_descriptions.append( my.config.get_element_description(element_name) )

        #my.element_titles = my.config.get_element_titles()  
        #my.element_descriptions = my.config.get_element_descriptions()  


        # MongoDb
        # Default columns
        if not my.element_names:
            impl = SearchType.get_database_impl_by_search_type(my.search_type)
            if impl.get_database_type() == "MongoDb":
                my.element_names = impl.get_default_columns()
                my.element_titles = ['Code', 'Name', 'Description']
                my.element_descriptions = ['Code', 'Name', 'Description']




        my.input_prefix = my.kwargs.get('input_prefix')
        if not my.input_prefix:
            my.input_prefix = 'edit'
        
        security = Environment.get_security()
        default_access = "edit"
        project_code = Project.get_project_code()


        for i, element_name in enumerate(my.element_names):

            if element_name in ignore:
                my.skipped_element_names.append(element_name)
                continue


            # check security access
            access_key2 = {
                'search_type': my.search_type,
                'project': project_code
            }
            access_key1 = {
                'search_type': my.search_type,
                'key': element_name, 
                'project': project_code

            }
            access_keys = [access_key1, access_key2]
            is_editable = security.check_access('element', access_keys, "edit", default=default_access)

            
            if not is_editable:
                my.skipped_element_names.append(element_name)
                continue
            widget = my.config.get_display_widget(element_name, kbd_handler=False)
            # some element could be disabled due to its data_type e.g. sql_timestamp
            if not widget:
                my.skipped_element_names.append(element_name)
                continue


            widget.set_sobject(my.sobjects[0])

            default_value = default_data.get(element_name)
            if default_value:
                widget.set_value(default_value)
           
            attrs = my.config.get_element_attributes(element_name)
            editable = widget.is_editable()
            if editable:
                editable = attrs.get("edit")
                editable = editable != "false"
            
            if not editable:
                my.skipped_element_names.append(element_name)
                continue

            # set parent
            widget.set_parent_wdg(my)
            
            # set parent_key in insert mode for now
            if my.mode =='insert' and my.parent_key:
                widget.set_option('parent_key', my.parent_key)
            
            
            title = my.element_titles[i]
            if title:
                widget.set_title(title)

            my.widgets.append(widget)

            description = my.element_descriptions[i]
            widget.add_attr("title", description)
Esempio n. 46
0
    def init(self):
        '''initialize the widget_config, and from there retrieve the schema_config'''
        web = WebContainer.get_web()
        self.search_type = self.kwargs.get('search_type')
        
        element_name = self.kwargs.get('element_name')
        self.view = self.kwargs.get('view')
        
        # FIXME: comment out the assert for now to avoid error screen
        if not self.view:
            self.view = 'table'
        #assert self.view

        self.config_xml = self.kwargs.get('config_xml')
        if not self.config_xml:
            self.config_xml = web.get_form_value('config_xml')
        
        self.default = self.kwargs.get('default') == 'True'

        cbk = ManageSearchTypeDetailCbk(search_type=self.search_type, view=self.view, \
                element_name=element_name)
        Command.execute_cmd(cbk)

        self.config_string = ""
        self.data_type_string = ""
        self.name_string = ""
        self.title_string = ""
        self.nullable_string = ""
        self.has_column = True


       
        if element_name:
            if self.config_xml:
                self.config_string = self.config_xml
                whole_config_string = "<config><%s>%s</%s></config>"%(self.view, self.config_xml, self.view)
                config = WidgetConfig.get(xml=whole_config_string, view=self.view)
                self.config = WidgetConfigView(self.search_type, self.view, [config])
            else:
                # don't pass in default here
                self.config = self.get_config(self.search_type, self.view)
                node = self.config.get_element_node(element_name)
                if node is not None:
                    config_xml = self.config.get_xml()
                    

                    self.config_string = config_xml.to_string(node)
                    self.title_string = config_xml.get_attribute(node, 'title')
            schema_config = SearchType.get_schema_config(self.search_type)
            
            attributes = schema_config.get_element_attributes(element_name)
            self.data_type_string = attributes.get("data_type")
            
            # double_precision is float
            if self.data_type_string == 'double precision':
                self.data_type_string = 'float'

            self.name_string = attributes.get("name")
            self.nullable_string = attributes.get("nullable")
            self.is_new_column = attributes.get("new") == 'True'

            # a database columnless widget
            if not self.name_string:
                self.has_column = False
Esempio n. 47
0
    def get_sobject_detail_wdg(my):
        div = DivWdg()
        #div.add_style("float: right")
        div.add_style("width: 100%")
        div.add_style("height: 100%")
        div.add_style("padding-top: 5px")

        info_div = DivWdg()
        div.add(info_div)
        #info_div.add_style("display: none")
        info_div.add_class("spt_sobject_detail")
        #info_div.add_style("width: 300px")
        info_div.add_style("padding: 30px 0px 30px 0px")

        info_table = Table()
        info_table.add_color("color", "color")
        info_div.add(info_table)

        edit_div = DivWdg()
        info_div.add(edit_div)
        edit_div.add_style("margin-top: -35px")
        edit_div.add_style("margin-left: 1px")
        edit_div.add_style("margin-right: -2px")
        #edit_div.add_style("overflow: scroll")
        edit_div.add_style("height: 100%")

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

        ignore = ["preview", "notes"]

        element_names = ['name', 'description', 'tasks']
        config = WidgetConfigView.get_by_search_type(
            search_type=my.full_search_type, view=view)
        config_element_names = config.get_element_names()
        for x in config_element_names:
            if x in ignore:
                continue
            if x not in element_names:
                element_names.append(x)

        # add the tile
        title = DivWdg()
        edit_div.add(title)
        title.add_gradient("background", "background3", 0, -10)
        title.add_style("height: 20px")
        title.add_style("padding: 4px")
        title.add_style("font-weight: bold")
        title.add("&nbsp")
        title.add_border()

        from tactic.ui.panel.edit_layout_wdg import EditLayoutWdg
        edit = EditLayoutWdg(search_type=my.full_search_type,
                             mode='view',
                             view="detail",
                             search_key=my.search_key,
                             width=400,
                             title=' ',
                             ignore=ignore,
                             element_names=element_names)
        edit_div.add(edit)

        # TEST extra data from a related sobject
        """
        related_search_type = "jobs/photo"
        element_names = ['photographer']

        related = Search.eval("@SOBJECT(%s)" % related_search_type, my.sobject, single=True)

        if related:
            related_key = related.get_search_key()

            from tactic.ui.panel.edit_layout_wdg import EditLayoutWdg
            edit = EditLayoutWdg(search_type=search_type, mode='view', view="detail", search_key=related_key, width=400, title=' ', element_names=element_names)
            edit_div.add(edit)
        """

        return div
Esempio n. 48
0
    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
Esempio n. 49
0
    def preprocess(my):
        my.max_value = 0
        my.min_value = 0
        my.steps = 0

        web = WebContainer.get_web()
        my.width = web.get_form_value("width")
        if not my.width:
            my.width = my.kwargs.get("width")


        my.chart_type = web.get_form_value("chart_type")
        if not my.chart_type:
            my.chart_type = my.kwargs.get("chart_type")
        if not my.chart_type:
            my.chart_type = 'bar'


        my.x_axis = web.get_form_value("x_axis")
        if not my.x_axis:
            my.x_axis = my.kwargs.get("x_axis")
        if not my.x_axis:
            my.x_axis = 'code'


        # FIXME: which should override???
        my.y_axis = web.get_form_values("y_axis")
        if not my.y_axis:
            my.y_axis = my.kwargs.get("y_axis")

        if my.y_axis:
            my.elements = my.y_axis
        else:
            my.elements = my.kwargs.get("elements")
            if not my.elements:
                my.elements = web.get_form_value("elements")

        if isinstance(my.elements,basestring):
            if my.elements:
                my.elements = my.elements.split('|')
            else:
                my.elements = []




        my.search_type = web.get_form_value("search_type")
        if not my.search_type:
            my.search_type = my.kwargs.get("search_type")


        my.search_keys = my.kwargs.get("search_keys")
        if my.search_type and my.search_type.startswith("@SOBJECT("):
            my.sobjects = Search.eval(my.search_type)
        elif my.search_keys:
            if isinstance(my.search_keys, basestring):
                my.search_keys = eval(my.search_keys)
            my.sobjects = Search.get_by_search_keys(my.search_keys)
        else:
            search = Search(my.search_type)
            search.add_limit(100)
            my.sobjects = search.get_sobjects()

        # get the definition
        sobjects = my.sobjects
        if sobjects:
            sobject = sobjects[0]
            search_type = sobject.get_search_type()
            view = 'definition'

            from pyasm.widget import WidgetConfigView
            my.config = WidgetConfigView.get_by_search_type(search_type, view)
        else:
            my.config = None


        my.widgets = {}
Esempio n. 50
0
            """
            view = "definition"
            from pyasm.search import SObjectDefaultConfig
            default = SObjectDefaultConfig(search_type=search_type,view=view)
            xml = default.get_xml()
            config = WidgetConfig.get(view=view, xml=xml)
            widget_config_list = [config]
            """
            try:
                # add the schema config definiiton
                schema_config = SearchType.get_schema_config(search_type)
                widget_config_list = [schema_config]
            except SqlException, e:
                widget_config_list = []
        if not config_view:
            config_view = WidgetConfigView(search_type, view,
                                           widget_config_list)
        return config_view

    get_config = classmethod(get_config)

    def add_link_behavior(my, link_wdg, element_name, config, options):
        '''this method provides the changed to add behaviors to a link'''

        # check security
        #default_access = "view"
        #security = Environment.get_security()
        #if not security.check_access("side_bar", element_name, "edit", default=default_access):
        #    return

        # avoid editing id and s_status
        if my.kwargs.get('view') == 'db_column' and element_name in [
Esempio n. 51
0
 def get_config(cls, config_search_type, view, default=False):
     # method to get the config view for this widget to display
     return WidgetConfigView.get_by_search_type(config_search_type, view)
Esempio n. 52
0
    def get_element_wdg(my, xml, def_config):

        element_node = xml.get_node("config/tmp/element")
        attrs = Xml.get_attributes(element_node)
        element_name = attrs.get("name")

        widget = my.get_widget(element_name)
        if widget:
            return widget


        if not element_name:
            import random
            num = random.randint(0, 100000)
            element_name = "element%s" % num
            xml.set_attribute(element_node, "name", element_name)


        # enable an ability to have a widget only loaded once in a request
        if attrs.get('load_once') in ['true', True]:
            widgets = Container.get("CustomLayoutWdg:widgets")
            if widgets == None:
                widgets = {}
                Container.put("CustomLayoutWdg:widgets", widgets)
            else:
                if widgets[element_name] == True:
                    return None

                widgets[element_name] = True


        # provide the ability to have shorthand format 
        # ie: <element display_class="tactic.ui..." />
        display_node = xml.get_node("config/tmp/element/display")
        if display_node is None:
            view = attrs.get("view")
            type = attrs.get("type")


            if type == "reference":
                search_type = attrs.get("search_type")
                my.config = WidgetConfigView.get_by_search_type(search_type, view)
                # check if definition has no name.  Don't use element_name
                if not attrs.get("name"):
                    return

                element_wdg = my.config.get_display_widget(element_name, extra_options=attrs)
                container = DivWdg()
                container.add(element_wdg)
                return container

            if not view:
                element_wdg = my.config.get_display_widget(element_name, extra_options=attrs)
                container = DivWdg()
                container.add(element_wdg)
                return container



            # look at the attributes
            class_name = attrs.get("display_class")
            if not class_name:
                class_name = "tactic.ui.panel.CustomLayoutWdg"
            display_node = xml.create_element("display")
            xml.set_attribute(display_node, "class", class_name)
            xml.append_child(element_node, display_node)

            for name, value in attrs.items():
                # replace the spt_ in the name.
                # NOTE: should this be restricted to only spt_ attributes?
                name = name.replace("spt_", "")
                attr_node = xml.create_element(name)
                xml.set_node_value(attr_node, value)
                xml.append_child(display_node, attr_node)


        load = attrs.get("load")
        if load in ["async", "sequence"]:
            return my.get_async_element_wdg(xml, element_name, load)




        use_container = attrs.get('use_container') == 'true'
        if use_container:
            # DEPRECATED
            container = my.get_container(xml)
        else:
            container = DivWdg()

        # add in attribute from the element definition
        # DEPRECATED: does this make any sense to have this here?
        for name, value in attrs.items():
            if name == 'name':
                continue
            container.add_style(name, value)






        # add the content
        try:
            view_node = xml.get_node("config/tmp/element/display/view")
            if view_node is not None:
                view = xml.get_node_value(view_node)
                if view.startswith("."):
                    if my.view_folder:
                        xml.set_node_value(view_node, "%s%s" %(my.view_folder,view))
            tmp_config = WidgetConfig.get('tmp', xml=xml)
            configs = []
            configs.append(tmp_config)

            # add the def_config if it exists
            if def_config:
                configs.append(def_config)

            config = WidgetConfigView('CustomLayoutWdg', 'tmp', configs, state=my.state)

            # NOTE: this doesn't work too well when we go to an abasolute
            # view.
            parent_view = my.kwargs.get("parent_view")
            if parent_view:
                parent_view = parent_view.replace(".", "/")
                parent_view = "%s/%s" % (parent_view, my.view)
            else:
                parent_view = my.view

            # NOTE: need some protection code for infinite loops


            includes = my.kwargs.get("include")
            element_wdg = config.get_display_widget(element_name, extra_options={"include":includes, "parent_view":parent_view})

            element_top = element_wdg.get_top()
            for name, value in attrs.items():
                if name == 'class':
                    for item in value.split(" "):
                        element_top.add_class(item)

                elif name == 'style':
                    for item in value.split(";"):
                        element_top.add_style(item)

                else:
                    element_top.set_attr(name, value)




            # make a provision if this custom widget is in a table
            if my.layout:
                sobject = my.get_current_sobject()
                element_wdg.set_sobject(sobject)



        except Exception, e:
            from pyasm.widget import ExceptionWdg
            log = ExceptionWdg(e)
            element_wdg = log
Esempio n. 53
0
    def get_filter_wdg(my):

        div = DivWdg()
        div.add_style("padding: 10px")
        div.add_style("margin: -10 -10 10 -10")
        div.add_style("min-width: 600px")
        div.add_class("spt_view_manager_filter")

        from tactic.ui.app import HelpButtonWdg

        help_wdg = HelpButtonWdg(alias="view-manager|what-are-views")
        div.add(help_wdg)
        help_wdg.add_style("float: right")

        div.add("<b>Search Type:</b> ")

        div.add_gradient("background", "background", -10)

        security = Environment.get_security()
        project = Project.get()
        if security.check_access("builtin", "view_site_admin", "allow"):
            search_type_objs = project.get_search_types(include_sthpw=True, include_config=True)
        else:
            search_type_objs = project.get_search_types()

        search_types = [x.get_value("search_type") for x in search_type_objs]
        titles = ["%s (%s)" % (x.get_value("search_type"), x.get_value("title")) for x in search_type_objs]

        select = SelectWdg(name="search_type")
        select.set_option("values", search_types)
        select.set_option("labels", titles)
        select.add_empty_option("-- Select --")
        select.set_persistence()
        # select.set_persist_on_submit()

        # security = Environment.get_security()
        # if security.check_access("builtin", "view_site_admin", "allow"):
        #    select_mode =  SearchTypeSelectWdg.ALL
        # else:
        #    select_mode =  SearchTypeSelectWdg.ALL_BUT_STHPW
        # select = SearchTypeSelectWdg(name='search_type', \
        #    mode=select_mode)

        behavior = {
            "type": "change",
            "cbjs_action": """
            var manager_top = bvr.src_el.getParent(".spt_view_manager_top");

            var input = spt.api.Utility.get_input(manager_top, 'search_type');
            var view_input = spt.api.Utility.get_input(manager_top, 'view');
            var view_input_value = '';
            if (view_input != null) {
                view_input_value = view_input.value;
            }
            var values = {'search_type': input.value, 'view': view_input_value, 'is_refresh': 'true'}; 
            spt.panel.refresh(manager_top, values);"""
            # //spt.panel.refresh(manager_top, values);'''
        }
        select.add_behavior(behavior)
        select.set_value(my.search_type)
        div.add(select)

        if not my.search_type:
            content = DivWdg()
            content.add_style("width: 400px")
            content.add_style("height: 400px")
            div.add(content)
            content.add_style("padding: 20px")
            content.add(IconWdg("WARNING", IconWdg.WARNING))
            content.add("No Search Type Selected")
            content.add_border()
            content.add_style("margin-top: 20px")
            content.add_color("background", "background")
            content.add_style("font-weight: bold")

            return div

        div.add("&nbsp;&nbsp;&nbsp;")
        div.add("<b>View: </b>")
        view_wdg = SelectWdg("view")
        view_wdg.set_value(my.view)
        view_wdg.add_empty_option("-- Select --")
        view_wdg.add_behavior(behavior)
        div.add(view_wdg)

        search = Search("config/widget_config")
        search.add_filter("search_type", my.search_type)
        db_configs = search.get_sobjects()

        views = set()
        for db_config in db_configs:
            view = db_config.get_value("view")
            if view.startswith("link_search:"):
                continue
            views.update([view])

        # print "search_type: ", my.search_type
        # print "view: ", views, my.view

        if my.search_type and my.view:
            config_view = WidgetConfigView.get_by_search_type(my.search_type, my.view)

            configs = config_view.get_configs()
            for x in configs:
                view = x.get_view()
                file_path = x.get_file_path()
                if view != my.view:
                    continue
                if file_path and file_path.endswith("DEFAULT-conf.xml"):
                    continue
                config_views = x.get_all_views()
                views.update(config_views)

        views_list = list(views)
        views_list.sort()
        view_wdg.set_option("values", views_list)

        return div
Esempio n. 54
0
    def init(my):
        '''initialize the widget_config, and from there retrieve the schema_config'''
        web = WebContainer.get_web()
        my.search_type = my.kwargs.get('search_type')

        element_name = my.kwargs.get('element_name')
        my.view = my.kwargs.get('view')

        # FIXME: comment out the assert for now to avoid error screen
        if not my.view:
            my.view = 'table'
        #assert my.view

        my.config_xml = my.kwargs.get('config_xml')
        if not my.config_xml:
            my.config_xml = web.get_form_value('config_xml')

        my.default = my.kwargs.get('default') == 'True'

        cbk = ManageSearchTypeDetailCbk(search_type=my.search_type, view=my.view, \
                element_name=element_name)
        Command.execute_cmd(cbk)

        my.config_string = ""
        my.data_type_string = ""
        my.name_string = ""
        my.title_string = ""
        my.nullable_string = ""
        my.has_column = True

        if element_name:
            if my.config_xml:
                my.config_string = my.config_xml
                whole_config_string = "<config><%s>%s</%s></config>" % (
                    my.view, my.config_xml, my.view)
                config = WidgetConfig.get(xml=whole_config_string,
                                          view=my.view)
                my.config = WidgetConfigView(my.search_type, my.view, [config])
            else:
                # don't pass in default here
                my.config = my.get_config(my.search_type, my.view)
                node = my.config.get_element_node(element_name)
                if node is not None:
                    config_xml = my.config.get_xml()

                    my.config_string = config_xml.to_string(node)
                    my.title_string = config_xml.get_attribute(node, 'title')
            schema_config = SearchType.get_schema_config(my.search_type)

            attributes = schema_config.get_element_attributes(element_name)
            my.data_type_string = attributes.get("data_type")

            # double_precision is float
            if my.data_type_string == 'double precision':
                my.data_type_string = 'float'

            my.name_string = attributes.get("name")
            my.nullable_string = attributes.get("nullable")
            my.is_new_column = attributes.get("new") == 'True'

            # a database columnless widget
            if not my.name_string:
                my.has_column = False
Esempio n. 55
0
    def get_element_wdg(my, xml, def_config):

        element_node = xml.get_node("config/tmp/element")
        attrs = Xml.get_attributes(element_node)
        element_name = attrs.get("name")

        widget = my.get_widget(element_name)
        if widget:
            return widget


        if not element_name:
            import random
            num = random.randint(0, 100000)
            element_name = "element%s" % num
            xml.set_attribute(element_node, "name", element_name)


        # enable an ability to have a widget only loaded once in a request
        if attrs.get('load_once') in ['true', True]:
            widgets = Container.get("CustomLayoutWdg:widgets")
            if widgets == None:
                widgets = {}
                Container.put("CustomLayoutWdg:widgets", widgets)
            else:
                if widgets[element_name] == True:
                    return None

                widgets[element_name] = True


        # provide the ability to have shorthand format 
        # ie: <element display_class="tactic.ui..." />
        display_node = xml.get_node("config/tmp/element/display")
        if display_node is None:
            view = attrs.get("view")
            type = attrs.get("type")

            if type == "reference":
                search_type = attrs.get("search_type")
                my.config = WidgetConfigView.get_by_search_type(search_type, view)
                # check if definition has no name.  Don't use element_name
                if not attrs.get("name"):
                    return

                element_wdg = my.config.get_display_widget(element_name, extra_options=attrs)
                container = DivWdg()
                container.add(element_wdg)
                return container


            class_name = attrs.get("display_class")

            # if no class name is defined and not view is defined look
            # at predefined elements
            if not view and not class_name:
                element_wdg = my.config.get_display_widget(element_name, extra_options=attrs)
                container = DivWdg()
                container.add(element_wdg)
                return container


            # look at the attributes
            if not class_name:
                class_name = "tactic.ui.panel.CustomLayoutWdg"
            display_node = xml.create_element("display")
            xml.set_attribute(display_node, "class", class_name)
            xml.append_child(element_node, display_node)

            for name, value in attrs.items():
                # replace the spt_ in the name.
                # NOTE: should this be restricted to only spt_ attributes?
                name = name.replace("spt_", "")
                attr_node = xml.create_element(name)
                xml.set_node_value(attr_node, value)
                xml.append_child(display_node, attr_node)


        load = attrs.get("load")
        if load in ["async", "sequence"]:
            return my.get_async_element_wdg(xml, element_name, load)




        use_container = attrs.get('use_container') == 'true'
        if use_container:
            # DEPRECATED
            container = my.get_container(xml)
        else:
            container = DivWdg()

        # add in attribute from the element definition
        # DEPRECATED: does this make any sense to have this here?
        for name, value in attrs.items():
            if name == 'name':
                continue
            container.add_style(name, value)






        # add the content
        try:
            view_node = xml.get_node("config/tmp/element/display/view")
            if view_node is not None:
                view = xml.get_node_value(view_node)
                if view.startswith("."):
                    if my.view_folder:
                        xml.set_node_value(view_node, "%s%s" %(my.view_folder,view))
            tmp_config = WidgetConfig.get('tmp', xml=xml)
            configs = []
            configs.append(tmp_config)

            # add the def_config if it exists
            if def_config:
                configs.append(def_config)

            config = WidgetConfigView('CustomLayoutWdg', 'tmp', configs, state=my.state)

            # NOTE: this doesn't work too well when we go to an abasolute
            # view.
            parent_view = my.kwargs.get("parent_view")
            if parent_view:
                parent_view = parent_view.replace(".", "/")
                parent_view = "%s/%s" % (parent_view, my.view)
            else:
                parent_view = my.view

            # NOTE: need some protection code for infinite loops


            includes = my.kwargs.get("include")
            element_wdg = config.get_display_widget(element_name, extra_options={"include":includes, "parent_view":parent_view})

            element_top = element_wdg.get_top()
            for name, value in attrs.items():
                if name == 'class':
                    for item in value.split(" "):
                        element_top.add_class(item)

                elif name == 'style':
                    for item in re.split(";\ ?", value):
                        element_top.add_style(item)

                else:
                    element_top.set_attr(name, value)




            # make a provision if this custom widget is in a table
            if my.layout:
                sobject = my.get_current_sobject()
                element_wdg.set_sobject(sobject)



        except Exception, e:
            from pyasm.widget import ExceptionWdg
            log = ExceptionWdg(e)
            element_wdg = log
Esempio n. 56
0
    def get_config(cls, config_search_type, view,  default=False, personal=False):
        config = WidgetConfigView.get_by_search_type(config_search_type, view)

        return config
Esempio n. 57
0
    def execute(my):
        assert my.search_type
        assert my.view
        assert my.file_path

        search = Search(my.search_type)
        if my.search_ids:
            search.add_enum_order_by("id", my.search_ids)
            search.add_filters("id", my.search_ids)
            sobjects = search.get_sobjects()
        elif my.search_keys:

            sobjects = Search.get_by_search_keys(my.search_keys,
                                                 keep_order=True)
            """
            search_codes = [SearchKey.extract_code(i) for i in my.search_keys if SearchKey.extract_code(i) ]
            if search_codes:
                search.add_filters("code", search_codes)
            else:
                search_ids = [SearchKey.extract_id(i) for i in my.search_keys if SearchKey.extract_id(i) ]
                search.add_filters("id", search_ids)
            """
        else:
            sobjects = search.get_sobjects()

        from pyasm.widget import WidgetConfigView
        from pyasm.web import Widget
        config = WidgetConfigView.get_by_search_type(my.search_type, my.view)

        columns = []
        if my.column_names:
            columns = my.column_names
        # should allow exporting ids only
        """
        else:
            if not config:
                columns = search.get_columns()
            else:
                columns = config.get_element_names()
        """
        if my.include_id:
            columns.insert(0, "id")

        # create the csv file
        org_file = file(my.file_path, 'w')
        csvwriter = csv.writer(org_file, quoting=csv.QUOTE_NONNUMERIC)

        # write the titles
        csvwriter.writerow(columns)

        elements = my.get_elements(config, columns)
        display_option_dict = {}
        # this is for widgets that do preprocessing on all sobjects
        for idx, element in enumerate(elements):
            element.set_sobjects(sobjects)
            element.preprocess()
            display_options = config.get_display_options(columns[idx])
            display_option_dict[element] = display_options

        for idx, sobject in enumerate(sobjects):
            values = []

            for element in elements:

                element.set_current_index(idx)
                value = element.get_text_value()
                if isinstance(value, Widget):
                    value = value.get_buffer_display()
                elif isinstance(value, basestring):
                    if isinstance(value, unicode):
                        value = value.encode('UTF-8', 'ignore')
                else:
                    value = str(value)

                options = display_option_dict.get(element)
                if options.get('csv_force_string') == 'true' and value:
                    value = '#FORCESTRING#%s' % value
                values.append(value)
            # write the values as list
            csvwriter.writerow(values)

        org_file.close()

        file2 = open(my.file_path, 'r')
        mod_file_path = '%s_mod' % my.file_path
        mod_file = open(mod_file_path, 'w')
        for line in file2:
            mod_line = re.sub(r'(\'|\"|)(#FORCESTRING#)', '=\\1', line)
            mod_file.write(mod_line)

        # new file
        file2.close()
        mod_file.close()

        #os.unlink(my.file_path)
        shutil.move(mod_file_path, my.file_path)
Esempio n. 58
0
    def preprocess(my):
        my.max_value = 0
        my.min_value = 0
        my.steps = 0

        web = WebContainer.get_web()
        my.width = web.get_form_value("width")
        if not my.width:
            my.width = my.kwargs.get("width")

        my.chart_type = web.get_form_value("chart_type")
        if not my.chart_type:
            my.chart_type = my.kwargs.get("chart_type")
        if not my.chart_type:
            my.chart_type = 'bar'

        my.x_axis = web.get_form_value("x_axis")
        if not my.x_axis:
            my.x_axis = my.kwargs.get("x_axis")
        if not my.x_axis:
            my.x_axis = 'code'

        # FIXME: which should override???
        my.y_axis = web.get_form_values("y_axis")
        if not my.y_axis:
            my.y_axis = my.kwargs.get("y_axis")

        if my.y_axis:
            my.elements = my.y_axis
        else:
            my.elements = my.kwargs.get("elements")
            if not my.elements:
                my.elements = web.get_form_value("elements")

        if isinstance(my.elements, basestring):
            if my.elements:
                my.elements = my.elements.split('|')
            else:
                my.elements = []

        my.search_type = web.get_form_value("search_type")
        if not my.search_type:
            my.search_type = my.kwargs.get("search_type")

        my.search_keys = my.kwargs.get("search_keys")
        if my.search_type and my.search_type.startswith("@SOBJECT("):
            my.sobjects = Search.eval(my.search_type)
        elif my.search_keys:
            if isinstance(my.search_keys, basestring):
                my.search_keys = eval(my.search_keys)
            my.sobjects = Search.get_by_search_keys(my.search_keys)
        else:
            search = Search(my.search_type)
            search.add_limit(100)
            my.sobjects = search.get_sobjects()

        # get the definition
        sobjects = my.sobjects
        if sobjects:
            sobject = sobjects[0]
            search_type = sobject.get_search_type()
            view = 'definition'

            from pyasm.widget import WidgetConfigView
            my.config = WidgetConfigView.get_by_search_type(search_type, view)
        else:
            my.config = None

        my.widgets = {}
Esempio n. 59
0
    def get_item_wdg(self, sobject):

        self.element_names = self.kwargs.get("element_names")
        if not self.element_names:
            self.element_names = ["preview","code","name","description",]
        else:
            self.element_names = self.element_names.split(",")

        if self.element_names[0] == "preview":
            has_preview = True
            self.element_names = self.element_names[1:]
        else:
            has_preview = False

        view = self.kwargs.get("view")
        if not view:
            view = "table"
        from pyasm.widget import WidgetConfigView
        search_type = sobject.get_search_type()
        self.config = WidgetConfigView.get_by_search_type(search_type, view)



        div = DivWdg()
        div.add_class("spt_item_top")
        div.add_style("padding: 10px")
        SmartMenu.assign_as_local_activator( div, 'DG_DROW_SMENU_CTX' )
        #div.add_class("spt_table_row")
        #div.add_class("spt_table_row_%s" % self.table_id)
        div.add_attr("spt_search_key", sobject.get_search_key(use_id=True))
        div.add_attr("spt_search_code", sobject.get_code())
        name = sobject.get_value("name", no_exception=True)
        if not name:
            name = sobject.get_code()
        div.add_attr("spt_name", name)

        table = Table()

        div.add(table)
        table.set_max_width()
        tr = table.add_row()

        width = self.kwargs.get("preview_width")
        if not width:
            width = "240px"

        if has_preview:
            td = table.add_cell()
            td.add_style("width: %s" % width);
            td.add_style("vertical-align: top")

            options = self.config.get_display_options("preview")
            redirect_expr = options.get("redirect_expr")
            if redirect_expr:
                parent = Search.eval(redirect_expr, sobject, single=True)
                #parent = sobject.get_parent()
                tile_wdg = self.tile_layout.get_tile_wdg(parent)
            else:
                tile_wdg = self.tile_layout.get_tile_wdg(sobject)

            td.add(tile_wdg)

        info_div = self.get_info_wdg(sobject)
        td = table.add_cell(info_div)
        td.add_style("vertical-align: top")


        return div
Esempio n. 60
0
    def get_config(cls, search_type, view, default=None, personal=False):
        # personal doesn't mean much here since this is only for Project view definition
        """
        if view == "__column__":
            xml == '''
            <config>
                <element name="tttt" type="__database__"/>
                <element name="uuuu" type="__database__"/>
                <element name="vvvv" type="__database__"/>
            </config>
            '''
        """
        widget_config = None
        config_view = None
        widget_config_list = []


        # get all the configs relevant to this search_type
        configs = []
       
        from pyasm.widget import WidgetConfigView
        if view == "definition":
            if default:
                try:
                    default_config_view = WidgetConfigView.get_by_search_type(search_type, view, use_cache=False, local_search=True)

                    user_config_view = WidgetConfigView.get_by_search_type(search_type, view)
                  
                    #merge the user config view from db into the default config view in xml file
                    default_config = default_config_view.get_definition_config()
                    user_config = user_config_view.get_definition_config()
                    if user_config:
                        user_element_names = user_config.get_element_names()
                        # make sure it's unique, there is a new validate function for
                        # WidgetDbConfig to ensure that also
                        user_element_names = Common.get_unique_list(user_element_names)
                        for elem in user_element_names:
                            user_node = user_config.get_element_node(elem)
                            default_config.append_xml_element(elem, node=user_node)
                except SqlException as e:
                     print "Search ERROR: ", e.__str__()
                     default_config = None
                
                if default_config:
                    default_config.get_xml().clear_xpath_cache()
                    widget_config_list = [default_config]

            else:
                config_view = WidgetConfigView.get_by_search_type(search_type, view, use_cache=True)

        elif view == "database_definition":
            schema_config = SearchType.get_schema_config(search_type)
            widget_config_list = [schema_config]
        elif view == 'template':
            base_dir = Environment.get_install_dir()
            file_path="%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir
            if os.path.exists(file_path):
                widget_config = WidgetConfig.get(file_path=file_path, view=view)
                widget_config_list = [widget_config]
            '''
            elif default == True :
                base_dir = Environment.get_install_dir()
                file_path="%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir
                if os.path.exists(file_path):
                    widget_config = WidgetConfig.get(file_path=file_path, view="default_definition")
                    widget_config_list = [widget_config]
            '''
        elif view == "custom_definition":
            # look for a definition in the database
            search = Search("config/widget_config")
            search.add_filter("search_type", 'SearchTypeSchema')
            search.add_filter("view", view)
            config = search.get_sobject()
            # this is really just a custom made definition
            #view = "definition"
            
            if config:
                widget_config_list = [config]
            else:
                widget_config_list = []

        elif view == "db_column":
            # look for a definition in the database
            """
            view = "definition"
            from pyasm.search import SObjectDefaultConfig
            default = SObjectDefaultConfig(search_type=search_type,view=view)
            xml = default.get_xml()
            config = WidgetConfig.get(view=view, xml=xml)
            widget_config_list = [config]
            """
            try:   
                # add the schema config definiiton
                schema_config = SearchType.get_schema_config(search_type)
                widget_config_list = [schema_config]
            except SqlException as e:
                widget_config_list = []
        if not config_view:
            config_view = WidgetConfigView(search_type, view, widget_config_list)
        return config_view