示例#1
0
    def get_display(my):
        if not my.is_preprocess:
            my.preprocess()

        widget = DivWdg()
        widget.add_class('spt_input_top')

        # add a callback to determine the input key
        widget.add_attr('spt_cbjs_get_input_key', "return spt.dg_table.get_status_key(cell_to_edit, edit_cell)")

        # add a data structure mapping, processes to task pipelines
        #data = {
        #    "model": "task_model",
        #    "texture": "task_texture",
        #    "rig":  "task_rig"
        #}
       
        if my.task_mapping:
            json_str = HtmlElement.get_json_string(my.task_mapping)
            widget.add_attr('spt_task_pipeline_mapping', json_str)

        for pipeline in my.task_pipelines:
            div = DivWdg()
            widget.add(div)
            div.add_class("spt_input_option")

            div.add_attr("spt_input_key", pipeline.get_code())
         
            # if there is not task_pipeline_code, create a virtual one:
            if not pipeline:
                process_names = ['Pending', 'In Progress', 'Approved']
            else:
                process_names = pipeline.get_process_names()


            allowed_processes = []
            security = Environment.get_security()
            cur_value = ''
            cur_sobject = my.get_current_sobject()
            if cur_sobject:
                cur_value = cur_sobject.get_value('status')

            for process in process_names:
                # not all statuses can be shown, if there are access rules
                # TODO: remove this process_select in 4.1
                if cur_value == process or security.check_access("process_select", process, access='view', default='deny'):
                    allowed_processes.append(process)
                    continue

                # use the new access rule process here
                access_key = [
                    {'process': '*' ,'pipeline':  pipeline.get_code()},
                    {'process': '*' ,'pipeline':  '*'},
                    {'process': process , 'pipeline':  pipeline.get_code()}
                    ]


                if security.check_access('process', access_key, "view", default="deny"):
                    allowed_processes.append(process)
                

            select = SelectWdg(my.get_input_name())
            select.add_empty_option('-- Select --')
            if cur_value in allowed_processes:
                select.set_value( cur_value )
            select.set_option("values", allowed_processes)
            # only old table layout has behaviors at the widget level
            if my.behaviors:
                from tactic.ui.panel import CellEditWdg
                CellEditWdg.add_edit_behavior(select)

            div.add(select.get_buffer_display())
        
        return widget
示例#2
0
    def get_first_row_wdg(self):

        # read the csv file
        self.file_path = ""

        div = DivWdg()

        div.add(self.get_upload_wdg())

        if not self.search_type:
            return div

        if not self.file_path:
            return div

        if not self.file_path.endswith(".csv"):
            div.add("Uploaded file [%s] is not a csv file" % self.file_path)
            return div

        if not os.path.exists(self.file_path):
            raise Exception("Path '%s' does not exists" % self.file_path)

        div.add(HtmlElement.br(2))

        div.add(
            HtmlElement.
            b("The following is taken from first line in the uploaded csv file.  Select the appropriate column to match."
              ))
        div.add(HtmlElement.br())
        div.add(
            HtmlElement.b(
                "Make sure you have all the required columns** in the csv."))
        option_div = DivWdg()

        option_div.add_style("float: left")
        option_div.add_style("margin-right: 30px")

        option_div.add("<p>3. Parsing Options:</p>")

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

        # first row and second row
        option_div.add(HtmlElement.br(2))
        option_div.add("Use Title Row: ")
        title_row_checkbox = FilterCheckboxWdg("has_title")
        title_row_checkbox.set_default_checked()
        option_div.add(title_row_checkbox)
        option_div.add(
            HintWdg(
                "Set this to use the first row as a title row to match up columns in the database"
            ))

        option_div.add(HtmlElement.br(2))
        option_div.add("Sample Data Row: ")
        data_row_text = TextWdg("data_row")
        data_row_text.set_attr("size", "3")
        option_div.add(data_row_text)
        option_div.add(
            HintWdg(
                "Set this as a sample data row to match the columns to the database"
            ))

        option_div.add(HtmlElement.br(2))

        div.add(option_div)
        self.has_title = title_row_checkbox.is_checked()

        # parse the first fow
        csv_parser = CsvParser(self.file_path)
        if self.has_title:
            csv_parser.set_has_title_row(True)
        else:
            csv_parser.set_has_title_row(False)
        csv_parser.parse()
        csv_titles = csv_parser.get_titles()
        csv_data = csv_parser.get_data()

        data_row = data_row_text.get_value()
        if not data_row:
            data_row = 0
        else:
            try:
                data_row = int(data_row)
            except ValueError:
                data_row = 0

            if data_row >= len(csv_data):
                data_row = len(csv_data) - 1
        data_row_text.set_value(data_row)

        table = Table()
        table.set_attr("cellpadding", "10")

        table.add_row()
        table.add_header("CSV Column Value")
        table.add_header("TACTIC Column")
        table.add_header("Create New Column")

        columns = self.search_type_obj.get_columns()
        search_type = self.search_type_obj.get_base_search_type()
        sobj = SObjectFactory.create(search_type)
        required_columns = sobj.get_required_columns()

        row = csv_data[data_row]
        labels = []
        for column in columns:
            if column in required_columns:
                label = '%s**' % column
            else:
                label = column
            labels.append(label)

        for j, cell in enumerate(row):
            table.add_row()
            table.add_cell(cell)

            column_select = SelectWdg("column_%s" % j)
            column_select.add_event(
                "onchange",
                "if (this.value!='') {set_display_off('new_column_div_%s')} else {set_display_on('new_column_div_%s')}"
                % (j, j))

            column_select.add_empty_option("-- Select --")
            column_select.set_option("values", columns)
            column_select.set_option("labels", labels)

            # only set the value if it is actually in there
            if csv_titles[j] in columns:
                column_select.set_option("default", csv_titles[j])
            column_select.set_persist_on_submit()
            column_select_value = column_select.get_value()

            display = column_select.get_buffer_display()
            td = table.add_cell(display)

            if csv_titles[j] not in columns:
                td.add(" <b style='color: red'>*</b>")

                # new property
                new_column_div = DivWdg()

                if column_select_value:
                    new_column_div.add_style("display", "none")
                else:
                    new_column_div.add_style("display", "block")

                new_column_div.set_id("new_column_div_%s" % j)

                td = table.add_cell(new_column_div)
                text = TextWdg("new_column_%s" % j)
                text.set_persist_on_submit()

                if self.has_title:
                    text.set_value(csv_titles[j])

                new_column_div.add(" ... or ...")
                new_column_div.add(text)

        self.num_columns = len(row)
        hidden = HiddenWdg("num_columns", self.num_columns)

        # need to somehow specify defaults for columns

        div.add(table)

        div.add("<br/><br/>")

        div.add(self.get_preview_wdg())

        return div
