コード例 #1
0
    def set_filter_data(search_type, view=None):
        '''set filter data based on some saved search values in wdg_settings'''

        # NOTE - This is MMS specific and is deprecated and will be deleted
        # DISABLING FOR Job and Request until job_detail stops stack tracing
        # This is due to mixing of searches between job and request in the
        # job detail.  Cannot find the issue.
        # 1) FilterData is global: should be scoped by search type
        # 2) After introduction of scroll bars, it started stack tracing
        # It looks like the state is not being properly passed through

        # temp fix to avoid cross contamination of filter data for Planners UI
        if search_type in ['MMS/job', 'MMS/request'] or view == '_planner':
            return

        filter_data = FilterData.get()
        if not filter_data.get_data():
            # use widget settings
            key = SearchWdg._get_key(search_type, view)
            data = WidgetSettings.get_value_by_key(key)
            if data:

                try:
                    filter_data = FilterData(data)
                    filter_data.set_to_cgi()
                except SetupException, e:
                    print "This filter data is causing error:", data
                    print e
コード例 #2
0
ファイル: search_wdg.py プロジェクト: zieglerm/TACTIC
    def alter_search(self, search=None):

        if not search:
            search = self.search
            if self.limit:
                try:
                    limit = int(self.limit)
                except ValueError:
                    limit = 50
            else:
                limit = 50
            if limit > 0:
                search.set_limit(limit)
       

        # if a parent key was added
        parent_key = self.kwargs.get('parent_key')
        if parent_key:
            parent = Search.get_by_search_key(parent_key)
            search.add_parent_filter(parent)

        self.state = self.kwargs.get('state')
        self.state = BaseRefreshWdg.process_state(self.state)
        
        if self.state:
            parent_type = self.state.get('parent_type')
            if parent_type:
                search.add_filter("search_type", parent_type)


            

        filter_data = FilterData.get()
        data = filter_data.get_data()
        filter_mode = None
        prefix = "filter_mode"
        if self.prefix_namespace:
            prefix = '%s_%s' %(self.prefix_namespace, prefix)
        values = FilterData.get().get_values_by_index(prefix, 0)
        
        if values:
            filter_mode = values.get('filter_mode')
        if not filter_mode:
            filter_mode = 'and'

        # handle the showing of retired
        show_retired = False
        search.set_show_retired(show_retired)

        # add all the filters
        for filter in self.filters:
            filter.set_filter_mode(filter_mode)
            filter.set_state(self.state)
            filter.alter_search(search)

            self.num_filters_enabled += filter.get_num_filters_enabled()
コード例 #3
0
    def get_process(my):
        '''Get from the ProcessFilterWdg in SObjectLoadWdg,
            otherwise get from FilterData'''

        process = ''

        # Ususally there is no pipeline defined for prod/shot_instance
        # so get from prod/shot
        search_type = my.search_type
        if search_type == 'prod/shot_instance':
            search_type = 'prod/shot'

        state = Container.get("global_state")
        if state:
            process = state.get('process')
        else:

            # get it from FilterData
            data = FilterData.get()
            values = data.get_values_by_prefix('view_action_option')
            if values:
                process = values[0].get('load_%s_process' % search_type)

        if not process:
            from pyasm.prod.web import ProcessFilterWdg
            process_filter = ProcessFilterWdg(None, search_type)
            process = process_filter.get_value()
        return process
コード例 #4
0
    def set_filter_data(search_type, view=None):
        '''set filter data based on some saved search values in wdg_settings'''

        filter_data = FilterData.get()
        if not filter_data.get_data():
            # use widget settings
            key = SearchWdg._get_key(search_type, view)
            data = WidgetSettings.get_value_by_key(key)
            if data:

                try:
                    filter_data = FilterData(data)
                    filter_data.set_to_cgi()
                except SetupException, e:
                    print "This filter data is causing error:", data
                    print e
コード例 #5
0
    def execute(my):
        my.init()

        # create the filters
        my.filters = []
        """
        for element_name in my.config.get_element_names():
            
            filter = my.config.get_display_widget(element_name)
            my.filters.append(filter)

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

        """
        config = "<config>\n"
        config += "<filter>\n"

        # get all of the serialized versions of the filters
        """
        for filter in my.filters:
            config += filter.serialize() + "\n"
        """
        filter_data = FilterData.get()
        json = filter_data.serialize()
        value_type = "json"
        config += "<values type='%s'>%s</values>\n" % (value_type, json)
        config += "</filter>\n"
        config += "</config>\n"

        # format the xml
        xml = Xml()
        xml.read_string(config)

        if not my.view:
            saved_view = "saved_search:%s" % my.search_type
        else:
            saved_view = my.view
        #    if my.view.startswith("saved_search:"):
        #        saved_view = my.view
        #    else:
        #        saved_view = "saved_search:%s" % my.view

        # use widget config instead
        search = Search('config/widget_config')
        search.add_filter("view", saved_view)
        search.add_filter("search_type", my.search_type)
        if my.personal:
            search.add_user_filter()
        config = search.get_sobject()

        if not config:
            config = SearchType.create('config/widget_config')
            config.set_value("view", saved_view)
            config.set_value("search_type", my.search_type)
            if my.personal:
                config.set_user()

        config.set_value("config", xml.to_string())
        config.commit()
コード例 #6
0
    def alter_search(my, search):
        '''
        from tactic.ui.filter import BaseFilterElementWdg
        config = my.get_config()
        element_names = config.get_element_names()
        for element_name in element_names:
            widget = config.get_display_widget(element_name)

            if isinstance(widget, BaseFilterElementWdg):
                widget.alter_search(search)

        '''


        from tactic.ui.panel import CustomLayoutWdg


        # define a standard search action
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        config = my.get_config()

        data_list = filter_data.get_values_by_prefix(my.prefix)
        #columns = search.get_columns()

        element_data_dict = {}
        for data in data_list:
            handler = data.get("handler")
            element_name = data.get("element_name")
            if not element_name:
                continue

            element_data_dict[element_name] = data



        element_names = config.get_element_names()
        if not element_names:
            element_names = ['keywords']

        for element_name in element_names:

            widget = config.get_display_widget(element_name)
            if not widget:
                widget = KeywordFilterElementWdg(column='code|description')
                widget.set_name(element_name)

            data = element_data_dict.get(element_name)
            if not data:
                data = {}
            widget.set_values(data)

            if isinstance(widget, KeywordFilterElementWdg):
                if not data.get("keywords") and my.kwargs.get("keywords"):
                    widget.set_value("value", my.kwargs.get("keywords"))

            widget.alter_search(search)

        return
