Ejemplo n.º 1
0
    def execute(my):
        sobject = my.sobject

        name = my.get_name()

        web = WebContainer.get_web()

        naming = web.get_form_value(name)

        if not naming:
            return

        naming_util = NamingUtil()
        template = naming_util.build_naming2(naming)

        naming = naming.strip("/")
        parts = re.split("[\\/._]", naming)

        # make some adjustments based on selections
        for idx, part in enumerate(parts):

            type_value = web.get_form_value("type_%s" % idx)

            if type_value:
                template = template.replace("{%d}" % idx, "{%s}" % type_value)
            else:
                template = template.replace("{%d}" % idx, part)

        sobject.set_value(name, template)
Ejemplo n.º 2
0
    def execute(self):
        sobject = self.sobject

        name = self.get_name()

        web = WebContainer.get_web()

        naming = web.get_form_value(name)

        if not naming:
            return

        naming_util = NamingUtil()
        template = naming_util.build_naming2(naming)

        naming = naming.strip("/")
        parts = re.split('[\\/._]', naming)

        # make some adjustments based on selections
        for idx, part in enumerate(parts):

            type_value = web.get_form_value("type_%s" % idx)

            if type_value:
                template = template.replace("{%d}" % idx, "{%s}" % type_value)
            else:
                template = template.replace("{%d}" % idx, part)

        sobject.set_value(name, template)
Ejemplo n.º 3
0
    def _get_result(self, sobject):

        # get the parent or relation
        column = self.get_column()
        parent_id = sobject.get_value(column)
        parent = self.parents_dict.get(parent_id)
        if not parent:
            return super(ForeignKeyElementWdg,self).get_display()


        template = self.get_option('template')
        # if not set, then look at the schema
        if not template:
            schema = Schema.get_by_project_code( Project.get_project_code() )
            search_type = parent.get_base_search_type()
            template = schema.get_attr_by_search_type(search_type,'display_template')

        if template:
            value = NamingUtil.eval_template(template, sobject, parent=parent)
        else:
            # NOTE: put something ... anything as a default
            columns = parent.get_search_type_obj().get_columns()
            if not len(columns):
                value = parent.get_value(columns[0])
            else:
                value = parent.get_value(columns[1])

        return value
Ejemplo n.º 4
0
    def _get_result(my, sobject):

        # get the parent or relation
        column = my.get_column()
        parent_id = sobject.get_value(column)
        parent = my.parents_dict.get(parent_id)
        if not parent:
            return super(ForeignKeyElementWdg,my).get_display()


        template = my.get_option('template')
        # if not set, then look at the schema
        if not template:
            schema = Schema.get_by_project_code( Project.get_project_code() )
            search_type = parent.get_base_search_type()
            template = schema.get_attr_by_search_type(search_type,'display_template')

        if template:
            value = NamingUtil.eval_template(template, sobject, parent=parent)
        else:
            # NOTE: put something ... anything as a default
            columns = parent.get_search_type_obj().get_columns()
            if not len(columns):
                value = parent.get_value(columns[0])
            else:
                value = parent.get_value(columns[1])

        return value
Ejemplo n.º 5
0
    def get_display(my):
        sobject = my.get_current_sobject()
        template = my.get_option("template")
        if not template:
            return super(SimpleTableElementWdg, my).__init__()

        display = NamingUtil.eval_template(template, sobject)
        my.value = display
        return display
Ejemplo n.º 6
0
    def get_display(my):
        sobject = my.get_current_sobject()
        template = my.get_option("template")
        if not template:
            return super(SimpleTableElementWdg, my).__init__()

        display = NamingUtil.eval_template(template, sobject)
        my.value = display
        return display