示例#3
0
    def get_display(my):
        if not my.is_preprocess:
            my.preprocess()

        widget = DivWdg()
        widget.add_class('spt_input_top')

        # add a callback to determine the input key
        widget.add_attr(
            'spt_cbjs_get_input_key',
            "return spt.dg_table.get_status_key(cell_to_edit, edit_cell)")

        # add a data structure mapping, processes to task pipelines
        #data = {
        #    "model": "task_model",
        #    "texture": "task_texture",
        #    "rig":  "task_rig"
        #}

        if my.task_mapping:
            json_str = HtmlElement.get_json_string(my.task_mapping)
            widget.add_attr('spt_task_pipeline_mapping', json_str)

        for pipeline in my.task_pipelines:
            div = DivWdg()
            widget.add(div)
            div.add_class("spt_input_option")

            div.add_attr("spt_input_key", pipeline.get_code())

            # if there is not task_pipeline_code, create a virtual one:
            if not pipeline:
                status_names = ['Pending', 'In Progress', 'Complete']
            else:
                status_names = pipeline.get_process_names()

            allowed_statuses = []
            security = Environment.get_security()
            cur_value = ''
            cur_sobject = my.get_current_sobject()
            if cur_sobject:
                cur_value = cur_sobject.get_value('status')

            processes = ['Synopsis', 'First Draft', 'Second Draft', 'Final']
            processes = [None]
            for process in processes:

                for status in status_names:
                    # not all statuses can be shown, if there are access rules
                    # TODO: remove this status in 4.1
                    if cur_value == status or security.check_access(
                            "process_select",
                            status,
                            access='view',
                            default='deny'):

                        if process:
                            allowed_statuses.append("%s / %s" %
                                                    (process, status))
                        else:
                            allowed_statuses.append(status)
                        continue

                    # use the new access rule process here
                    access_key = [{
                        'process': '*',
                        'pipeline': pipeline.get_code()
                    }, {
                        'process': '*',
                        'pipeline': '*'
                    }, {
                        'process': status,
                        'pipeline': pipeline.get_code()
                    }]

                    if security.check_access('status',
                                             access_key,
                                             "view",
                                             default="deny"):
                        if process:
                            allowed_statuses.append("%s / %s" %
                                                    (process, status))
                        else:
                            allowed_statuses.append(status)

                if process:
                    allowed_statuses.append("---")

            select = SelectWdg(my.get_input_name())
            select.add_empty_option('-- Select --')
            if cur_value in allowed_statuses:
                select.set_value(cur_value)
            select.set_option("values", allowed_statuses)
            # only old table layout has behaviors at the widget level
            if my.behaviors:
                from tactic.ui.panel import CellEditWdg
                CellEditWdg.add_edit_behavior(select)

            div.add(select.get_buffer_display())

        return widget