コード例 #7
0
ファイル: custom_search_wdg.py プロジェクト: zieglerm/TACTIC
    def alter_search(self, search):

        user = Environment.get_user_name()
        from pyasm.security import Login
        user = Login.get_by_login(user)
        search.add_filter("login", user.get_value("login"))

        import datetime
        from dateutil import parser
        filter_data = FilterData.get()
        values = filter_data.get_values_by_index("week", 0)
        date_string = values.get("calendar")
        if date_string:
            date = parser.parse(date_string)
        else:
            date = datetime.datetime.now()

        from tactic.ui.report import MMSUtility
        #start_wday, end_wday = self.get_week_range(date_string)
        start_wday, end_wday = MMSUtility.get_week_range(date)

        one_day = datetime.timedelta(days=1)

        column = "work_performed_date"

        # KEEP it simple for now
        search.add_op("begin")
        search.add_filter(column, start_wday, op='>=')
        search.add_filter(column, end_wday, op='<=')
        search.add_op("and")
        '''
        search.add_op("begin")
        search.add_filter(column, start_wday + one_day, op='>=')
        search.add_filter(column, end_wday - one_day, op='<=')
        search.add_op("and")

        search.add_op("begin")
        search.add_filter(column, start_wday, op='>=')
        search.add_filter(column, start_wday+one_day, op='<=')
        search.add_filter("shift", "pm", op='=')
        search.add_op("and")

        # FIXME: have to add this extra "or" because we don't support multiple
        # begins??
        search.add_op("or")
 
        search.add_op("begin")
        search.add_filter(column, end_wday, op='>=')
        search.add_filter(column, end_wday+one_day, op='<=')
        search.add_filter("shift", "am", op='=')
        search.add_op("and")
 
        search.add_op("or")
        '''

        search.add_order_by(column)
        search.add_order_by("work_start_time")
        search.add_order_by("shift")
コード例 #8
0
    def get_title(my):
        from tactic.ui.filter import FilterData
        values = FilterData.get().get_values_by_index(my.prefix, 0)
        selected_year = ''
        date = None
        selected_date_value = values.get(my.CAL_NAME)

        work_date_selector = CalendarInputWdg(my.CAL_NAME)
        if selected_date_value:
            selected_date = Date(db_date=selected_date_value)
        else:
            selected_date = Date()
        #my.mode = my.sel.get_value()

        week = int(selected_date.get_week())

        year = int(selected_date.get_year())
        weekday_list = Calendar.get_monthday_time(year, week)

        div = DivWdg()
        if my.mode == 'day':
            spacer = FloatDivWdg('&nbsp;', width=my.DAY_TITLE_WIDTH)
            div.add(spacer)
            my.weekday = int(selected_date.get_weekday(is_digit=True))
            month = selected_date.get_month(is_digit=False)
            month_div = FloatDivWdg(css='center_content')
            month_div.add(month)
            div.add_style('width: 15em')
        else:
            month_list = []
            for item in weekday_list:
                month, day, time = item
                if month not in month_list:
                    month_list.append(month)

            month_div = FloatDivWdg(width=my.WEEK_TITLE_WIDTH,
                                    css='right_content')
            month_div.add(' / '.join(month_list))
            div.add_style('width: 45em')

        div.add(month_div)

        for idx, i in enumerate(TimecardWdg.WEEK_CALENDAR):
            if my.weekday != None and idx != my.weekday:
                continue
            total = FloatDivWdg(width=50, css='center_content')
            span = SpanWdg(weekday_list[idx][1])
            if i in ["sat", "sun"]:
                span.add_style('color', '#995151')
            span.add(HtmlElement.br())

            weekday_span = SpanWdg('%s' % i.capitalize(), css='smaller')
            span.add(weekday_span)
            total.add(span)
            div.add(total)

        return div
コード例 #9
0
    def set_persistent_value(my):
        filter_data = FilterData.get_from_cgi()

        json = filter_data.serialize()
        # use widget settings instead
        # Using solely TableLayoutWdg will result in having no search view
        if my.view:
            key = SearchWdg._get_key(my.search_type, my.view)
            WidgetSettings.set_value_by_key(key, json)
        #value = WidgetSettings.get_value_by_key(key)
        #print "value: ", value
        return
コード例 #10
0
ファイル: yearly_report_wdg.py プロジェクト: zieglerm/TACTIC
    def get_display(self):
        filter_data = FilterData.get_from_cgi()
        values = filter_data.get_values("custom", "year")

        year = 0
        for value in values:
            if value:
                try:
                    year = int(value)
                except:
                    pass
        if not year:
            date = Date()
            year = int(date.get_year())

        sobject = self.get_current_sobject()
        id = sobject.get_id()

        column = self.get_option("column")
        month = int(self.get_option('month'))

        end_year = year
        end_month = month + 1
        if end_month > 12:
            end_month = 1
            end_year += 1

        search_type = 'MMS/personal_time_log'

        if year:

            search = Search(search_type)
            search.add_filter('login_id', id)
            search.add_filter('work_performed_date',
                              '%s-%0.2d-01' % (year, month), '>')
            search.add_filter('work_performed_date',
                              '%s-%0.2d-01' % (end_year, end_month), '<')

            sobjects = search.get_sobjects()
        else:
            sobjects = []

        if sobjects:
            parser = ExpressionParser()
            sum = parser.eval("@SUM(%s.%s)" % (search_type, column),
                              sobjects=sobjects)
        else:
            sum = 0

        div = DivWdg()
        div.add(sum)
        return div
コード例 #11
0
ファイル: asset_loader_wdg.py プロジェクト: rajubuddha/TACTIC
    def get_process(my):
        process_select = Container.get('process_filter')
        process = ''
        if process_select:
            process = process_select.get_value()
        else:
            # get it from FilterData
            data = FilterData.get()
            values = data.get_values_by_prefix('view_action_option')
            if values:
                process = values[0].get('load_asset_process')

        return process
コード例 #12
0
ファイル: search_wdg.py プロジェクト: zieglerm/TACTIC
    def execute(self):
        self.init()

        # create the filters
        self.filters = []

        config = "<config>\n"
        config += "<filter>\n"

        # get all of the serialized versions of the filters
        filter_data = FilterData.get()
        json = filter_data.serialize()
        value_type = "json"
        config += "<values type='%s'>%s</values>\n" % (value_type, json)
        config += "</filter>\n"
        config += "</config>\n"
        

        # format the xml
        xml = Xml()
        xml.read_string(config)


        if not self.view:
            saved_view = "saved_search:%s" % self.search_type
        else:
            saved_view = self.view
        #    if self.view.startswith("saved_search:"):
        #        saved_view = self.view
        #    else:
        #        saved_view = "saved_search:%s" % self.view

        # use widget config instead
        search = Search('config/widget_config')
        search.add_filter("view", saved_view)
        search.add_filter("search_type", self.search_type)
        if self.personal:
            search.add_user_filter()
        config = search.get_sobject()

        if not config:
            config = SearchType.create('config/widget_config')
            config.set_value("view", saved_view)
            config.set_value("search_type", self.search_type)
            if self.personal:
                config.set_user()

        config.set_value("category", "search_filter")
        config.set_value("config", xml.to_string())
        config.commit()
コード例 #13
0
    def init(self):
        self.view = self.kwargs.get('view')
        self.simple_search_view = self.kwargs.get('simple_search_view')
        self.search_type = self.kwargs.get('search_type')
        self.asset_search_type = self.kwargs.get('asset_search_type')
        if not self.asset_search_type:
            self.asset_search_type = 'prod/asset'
        self.instance_search_type = self.kwargs.get('instance_search_type')
        if not self.instance_search_type:
            self.instance_search_type = 'prod/shot_instance'

        #self.load_script = self.kwargs.get('load_script')
        #self.load_script_path = self.kwargs.get('load_script_path')
        self.is_refresh = self.kwargs.get('is_refresh') == 'true'
        self.state = Container.get_full_dict("global_state")
        self.process = self.state.get("process")

        values = FilterData.get().get_values_by_index('shot_filter', 0)
        self.shot_code = values.get('shot_code')