Ejemplo n.º 7
0
    def get_display(my):

        web = WebContainer.get_web()
        naming_util = NamingUtil()

        if not my.widget_name:
            my.widget_name = my.get_name()

        # get the sobject required by this input
        sobject = my.get_current_sobject()
        if not sobject:
            sobject = Search.get_by_id(my.search_type, my.search_id)

        if my.new_sample_name:
            my.new_sample_name.replace("//", "/")
        else:
            my.new_sample_name = sobject.get_value(my.widget_name)

        widget = DivWdg()
        widget.set_id("naming")
        widget.add_style("display: block")

        # set the sample text
        div = DivWdg()
        div.add("Sample name: <i>%s</i>" % my.new_sample_name)
        div.add(HtmlElement.br(2))

        new_sample_wdg = ProdIconButtonWdg("Set New Sample")
        new_sample_wdg.add_event("onclick", "toggle_display('generate')")
        div.add(new_sample_wdg)

        generate = DivWdg()
        generate.add(HtmlElement.br())
        generate.set_id("generate")
        generate.add_style("display: none")
        sample_text = TextWdg("new_sample_name")
        sample_text.set_option("size", "30")
        # sample_text.set_persist_on_submit()
        # if my.new_sample_name:
        #    sample_text.set_value(my.new_sample_name)
        generate.add(sample_text)

        button = IconButtonWdg("Generate", IconWdg.REFRESH, long=True)
        on_script = my.setup_ajax("naming")
        button.add_event("onclick", on_script)
        generate.add(button)
        generate.add(HtmlElement.br(2))

        div.add(generate)
        widget.add(div)

        hidden = TextWdg(my.widget_name)
        value = my.naming
        hidden.set_value(my.new_sample_name)
        widget.add(my.widget_name)
        widget.add(hidden)

        # get all of the parts

        # TODO: not sure if this should be dictated by the sample name
        # break up the name into parts
        import re

        if my.new_sample_name:
            tmp = my.new_sample_name.strip("/")
            parts = re.split("[\\/._]", tmp)
            print "parts: ", parts
        else:
            return widget

        # if there is a naming, then populate that
        if my.edit_search_type:
            options = naming_util.get_options(my.edit_search_type)
        else:
            options = naming_util.get_options(sobject.get_value("search_type"))

        table = Table()
        type_values = []
        padding_values = []
        for idx, part in enumerate(parts):
            table.add_row()
            table.add_cell(part)

            type_select = SelectWdg("type_%s" % idx)
            type_select.add_empty_option("-- Explicit --")
            type_select.set_persist_on_submit()
            type_select.set_option("values", "|".join(options))
            type_values.append(type_select.get_value())
            td = table.add_cell(type_select)

        widget.add(table)

        return widget
Ejemplo n.º 8
0
    def get_display(self):

        web = WebContainer.get_web()
        naming_util = NamingUtil()

        if not self.widget_name:
            self.widget_name = self.get_name()

        # get the sobject required by this input
        sobject = self.get_current_sobject()
        if not sobject:
            sobject = Search.get_by_id(self.search_type, self.search_id)

        if self.new_sample_name:
            self.new_sample_name.replace("//", "/")
        else:
            self.new_sample_name = sobject.get_value(self.widget_name)

        widget = DivWdg()
        widget.set_id("naming")
        widget.add_style("display: block")

        # set the sample text
        div = DivWdg()
        div.add("Sample name: <i>%s</i>" % self.new_sample_name)
        div.add(HtmlElement.br(2))

        new_sample_wdg = ProdIconButtonWdg("Set New Sample")
        new_sample_wdg.add_event("onclick", "toggle_display('generate')")
        div.add(new_sample_wdg)

        generate = DivWdg()
        generate.add(HtmlElement.br())
        generate.set_id("generate")
        generate.add_style("display: none")
        sample_text = TextWdg("new_sample_name")
        sample_text.set_option("size", "30")
        #sample_text.set_persist_on_submit()
        #if self.new_sample_name:
        #    sample_text.set_value(self.new_sample_name)
        generate.add(sample_text)

        button = IconButtonWdg("Generate", IconWdg.REFRESH, long=True)
        on_script = self.setup_ajax("naming")
        button.add_event("onclick", on_script)
        generate.add(button)
        generate.add(HtmlElement.br(2))

        div.add(generate)
        widget.add(div)

        hidden = TextWdg(self.widget_name)
        value = self.naming
        hidden.set_value(self.new_sample_name)
        widget.add(self.widget_name)
        widget.add(hidden)

        # get all of the parts

        # TODO: not sure if this should be dictated by the sample name
        # break up the name into parts
        import re
        if self.new_sample_name:
            tmp = self.new_sample_name.strip("/")
            parts = re.split('[\\/._]', tmp)
            print "parts: ", parts
        else:
            return widget

        # if there is a naming, then populate that
        if self.edit_search_type:
            options = naming_util.get_options(self.edit_search_type)
        else:
            options = naming_util.get_options(sobject.get_value("search_type"))

        table = Table()
        type_values = []
        padding_values = []
        for idx, part in enumerate(parts):
            table.add_row()
            table.add_cell(part)

            type_select = SelectWdg("type_%s" % idx)
            type_select.add_empty_option("-- Explicit --")
            type_select.set_persist_on_submit()
            type_select.set_option("values", "|".join(options))
            type_values.append(type_select.get_value())
            td = table.add_cell(type_select)

        widget.add(table)

        return widget