示例#4
0
    def get_first_row_wdg(my):

        # read the csv file
        my.file_path = ""

        div = DivWdg()

        div.add( my.get_upload_wdg() )

        if not my.search_type:
            return div

        if not my.file_path:
            return div


        if not my.file_path.endswith(".csv"):
            div.add( "Uploaded file [%s] is not a csv file"% my.file_path)
            return div

        if not os.path.exists(my.file_path):
            raise Exception("Path '%s' does not exists" % my.file_path)

        div.add(HtmlElement.br(2))

        div.add( HtmlElement.b("The following is taken from first line in the uploaded csv file.  Select the appropriate column to match.") )
        div.add(HtmlElement.br())
        div.add(  HtmlElement.b("Make sure you have all the required columns** in the csv."))
        option_div = DivWdg()
        
        option_div.add_style("float: left")
        option_div.add_style("margin-right: 30px")

        option_div.add("<p>3. Parsing Options:</p>")

        my.search_type_obj = SearchType.get(my.search_type)


        # first row and second row
        option_div.add( HtmlElement.br(2) )
        option_div.add("Use Title Row: ")
        title_row_checkbox = FilterCheckboxWdg("has_title")
        title_row_checkbox.set_default_checked()
        option_div.add(title_row_checkbox)
        option_div.add( HintWdg("Set this to use the first row as a title row to match up columns in the database") )
        
        option_div.add( HtmlElement.br(2) )
        option_div.add("Sample Data Row: ")
        data_row_text = TextWdg("data_row")
        data_row_text.set_attr("size", "3")
        option_div.add(data_row_text)
        option_div.add( HintWdg("Set this as a sample data row to match the columns to the database") )

        option_div.add( HtmlElement.br(2) )
        
       
        div.add(option_div)
        my.has_title = title_row_checkbox.is_checked()
        
        
        # parse the first fow
        csv_parser = CsvParser(my.file_path)
        if my.has_title:
            csv_parser.set_has_title_row(True)
        else:
            csv_parser.set_has_title_row(False)
        csv_parser.parse()
        csv_titles = csv_parser.get_titles()
        csv_data = csv_parser.get_data()



        data_row = data_row_text.get_value()
        if not data_row:
            data_row = 0
        else:
            try:
                data_row = int(data_row)
            except ValueError:
                data_row = 0

            if data_row >= len(csv_data):
                data_row = len(csv_data)-1
        data_row_text.set_value(data_row)




        table = Table()
        table.set_attr("cellpadding", "10")

        table.add_row()
        table.add_header("CSV Column Value")
        table.add_header("TACTIC Column")
        table.add_header("Create New Column")
        
        columns = my.search_type_obj.get_columns()
        search_type = my.search_type_obj.get_base_search_type()
        sobj = SObjectFactory.create(search_type)
        required_columns = sobj.get_required_columns()
        
        row = csv_data[data_row]
        labels = []
        for column in columns:
            if column in required_columns:
                label = '%s**'%column
            else:
                label = column
            labels.append(label)

        for j, cell in enumerate(row):
            table.add_row()
            table.add_cell(cell)

            column_select = SelectWdg("column_%s" % j)
            column_select.add_event("onchange", "if (this.value!='') {set_display_off('new_column_div_%s')} else {set_display_on('new_column_div_%s')}" % (j,j))

            column_select.add_empty_option("-- Select --")
            column_select.set_option("values", columns)
            column_select.set_option("labels", labels)

            # only set the value if it is actually in there
            if csv_titles[j] in columns:
                column_select.set_option("default", csv_titles[j])
            column_select.set_persist_on_submit()
            column_select_value = column_select.get_value()


            display = column_select.get_buffer_display()
            td = table.add_cell( display )

            if csv_titles[j] not in columns:
                td.add(" <b style='color: red'>*</b>")

                # new property
                new_column_div = DivWdg()

                if column_select_value:
                    new_column_div.add_style("display", "none")
                else:
                    new_column_div.add_style("display", "block")

                new_column_div.set_id("new_column_div_%s" % j)

                td = table.add_cell( new_column_div )
                text = TextWdg("new_column_%s" % j)
                text.set_persist_on_submit()

                if my.has_title:
                    text.set_value(csv_titles[j])


                new_column_div.add( " ... or ..." )
                new_column_div.add( text )


        my.num_columns = len(row)
        hidden = HiddenWdg("num_columns", my.num_columns)


        # need to somehow specify defaults for columns


        div.add(table)

        div.add("<br/><br/>")


        div.add(my.get_preview_wdg())


        return div