コード例 #14
0
ファイル: introspect.py プロジェクト: zieglerm/TACTIC
    def alter_search(self, search):
        print "Introspect alter_search"

        # see if any of the filters have a class handler defined
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get_from_cgi()
        values = filter_data.get_values_by_index("introspect", 0)

        do_search = values.get('search')
        if not do_search:
            return

        #search.add_filter("code", "chr002")
        session = SessionContents.get()

        node_names = session.get_node_names()

        snapshot_codes = session.get_snapshot_codes()
        snapshot_search = Search("sthpw/snapshot")
        snapshot_search.add_filters("code", snapshot_codes)
        snapshots = snapshot_search.get_sobjects()

        state_search_type = self.kwargs.get("search_type")

        # get ids
        ids = []
        for snapshot in snapshots:
            search_type = snapshot.get_value("search_type")
            if state_search_type:
                search_type_obj = SearchType.get(search_type)
                key = search_type_obj.get_base_key()
                print "compare: ", key, state_search_type
                if key != state_search_type:
                    continue

            id = snapshot.get_value("search_id")
            ids.append(id)

        print "ids: ", ids
        if ids:
            search.add_filters("id", ids)
コード例 #15
0
    def alter_task_search(self, search, prefix='children', prefix_namespace='' ):
        from tactic.ui.filter import FilterData, BaseFilterWdg, GeneralFilterWdg
        filter_data = FilterData.get()
        parent_search_type = get_search_type()
        
        if not filter_data.get_data():
            # use widget settings
            key = "last_search:%s" % parent_search_type
            data = WidgetSettings.get_value_by_key(key)
            if data:
                filter_data = FilterData(data)
            filter_data.set_to_cgi()

        
        filter_mode_prefix = 'filter_mode'
        if prefix_namespace:
            filter_mode_prefix = '%s_%s' %(prefix_namespace, filter_mode_prefix)
        
        filter_mode = 'and'
        filter_mode_value = filter_data.get_values_by_index(filter_mode_prefix, 0)
        if filter_mode_value:
            filter_mode = filter_mode_value.get('filter_mode')
       
        if prefix_namespace:
            prefix = '%s_%s' %(prefix_namespace, prefix)
        values_list = BaseFilterWdg.get_search_data_list(prefix, \
                search_type=self.get_searchable_search_type())
        if values_list:
            
            search.add_op('begin')
            GeneralFilterWdg.alter_sobject_search( search, values_list, prefix)
            if filter_mode != 'custom': 
                search.add_op(filter_mode)
        
        
        return search
コード例 #16
0
    def get_display(self):

        widget = DivWdg()
        self.set_as_panel(
            widget,
            class_name='spt_view_panel spt_panel spt_app_asset_inst_panel')

        parent_search_type = self.search_type

        if self.show_search:
            # Have to limit this search to just its parent.. cuz if the target is prod/shot_instance
            # and its parent search is ShotFilterWdg, it's hard to isolate what shot has been selected
            search_bvr = {
                'type':
                'click_up',
                'cbjs_action':
                'spt.dg_table.search_cbk(evt, bvr)',
                'override_class_name':
                'tactic.ui.cgapp.AppAssetInstancePanelWdg',
                'override_target':
                "bvr.src_el.getParent('.spt_app_asset_inst_panel')"
            }

            search_wdg = SearchWdg(search_type=parent_search_type, view='search_shot_loader', parent_key='', filter=''\
            , display='block', custom_filter_view='', state=None, run_search_bvr=search_bvr)
            widget.add(HtmlElement.spacer_div(1, 10))
            widget.add(search_wdg)

            # if there is result, it could only be one shot
            search = search_wdg.get_search()
            shots = search.get_sobjects()

            if not self.shot and len(shots) == 1:
                self.shot = shots[0]

        # create the asset table
        table_id = "main_body_asset_instance_table"

        if not self.shot:
            return widget
        # get any parent shots
        parent_code = self.shot.get_value("parent_code")
        shot_code = self.shot.get_code()

        # add the search make sure set elements are not shown
        search = Search(self.instance_search_type)
        if parent_code != "":
            search.add_filters(self.shot.get_foreign_key(),
                               [shot_code, parent_code])
        else:
            search.add_filter(self.shot.get_foreign_key(), shot_code)

        search.add_where("\"type\" in ('set_item', 'asset')")
        search.add_order_by('asset_code')

        instances = search.get_sobjects()

        # if parent shot and current shot has the same instance, hide the
        # parent's one

        top_instances = []
        for instance in instances:
            if instance.get_value('type') != 'set_item':
                top_instances.append(instance)

        #instances = ShotInstance.filter_instances(instances, shot_code)
        top_instances = ShotInstance.filter_instances(top_instances, shot_code)
        # TODO: just add asset name to the ShotInstance table
        # get the original asset names

        aux_data = ShotInstance.get_aux_data(top_instances,
                                             self.asset_search_type)

        values = FilterData.get().get_values_by_index('view_action_option', 0)
        state = {}

        if not self.show_search:
            if values:
                state['process'] = values.get('load_%s_process' %
                                              parent_search_type)
            else:
                process_filter = ProcessFilterWdg(None, parent_search_type)
                state['process'] = process_filter.get_value()

        Container.put("global_state", state)

        from tactic.ui.cgapp import CGAppLoaderWdg
        cg_wdg = CGAppLoaderWdg(view='load',
                                search_type=self.instance_search_type)
        widget.add(cg_wdg)

        if not top_instances:
            widget.add('No Asset Instances in Shot.')
        else:
            asset_table = TableLayoutWdg(table_id = table_id, search_type=self.instance_search_type,\
                view="load", inline_search=False, aux_info = aux_data, mode='simple')

            #asset_table = ViewPanelWdg( search_type=search_type,  inline_search=False, \
            #        show_general_search=False, view='load', state=state, mode='simple')

            asset_table.set_sobjects(top_instances)
            widget.add(asset_table)

            shot_inst_names = [inst.get_code() for inst in instances]

            self.add_unassigned_instances(widget, shot_inst_names)
        return widget
コード例 #17
0
ファイル: simple_search_wdg.py プロジェクト: mwx1993/TACTIC
    def get_display(my):

        element_data_dict = {}

        config = my.get_config()
        element_names = config.get_element_names()
        content_wdg = DivWdg()


        if not element_names:
            element_names = ['keywords']

        my.set_content(content_wdg)

        
        # this is somewhat duplicated logic from alter_search, but since this is called 
        # in ViewPanelWdg, it's a diff instance and needs to retrieve again
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix(my.prefix)
        for data in data_list:
            handler = data.get("handler")
            element_name = data.get("element_name")
            if not element_name:
                continue

            element_data_dict[element_name] = data

        elements_wdg = DivWdg()
        content_wdg.add(elements_wdg)
        elements_wdg.add_color("color", "color")
        elements_wdg.add_style("padding-top: 10px")
        elements_wdg.add_style("padding-bottom: 15px")

        #elements_wdg.add_color("background", "background3", 0)
        elements_wdg.add_color("background", "background", -3)
        elements_wdg.add_border()



        if len(element_names) == 1:
            elements_wdg.add_style("border-width: 0px 0px 0px 0px" )
            elements_wdg.add_style("padding-right: 50px" )
        else:
            elements_wdg.add_style("border-width: 0px 1px 0px 0px" )

        table = Table()
        table.add_color("color", "color")
        elements_wdg.add(table)
        table.add_class("spt_simple_search_table")
       
        num_rows = int(len(element_names)/2)+1
        tot_rows = int(len(element_names)/2)+1
        project_code = Project.get_project_code()
        # my.search_type could be the same as my.base_search_type
        full_search_type = SearchType.build_search_type(my.search_type, project_code)

        visible_rows = my.kwargs.get("visible_rows")
        if visible_rows:
            visible_rows = int(visible_rows)
            num_rows = visible_rows
        else:
            visible_rows = 0

        titles = config.get_element_titles() 
        row_count = 0
        for i, element_name in enumerate(element_names):
            attrs = config.get_element_attributes(element_name)
            if i % 2 == 0:

                if visible_rows and row_count == visible_rows:
                    tr, td = table.add_row_cell("+ more ...")
                    td.add_class("hand")
                    td.add_class("SPT_DTS")
                    td.add_class("spt_toggle")
                    td.add_style("padding-left: 10px")

                    td.add_behavior( {
                        'type': 'click_up',
                        'visible_rows': visible_rows,
                        'cbjs_action': '''
                        var top = bvr.src_el.getParent(".spt_simple_search_table");
                        var expand = true;
                        var rows = top.getElements(".spt_simple_search_row");
                        for (var i = 0; i < rows.length; i++) {
                            var row = rows[i];
                            if (row.getStyle("display") == "none") {
                                row.setStyle("display", "");
                            }
                            else {
                                row.setStyle("display", "none");
                                expand = false;
                            }
                        }
                        var spacer = top.getElements(".spt_spacer");
                        var cell = top.getElement(".spt_toggle");
                        if (expand) {
                            spacer.setStyle("height", (rows.length+bvr.visible_rows)*20);
                            cell.innerHTML = "- less ...";
                        }
                        else {
                            spacer.setStyle("height", bvr.visible_rows*20);
                            cell.innerHTML = "+ more ...";
                        }

                        '''
                    } )


                tr = table.add_row()
                if visible_rows and row_count >= visible_rows:

                    tr.add_class("spt_simple_search_row")
                    tr.add_style("display: none")
                    tr.add_style("height: 0px")

                row_count += 1

            icon_td = table.add_cell()
            title_td = table.add_cell()
            element_td =table.add_cell()


            # show the title
            title_td.add_style("text-align: right")
            title_td.add_style("padding-right: 5px")
            title_td.add_style("min-width: 100px")


            element_wdg = DivWdg()
            if attrs.get('view') == 'false':
                element_wdg.add_style('display: none')
            element_td.add(element_wdg)

            #title_td.add_style("border: solid 1px red")
            #element_td.add_style("border: solid 1px blue")
            #element_wdg.add_style("border: solid 1px yellow")


            if i == 0 and len(element_names) > 1:
                spacer = DivWdg()
                spacer.add_class("spt_spacer")
                spacer.add_style("border-style: solid")
                spacer.add_style("border-width: 0 1 0 0")
                #spacer.add_style("height: %spx" % (num_rows*20))
                spacer.add_style("height: %spx" % (num_rows*20))
                spacer.add_style("width: 10px")
                spacer.add_style("border-color: %s" % spacer.get_color("border") )
                spacer.add("&nbsp;")
                td = table.add_cell(spacer)
                td.add_attr("rowspan", tot_rows)

            #element_wdg.add_color("color", "color3")
            #element_wdg.add_color("background", "background3")
            #element_wdg.set_round_corners()
            #element_wdg.add_border()

            element_wdg.add_style("padding: 4px 10px 4px 5px")
            element_wdg.add_class("spt_table_search")
            element_wdg.add_style("margin: 1px")
            element_wdg.add_style("min-height: 20px")
            element_wdg.add_style("min-width: 250px")

            # this is done at get_top()
            #element_wdg.add_class("spt_search")
            element_wdg.add( HiddenWdg("prefix", my.prefix))

            display_handler = config.get_display_handler(element_name)
            element_wdg.add( HiddenWdg("handler", display_handler))


            element_wdg.add( HiddenWdg("element_name", element_name))
        

            from pyasm.widget import ExceptionWdg
            try:
                widget = config.get_display_widget(element_name)
                if widget:
                    widget.set_title(titles[i])

            except Exception, e:
                element_wdg.add(ExceptionWdg(e))
                continue


            if not widget:
                # the default for KeywordFilterElementWdg is mode=keyword
                if not my.column_choice:
                    my.column_choice = my.get_search_col(my.search_type)
                widget = KeywordFilterElementWdg(column=my.column_choice)
                widget.set_name(element_name)
                


            from pyasm.widget import IconWdg
            icon_div = DivWdg()
            icon_td.add(icon_div)
            icon_div.add_style("width: 20px")
            icon_div.add_style("margin-top: 2px")
            icon_div.add_style("padding-left: 5px")
            icon_div.add_class("spt_filter_top")


            widget.set_show_title(False)
            #element_wdg.add("%s: " % title)
            data = element_data_dict.get(element_name)
			
			
            view_panel_keywords = my.kwargs.get("keywords")
            #user data takes precedence over view_panel_keywords
            if isinstance(widget, KeywordFilterElementWdg):
                if view_panel_keywords:
                    widget.set_value("value", view_panel_keywords)
            if data:
                widget.set_values(data)

                
           
			    
                    

            if isinstance(widget, KeywordFilterElementWdg) and not full_search_type.startswith('sthpw/sobject_list'):
                widget.set_option('filter_search_type', full_search_type)
            try:
                if attrs.get('view') != 'false':
                    title_td.add(widget.get_title_wdg())

                element_wdg.add(widget.get_buffer_display())
            except Exception, e:
                element_wdg.add(ExceptionWdg(e))
                continue
コード例 #18
0
    def execute(my):

        trigger_sobj = my.get_trigger_sobj()
        data = trigger_sobj.get_value("data")
        #data = """[
        #{ "prefix": "rule", "name": "status", "value": "Approved" },
        #{ "prefix": "rule", "name": "pipeline" "value": "model" },
        #{ "prefix": "action", "type": "output", "name": "status", "value": "Pending" }
        #]
        #"""

        data = jsonloads(data)
        print "data: ", data
        from tactic.ui.filter import FilterData
        filter_data = FilterData(data)

        task = my.get_caller()

        # check that the process is correct
        trigger_info = filter_data.get_values_by_index("trigger")
        process = trigger_info.get("process")

        if task.get_value("process") != process:
            return

        parent = None

        rules = filter_data.get_values_by_prefix("rule")

        # go through each rule and determine if this trigger applies
        is_valid = True
        for rule in rules:
            attribute = rule.get('name')
            value = rule.get('value')

            if attribute in ['status']:
                # if condition does not match
                if task.get_value(attribute) != value:
                    is_valid = False

            elif attribute in ['pipeline']:
                attribute = 'pipeline_code'
                if parent == None:
                    parent = task.get_parent()
                    if parent == None:
                        continue

                if parent.get_value(attribute) != value:
                    is_valid = False

            else:
                is_valid = False

        if not is_valid:
            return

        # update the data

        #input = my.get_input()
        #update_data = input.get('update_data')
        #status = update_data.get('status')
        #search_key = input.get('search_key')
        #task = Search.get_by_search_key(search_key)

        # get the next process tasks
        output_tasks = task.get_output_tasks()
        input_tasks = task.get_input_tasks()
        actions = filter_data.get_values_by_prefix("action")
        #print "actions: ", actions

        for action in actions:
            type = action.get("type")
            attribute = action.get('name')
            value = action.get('value')

            if type == 'output':
                for output_task in output_tasks:
                    #output_status = output_task.get_value("status")
                    output_task.set_value(attribute, value)
                    output_task.commit()

            elif type == 'input':
                for output_task in output_tasks:
                    print "a : ", attribute, value

                    #output_status = output_task.get_value("status")
                    output_task.set_value(attribute, value)
                    output_task.commit()

            elif type == 'process':
                process = action.get("process")

                for input_task in input_tasks:
                    task_process = input_task.get_value("process")
                    if task_process == process:
                        input_task.set_value(attribute, value)
                        input_task.commit()
                        break

                for output_task in output_tasks:
                    task_process = output_task.get_value("process")
                    if task_process == process:
                        output_task.set_value(attribute, value)
                        output_task.commit()
                        break
コード例 #19
0
    def init(my):
        my.current_offset = 0
        my.count = None
        #my.text = TextWdg(my.search_limit_name)
        my.text = HiddenWdg(my.search_limit_name)
        my.text.add_style("width: 23px")
        my.text.add_style("margin-bottom: -1px")
        my.text.add_class("spt_search_limit_text")
        my.text.set_persist_on_submit(prefix=my.prefix)

        behavior = {
            'type':
            'keydown',
            'cbjs_action':
            '''
                 if (evt.key=='enter') {
                    // register this as changed item
                    var value = bvr.src_el.value;
                    
                        if (isNaN(value) || value.test(/[\.-]/)) {
                            spt.error('You have to use an integer.');
                        }
                }
        '''
        }

        my.text.add_behavior(behavior)

        # get the search limit that is passed in
        filter_data = FilterData.get()
        values = filter_data.get_values_by_prefix(my.prefix)
        if not values:
            # check web for embedded table
            web = WebContainer.get_web()
            values = {}
            limit_value = web.get_form_value("search_limit")
            label_value = web.get_form_value(my.label)
            if limit_value:
                values['search_limit'] = limit_value
            if label_value:
                values[my.label] = label_value
        else:
            values = values[0]

        my.values2 = filter_data.get_values_by_prefix("search_limit_simple")
        if not len(my.values2):
            my.values2 = {}
        else:
            my.values2 = my.values2[0]

        my.stated_search_limit = values.get("search_limit")
        """
        if not my.stated_search_limit:
            my.stated_search_limit = values.get("limit_select")
        if not my.stated_search_limit:
            my.stated_search_limit = values.get("custom_limit")
        """
        if my.stated_search_limit:
            my.stated_search_limit = int(my.stated_search_limit)
        else:
            my.stated_search_limit = 0

        # reused for alter_search() later
        my.values = values
コード例 #20
0
ファイル: base_config_wdg.py プロジェクト: zieglerm/TACTIC
    def init(self):

        # create all of the display elements
        if not self.config:
            # it shouldn't use the self.search_type_obj here as it would absorb the project info
            self.config = WidgetConfigView.get_by_search_type(self.search_type, self.config_base)
        self.element_names = self.config.get_element_names()
        self.element_titles = self.config.get_element_titles()  

        # TODO: should probably be all the attrs
        self.element_widths = self.config.get_element_widths()  

       
        simple_view = self.kwargs.get("show_simple_view")
        if simple_view == "true":
            simple_view = True
        else:
            simple_view = False


        self.extra_data = self.kwargs.get("extra_data")
        if self.extra_data and isinstance(self.extra_data, basestring):
            try:
                self.extra_data = jsonloads(self.extra_data)
            except:
                self.extra_data = self.extra_data.replace("'", '"')
                self.extra_data = jsonloads(self.extra_data)



        # go through each element name and construct the handlers
        for idx, element_name in enumerate(self.element_names):

            # check to see if these are removed for this production
            #if element_name in invisible_elements:
            #    continue

            simple_element = None

            display_handler = self.config.get_display_handler(element_name)
            new_display_handler = self.remap_display_handler(display_handler)
            if new_display_handler:
                display_handler = new_display_handler

            if not display_handler:
                # else get it from default of this type
                display_handler = self.get_default_display_handler(element_name)

            # get the display options
            display_options = self.config.get_display_options(element_name)

            # add in extra_data
            if self.extra_data:
                for key, value in self.extra_data.items():
                    display_options[key] = value

            try:
                if not display_handler:
                    element = self.config.get_display_widget(element_name)
                else:
                    display_options['element_name'] = element_name
                    element = WidgetConfig.create_widget( display_handler, display_options=display_options )
            except Exception as e:
                from tactic.ui.common import WidgetTableElementWdg
                element = WidgetTableElementWdg()
                # FIXME: not sure why this doesn't work
                #from pyasm.widget import ExceptionWdg
                #log = ExceptionWdg(e)
                #element.add(log)
                # FIXME: not sure why this doesn't work
                from pyasm.widget import IconWdg
                icon = IconWdg("Error", IconWdg.ERROR)
                element.add(icon)
                element.add(e)

            # skip the empty elements like ThumbWdg
            if simple_element and not element.is_simple_viewable():
                continue
            # make simple_element the element if it exists
            if simple_element:
                element = simple_element
            # if the element failed to create, then continue
            if element == None:
                continue


            element.set_name(element_name)
            title = self.element_titles[idx]
            element.set_title(title)

            # FIXME: this causes a circular reference which means the
            # Garbage collector can't clean it up
            # make sure the element knows about its layout engine
            element.set_layout_wdg(self)


            # TODO: should convert this to ATTRS or someting like that.  Not
            # just width
            if idx >= len(self.element_widths):
                element.width = 150
            else:
                element.width = self.element_widths[idx]

            if self.input_prefix:
                element.set_input_prefix(self.input_prefix)


            # get the display options
            #display_options = self.config.get_display_options(element_name)
            #for key in display_options.keys():
            element.set_options(display_options)

            self.add_widget(element,element_name)

            # layout widgets also categorize their widgets based on type
            if element_name == "Filter":
                section_name = 'filter'
            else:
                section_name = 'default'
            section = self.sections.get(section_name)
            if not section:
                section = []
                self.sections[section_name] = section
            section.append(element)


        # go through each widget and pass them the filter_data object
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        if not filter_data:
            filter_data = {}
        for widget in self.widgets:
            widget.set_filter_data(filter_data)



        # initialize all of the child widgets
        super(BaseConfigWdg,self).init()
コード例 #21
0
ファイル: base_config_wdg.py プロジェクト: hellios78/TACTIC
class BaseConfigWdg(BaseRefreshWdg):
    def __init__(my, search_type, config_base, input_prefix='', config=None):

        if type(search_type) in types.StringTypes:
            my.search_type_obj = SearchType.get(search_type)
            my.search_type = search_type
        elif isinstance(search_type, SearchType):
            my.search_type_obj = search_type
            my.search_type = my.search_type_obj.get_base_key()
        elif inspect.isclass(search_type) and issubclass(search_type, SObject):
            my.search_type_obj = SearchType.get(search_type.SEARCH_TYPE)
            my.search_type = my.search_type_obj.get_base_key()
        else:
            raise LayoutException('search_type must be a string or an sobject')
        my.config = config
        my.config_base = config_base
        my.input_prefix = input_prefix
        my.element_names = []
        my.element_titles = []

        from pyasm.web import DivWdg
        my.top = DivWdg()

        # Layout widgets compartmentalize their widgets in sections for drawing
        my.sections = {}

        super(BaseConfigWdg, my).__init__()

    # NEED to add these because this is derived from HtmlElement and not
    # BaseRefreshWdg
    def add_style(my, name, value=None):
        return my.top.add_style(name, value=value)

    def add_class(my, class_name):
        return my.top.add_class(class_name)

    def has_class(my, class_name):
        return my.top.has_class(class_name)

    def add_behavior(my, behavior):
        return my.top.add_behavior(behavior)

    def add_relay_behavior(my, behavior):
        return my.top.add_relay_behavior(behavior)

    def get_default_display_handler(cls, element_name):
        raise Exception("Must override 'get_default_display_handler()'")

    get_default_display_handler = classmethod(get_default_display_handler)

    def get_config_base(my):
        return my.config_base

    def get_config(my):
        return my.config

    def get_view(my):
        return my.config_base

    def remap_display_handler(my, display_handler):
        '''Provide an opportunity to remap a display handler for newer
        layouts engines using older configs'''
        return display_handler

    def init(my):

        # create all of the display elements
        if not my.config:
            # it shouldn't use the my.search_type_obj here as it would absorb the project info
            my.config = WidgetConfigView.get_by_search_type(
                my.search_type, my.config_base)
        my.element_names = my.config.get_element_names()
        my.element_titles = my.config.get_element_titles()

        # TODO: should probably be all the attrs
        my.element_widths = my.config.get_element_widths()

        simple_view = my.kwargs.get("show_simple_view")
        if simple_view == "true":
            simple_view = True
        else:
            simple_view = False

        # go through each element name and construct the handlers
        for idx, element_name in enumerate(my.element_names):

            # check to see if these are removed for this production
            #if element_name in invisible_elements:
            #    continue

            simple_element = None

            display_handler = my.config.get_display_handler(element_name)
            new_display_handler = my.remap_display_handler(display_handler)
            if new_display_handler:
                display_handler = new_display_handler

            if not display_handler:
                # else get it from default of this type
                display_handler = my.get_default_display_handler(element_name)

            # get the display options
            display_options = my.config.get_display_options(element_name)
            try:
                if not display_handler:
                    element = my.config.get_display_widget(element_name)
                else:
                    element = WidgetConfig.create_widget(
                        display_handler, display_options=display_options)
            except Exception, e:
                from tactic.ui.common import WidgetTableElementWdg
                element = WidgetTableElementWdg()
                # FIXME: not sure why this doesn't work
                #from pyasm.widget import ExceptionWdg
                #log = ExceptionWdg(e)
                #element.add(log)
                # FIXME: not sure why this doesn't work
                from pyasm.widget import IconWdg
                icon = IconWdg("Error", IconWdg.ERROR)
                element.add(icon)
                element.add(e)

            # skip the empty elements like ThumbWdg
            if simple_element and not element.is_simple_viewable():
                continue
            # make simple_element the element if it exists
            if simple_element:
                element = simple_element
            # if the element failed to create, then continue
            if element == None:
                continue

            element.set_name(element_name)
            title = my.element_titles[idx]
            element.set_title(title)

            # FIXME: this causes a circular reference which means the
            # Garbage collector can't clean it up
            # make sure the element knows about its layout engine
            element.set_layout_wdg(my)

            # TODO: should convert this to ATTRS or someting like that.  Not
            # just width
            element.width = my.element_widths[idx]

            if my.input_prefix:
                element.set_input_prefix(my.input_prefix)

            # get the display options
            #display_options = my.config.get_display_options(element_name)
            #for key in display_options.keys():
            element.set_options(display_options)

            my.add_widget(element, element_name)

            # layout widgets also categorize their widgets based on type
            if element_name == "Filter":
                section_name = 'filter'
            else:
                section_name = 'default'
            section = my.sections.get(section_name)
            if not section:
                section = []
                my.sections[section_name] = section
            section.append(element)

        # go through each widget and pass them the filter_data object
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        if not filter_data:
            filter_data = {}
        for widget in my.widgets:
            widget.set_filter_data(filter_data)

        # initialize all of the child widgets
        super(BaseConfigWdg, my).init()
コード例 #22
0
class SearchWdg(BaseRefreshWdg):
    def get_args_keys(my):
        '''External settings which populate the widget.  There are 3 ways to
        define which searches exist.
            1) specify the filters, 
            2) specify the view,
            3) specify whether to use the last saved search
        '''
        return {
            'search_type': 'The search_type that this search is operating on',
            'display':
            'Boolean. The initial display mode of the search.  it is none by default',
            'view': 'The stored view for the data. Saved Search',
            'parent_key': 'Provides ability to search by a single parent key',
            #'popup_embedded': 'Boolean, if True then this widget is generated for a Popup window (so now open close)',
            'filter': 'manaual data structure for filter',
            'use_last_search':
            'Boolean to determine if the last search is read or not',
            'state': 'the surrounding state of the search',
            'user_override':
            'if True, current search data overrides what is in the search_view',
            'limit': 'an overriding search limit. < 0 means no limit',
            'run_search_bvr': 'Run Search behavior',
            'custom_filter_view': 'Provide a custom filter area',
            'custom_search_view': 'Provide a custom search view'
        }

    def get_default_filter_config(my):
        custom_filter_view = my.kwargs.get('custom_filter_view')

        if not custom_filter_view:
            custom_filter_view = ''

        config = []
        config.append("<config>\n")
        config.append("<filter>\n")

        config.append('''
        <element name='Combination'>
          <display class='tactic.ui.filter.SObjectSearchFilterWdg'>
            <search_type>%s</search_type>
            <prefix>quick</prefix>
          </display>
        </element>
        ''' % my.search_type)

        config.append('''
        <element name='Custom'>
          <display class='tactic.ui.filter.GeneralFilterWdg'>
            <prefix>custom</prefix>
            <search_type>%s</search_type>
            <mode>custom</mode>
            <custom_filter_view>%s</custom_filter_view>
          </display>
        </element>
        ''' % (my.search_type, custom_filter_view))

        config.append('''
        <element name='Filter'>
          <display class='tactic.ui.filter.GeneralFilterWdg'>
             <prefix>main_body</prefix>
             <search_type>%s</search_type>
             <mode>sobject</mode>
           </display>
        </element>
        ''' % my.search_type)
        """
        config.append('''
        <element name='Filter2'>
          <display class='tactic.ui.filter.GeneralFilterWdg'>
             <prefix>filter2</prefix>
             <search_type>%s</search_type>
             <mode>sobject</mode>
           </display>
        </element>
        ''' % my.search_type)
        """

        config.append('''
        <element name='Parent'>
          <display class='tactic.ui.filter.GeneralFilterWdg'>
            <prefix>parent</prefix>
            <search_type>%s</search_type>
            <mode>parent</mode>
          </display>
        </element>
        ''' % my.search_type)

        config.append('''
        <element name='Children'>
          <display class='tactic.ui.filter.GeneralFilterWdg'>
            <prefix>children</prefix>
            <search_type>%s</search_type>
            <mode>child</mode>
          </display>
        </element>
        ''' % my.search_type)
        """
        config.append('''
        <element name='Related'>
          <display class='tactic.ui.filter.GeneralFilterWdg'>
            <prefix>related</prefix>
            <search_type>%s</search_type>
            <mode>child</mode>
          </display>
        </element>
        ''' % my.search_type)
        """

        config.append("</filter>\n")
        config.append("</config>\n")

        config = ''.join(config)

        config_xml = Xml()
        config_xml.read_string(config)
        config = WidgetConfig.get(xml=config_xml, view='filter')
        return config

    def get_num_filters_enabled(my):
        return my.num_filters_enabled

    def init(my):

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

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

        # create a search for this search widget
        my.search_type = my.kwargs.get('search_type')
        my.search = Search(my.search_type)
        my.config = None

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

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

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

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

        # get the config from a specific location

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

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

        # get from search view

        # filter can be either dict(data) or a list or
        # xml(filter wdg definition)
        if filter:
            if type(filter) == types.DictType:
                my.config = my.get_default_filter_config()
                filter_data = FilterData([filter])
                filter_data.set_to_cgi()
            elif type(filter) == types.ListType:
                my.config = my.get_default_filter_config()
                filter_data = FilterData(filter)
                filter_data.set_to_cgi()

            else:

                try:
                    filter_data = None

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

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

                except XmlException, e:
                    print "WARNING: non-xml filter detected!! %s" % filter

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

            try:
                search = Search('config/widget_config')
                search.add_filter("view", my.view)
                search.add_filter("search_type", my.search_type)
                config_sobj = search.get_sobject()
            except SearchException, e:
                print "WARNING: ", e
                config_sobj = None

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

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

                #my.config = my.get_default_filter_config()

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

            else:
                if my.use_last_search:
                    my.set_filter_data(my.search_type, my.view)
コード例 #23
0
ファイル: custom_search_wdg.py プロジェクト: zieglerm/TACTIC
    def get_display(self):

        from tactic.ui.report import MMSUtility
        import datetime
        date = datetime.datetime.now()
        start_wday, end_wday = MMSUtility.get_week_range(date)

        self.prefix = 'week'
        top = DivWdg()
        top.add_class("spt_table_search")
        self.set_as_panel(top)

        from tactic.ui.container import RoundedCornerDivWdg
        inner = RoundedCornerDivWdg(corner_size=10, hex_color_code='949494')
        inner.set_dimensions(width_str="95%",
                             content_height_str='95%',
                             height_str="100%")
        inner.add_style("margin: 20px")
        top.add(inner)

        hidden = HiddenWdg("prefix", self.prefix)
        top.add(hidden)

        filter_data = FilterData.get()
        values = filter_data.get_values_by_index("week", 0)
        date_string = values.get("calendar")
        if not date_string:
            date_string = WebContainer.get_web().get_form_value("calendar")

        if date_string:
            date = parser.parse(date_string)
        else:
            date = datetime.datetime.now()

        week = 1

        table = Table()
        table.add_style("color: black")
        table.add_style("width: 600px")
        table.add_row()
        inner.add(table)

        #inner.add("Range: %s - %s<br/><br/>" % (start_wday, end_wday))

        table.add_cell("Week Of Date: <br/>")
        calendar = CalendarInputWdg('calendar')

        day_cbk = '''
        var top = spt.get_parent(bvr.src_el, '.spt_table_search');
        var week_el = top.getElement('.spt_calendar_week');
        var input_el = top.getElement('.spt_calendar_input');
        var value = input_el.value;
        var week = spt.date_util.ymd.get_week( value )
        week_el.innerHTML = week + '';
        '''
        calendar.add_day_cbk(day_cbk)

        #calendar.set_option("first_day_of_week", 4)
        calendar.set_value(date.strftime("%Y-%m-%d"))
        # TODO: set default
        table.add_cell(calendar)

        week = int(date.strftime("%W")) + 1

        table.add_cell("Week: ")
        #select = SelectWdg("week")
        #select.add_class("action inputfield")
        #select.set_option("values", range(1,53) )
        #select.set_value(week)
        #select.set_option( "size", "2" )
        text = DivWdg()
        text.add_class("spt_calendar_week")
        text.add_style("width", "25px")
        text.add(week)
        table.add_cell(text)

        table.add_cell(self.get_search_wdg())

        return top
コード例 #24
0
    def init(my):

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

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

        # create a search for this search widget
        my.search_type = my.kwargs.get('search_type')
        my.search = Search(my.search_type)
        my.config = None

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

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

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

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

        # get the config from a specific location

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

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

        # get from search view

        # filter can be either dict(data) or a list or
        # xml(filter wdg definition)
        if filter:
            if type(filter) == types.DictType:
                my.config = my.get_default_filter_config()
                filter_data = FilterData([filter])
                filter_data.set_to_cgi()
            elif type(filter) == types.ListType:
                my.config = my.get_default_filter_config()
                filter_data = FilterData(filter)
                filter_data.set_to_cgi()

            else:

                try:
                    filter_data = None

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

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

                except XmlException, e:
                    print "WARNING: non-xml filter detected!! %s" % filter
コード例 #25
0
ファイル: simple_search_wdg.py プロジェクト: zieglerm/TACTIC
    def get_display(self):

        element_data_dict = {}

        config = self.get_config()
        element_names = config.get_element_names()

        content_wdg = DivWdg()
        content_wdg.add_class("spt_simple_search_top")

        onload_js = DivWdg()
        content_wdg.add(onload_js)
        onload_js.add_behavior({
            'type': 'load',
            'cbjs_action': self.get_onload_js()
        })

        if not element_names:
            element_names = ['keywords']

        self.set_content(content_wdg)

        # this is somewhat duplicated logic from alter_search, but since this is called
        # in ViewPanelWdg, it's a diff instance and needs to retrieve again
        filter_data = FilterData.get()

        filter_view = self.kwargs.get("filter_view")
        if filter_view:
            search = Search("config/widget_config")
            search.add_filter("view", filter_view)
            search.add_filter("category", "search_filter")
            search.add_filter("search_type", self.search_type)
            filter_config = search.get_sobject()
            if filter_config:
                filter_xml = filter_config.get_xml_value("config")
                filter_value = filter_xml.get_value("config/filter/values")
                if filter_value:
                    data_list = jsonloads(filter_value)

        else:
            data_list = filter_data.get_values_by_prefix(self.prefix)

        for data in data_list:
            handler = data.get("handler")
            element_name = data.get("element_name")
            if not element_name:
                continue

            element_data_dict[element_name] = data

        elements_wdg = DivWdg()
        content_wdg.add(elements_wdg)
        elements_wdg.add_color("color", "color")
        elements_wdg.add_style("padding-top: 10px")
        elements_wdg.add_style("padding-bottom: 15px")

        #elements_wdg.add_color("background", "background3", 0)
        elements_wdg.add_color("background", "background", -3)
        elements_wdg.add_border()

        if len(element_names) == 1:
            elements_wdg.add_style("border-width: 0px 0px 0px 0px")
            elements_wdg.add_style("padding-right: 50px")
        else:
            elements_wdg.add_style("border-width: 0px 0px 0px 0px")

        table = Table()
        table.add_color("color", "color")
        elements_wdg.add(table)
        table.add_class("spt_simple_search_table")

        columns = self.kwargs.get("columns")
        if not columns:
            columns = 2
        else:
            columns = int(columns)

        num_rows = int(len(element_names) / columns) + 1
        tot_rows = int(len(element_names) / columns) + 1
        project_code = Project.get_project_code()
        # self.search_type could be the same as self.base_search_type
        full_search_type = SearchType.build_search_type(
            self.search_type, project_code)

        visible_rows = self.kwargs.get("visible_rows")
        if visible_rows:
            visible_rows = int(visible_rows)
            num_rows = visible_rows
        else:
            visible_rows = 0

        titles = config.get_element_titles()
        row_count = 0
        for i, element_name in enumerate(element_names):
            attrs = config.get_element_attributes(element_name)
            if i % columns == 0:

                if visible_rows and row_count == visible_rows:
                    tr, td = table.add_row_cell("+ more ...")
                    td.add_class("hand")
                    td.add_class("SPT_DTS")
                    td.add_class("spt_toggle")
                    td.add_style("padding-left: 10px")

                    td.add_behavior({
                        'type':
                        'click_up',
                        'visible_rows':
                        visible_rows,
                        'cbjs_action':
                        '''
                        var top = bvr.src_el.getParent(".spt_simple_search_table");
                        var expand = true;
                        var rows = top.getElements(".spt_simple_search_row");
                        for (var i = 0; i < rows.length; i++) {
                            var row = rows[i];
                            if (row.getStyle("display") == "none") {
                                row.setStyle("display", "");
                            }
                            else {
                                row.setStyle("display", "none");
                                expand = false;
                            }
                        }
                        var spacer = top.getElements(".spt_spacer");
                        var cell = top.getElement(".spt_toggle");
                        if (expand) {
                            spacer.setStyle("height", (rows.length+bvr.visible_rows)*20);
                            cell.innerHTML = "- less ...";
                        }
                        else {
                            spacer.setStyle("height", bvr.visible_rows*20);
                            cell.innerHTML = "+ more ...";
                        }

                        '''
                    })

                tr = table.add_row()
                if visible_rows and row_count >= visible_rows:

                    tr.add_class("spt_simple_search_row")
                    tr.add_style("display: none")
                    tr.add_style("height: 0px")

                row_count += 1

            icon_td = table.add_cell()
            title_td = table.add_cell()
            element_td = table.add_cell()

            # need to add these to all the elements because it is all separated
            # by table tds
            icon_td.add_class("spt_element_item")
            icon_td.add_attr("spt_element_name", element_name)
            title_td.add_class("spt_element_item")
            title_td.add_attr("spt_element_name", element_name)
            element_td.add_class("spt_element_item")
            element_td.add_attr("spt_element_name", element_name)

            # show the title
            title_td.add_style("text-align: left")
            title_td.add_style("padding-right: 5px")
            title_td.add_style("min-width: 60px")

            element_wdg = DivWdg()
            if attrs.get('view') == 'false':
                element_wdg.add_style('display: none')
            element_td.add(element_wdg)

            if i >= 0 and i < columns - 1 and len(element_names) > 1:
                spacer = DivWdg()
                spacer.add_class("spt_spacer")
                spacer.add_style("border-style: solid")
                spacer.add_style("border-width: 0 0 0 0")
                #spacer.add_style("height: %spx" % (num_rows*20))
                spacer.add_style("height: %spx" % (num_rows * 10))
                spacer.add_style("width: 10px")
                spacer.add_style("border-color: %s" %
                                 spacer.get_color("border"))
                spacer.add("&nbsp;")
                td = table.add_cell(spacer)
                td.add_attr("rowspan", tot_rows)

            element_wdg.add_style("padding: 4px 10px 4px 5px")
            element_wdg.add_class("spt_table_search")
            element_wdg.add_style("margin: 1px")
            element_wdg.add_style("min-height: 20px")
            element_wdg.add_style("min-width: 250px")

            # this is done at get_top()
            #element_wdg.add_class("spt_search")
            element_wdg.add(HiddenWdg("prefix", self.prefix))

            display_handler = config.get_display_handler(element_name)
            element_wdg.add(HiddenWdg("handler", display_handler))

            element_wdg.add(HiddenWdg("element_name", element_name))

            from pyasm.widget import ExceptionWdg
            try:
                widget = config.get_display_widget(element_name)
                if widget:
                    widget.set_title(titles[i])

            except Exception as e:
                element_wdg.add(ExceptionWdg(e))
                continue

            if not widget:
                # the default for KeywordFilterElementWdg is mode=keyword
                if not self.column_choice:
                    self.column_choice = self.get_search_col(self.search_type)
                widget = KeywordFilterElementWdg(column=self.column_choice)
                widget.set_name(element_name)

            from pyasm.widget import IconWdg
            icon_div = DivWdg()
            icon_td.add(icon_div)
            icon_div.add_style("width: 20px")
            icon_div.add_style("margin-top: -2px")
            icon_div.add_style("padding-left: 6px")
            icon_div.add_class("spt_filter_top")

            widget.set_show_title(False)
            #element_wdg.add("%s: " % title)
            data = element_data_dict.get(element_name)

            view_panel_keywords = self.kwargs.get("keywords")
            #user data takes precedence over view_panel_keywords
            if isinstance(widget, KeywordFilterElementWdg):
                if view_panel_keywords:
                    widget.set_value("value", view_panel_keywords)
            if data:
                widget.set_values(data)

            if isinstance(
                    widget, KeywordFilterElementWdg
            ) and not full_search_type.startswith('sthpw/sobject_list'):
                widget.set_option('filter_search_type', full_search_type)
            try:
                if attrs.get('view') != 'false':
                    title_td.add(widget.get_title_wdg())

                element_wdg.add(widget.get_buffer_display())
            except Exception as e:
                element_wdg.add(ExceptionWdg(e))
                continue

            icon = IconWdg("Filter Set", "BS_ASTERISK")
            #icon.add_style("color", "#393")
            icon_div.add(icon)
            icon.add_class("spt_filter_set")
            icon.add_class("hand")
            icon.add_attr("spt_element_name", element_name)

            icon.add_behavior({
                'type':
                'click',
                'cbjs_action':
                '''
                var element_name = bvr.src_el.getAttribute("spt_element_name");
                spt.simple_search.clear_element(element_name);
                '''
            })

            if not widget.is_set():
                icon.add_style("display: none")

            else:
                color = icon_div.get_color("background", -10)
                icon_td.add_style("background-color", color)
                title_td.add_style("background-color", color)
                element_td.add_style("background-color", color)

        #elements_wdg.add("<br clear='all'/>")
        top = self.get_top()
        return top
コード例 #26
0
ファイル: tile_layout_wdg.py プロジェクト: mwx1993/TACTIC
    def init(my):
        my.scale_called = False
        my.scale = None
        top_view = my.kwargs.get("top_view")
        if top_view:
            kwargs = {
                'view': top_view,
            }
            from tactic.ui.panel import CustomLayoutWdg
            my.title_wdg = CustomLayoutWdg(**kwargs)
        else:
            my.title_wdg = None
        my.sticky_scale = my.kwargs.get('sticky_scale')
        if my.sticky_scale == 'local':
            # NOTE: each side bar link has a unique name on each level, but it's not always available
            # not in page refresh or built-in links
            # element = my.kwargs.get('element_name')
            my.scale_prefix = '%s:%s' %(my.search_type, my.view)
        else:
            my.scale_prefix = ''
        
        bottom_view = my.kwargs.get("bottom_view")
        if bottom_view:
            kwargs = {
                'view': bottom_view,
                'load': 'sequence',
            }
            from tactic.ui.panel import CustomLayoutWdg
            my.bottom = CustomLayoutWdg(**kwargs)
        else:
            my.bottom = None

        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        

        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")
        if my.scale == None:
            my.scale = 100


        my.aspect_ratio = my.kwargs.get('aspect_ratio')
        if my.aspect_ratio:
            parts = re.split('[\Wx]+', my.aspect_ratio)
            my.aspect_ratio = (int(parts[0]), int(parts[1]))
        else:
            my.aspect_ratio = (240, 160)

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

        my.top_styles = my.kwargs.get('styles')
        my.spacing = my.kwargs.get('spacing')
        if not my.spacing:
            my.spacing = '10'

        super(TileLayoutWdg, my).init()
コード例 #27
0
ファイル: search_wdg.py プロジェクト: zieglerm/TACTIC
    def init(self):

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

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

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

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

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


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


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

        # get the config from a specific location

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

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

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

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

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

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

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

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


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

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

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

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


        if not self.config:
            return


        self.num_filters_enabled = 0

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

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

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

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

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

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

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