def get_item_list(self, items): self.select = SelectWdg(self.SELECT_NAME) self.select.set_attr("size", '%s' %(len(items)+1)) if items == ['']: return self.select self.select.set_option('values', items) code_col = self.web.get_form_value('code_col') labels = [] # assume they are all the same search type search_ids = [item.split("|", 1)[1] for item in items] search_type = '' if items: search_type = items[0].split('|', 1)[0] if search_type and search_ids: sobjs = Search.get_by_id(search_type, search_ids) for sobj in sobjs: name = sobj.get_name() code = sobj.get_code() if code_col and sobj.has_value(code_col): code = sobj.get_value(code_col) if name == code: labels.append(code) else: labels.append('%s - %s' %(code, name)) self.select.set_option('labels', labels) return self.select
def get_sequence_wdg(my): text_span = SpanWdg('New item ') current = my.get_my_sobject() search_type = get_search_type() select = SelectWdg(my.NEW_ITEM) select.set_option('web_state', my.get_option('web_state')) # get all of the options for this search type search = Search(search_type) search.add_order_by("code") sobjects = search.get_sobjects() if not sobjects: raise SetupException( "No Assets defined. Please create assets to add tasks to") values = [x.get_search_key() for x in sobjects] labels = [] code_col = my.web.get_form_value('code_col') for x in sobjects: name = x.get_name() code = x.get_code() if code_col and x.has_value(code_col): code = x.get_value(code_col) if name == code: labels.append(code) else: labels.append("%s - %s" % (code, name)) select.set_option("values", values) select.set_option("labels", labels) # transfer the options for key, value in my.options.items(): select.set_option(key, value) # extra code not needed here. setting web_state to true in the config # is sufficient, still not perfect yet. if not current: pass else: search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id")) select.set_value(search_key) button = my.get_sequence_button() text_span.add(select) text_span.add(button) return text_span
def _add_week(my, main_div, week, widget): '''add week display''' week_name = 'week_%s' % my.task.get_search_key() year_name = 'year_%s' % my.task.get_search_key() weeks = [i for i in xrange(1, 53)] week_filter = SelectWdg(week_name) week_filter.add_class('med') week_filter.set_option('values', weeks) week_filter.set_value(week) #widget.add_ajax_input(week_text) # add the name to the TimecardHourCmd widget.get_cmd().add_element_name(week_name) refresh_script = widget.get_refresh_script() week_filter.add_event('onchange', refresh_script) script = [ TimecardTaskRowWdg.get_script(week_name, year_name, add=False) ] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_LEFT) link = HtmlElement.js_href(';'.join(script), data=img) div = _get_div(20) div.add(link) main_div.add(div) div = _get_div(70) div.add("Wk ") div.add(week_filter) main_div.add(div) div = _get_div(20) script = [ TimecardTaskRowWdg.get_script(week_name, year_name, add=True) ] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_RIGHT) link = HtmlElement.js_href(';'.join(script), data=img) div.add(link) main_div.add(div)
def get_sequence_wdg(my): text_span = SpanWdg('New item ') current = my.get_my_sobject() search_type = get_search_type() select = SelectWdg(my.NEW_ITEM) select.set_option('web_state', my.get_option('web_state') ) # get all of the options for this search type search = Search(search_type) search.add_order_by("code") sobjects = search.get_sobjects() if not sobjects: raise SetupException("No Assets defined. Please create assets to add tasks to") values = [x.get_search_key() for x in sobjects] labels = [] code_col = my.web.get_form_value('code_col') for x in sobjects: name = x.get_name() code = x.get_code() if code_col and x.has_value(code_col): code = x.get_value(code_col) if name == code: labels.append(code) else: labels.append("%s - %s" % (code, name) ) select.set_option("values", values) select.set_option("labels", labels) # transfer the options for key, value in my.options.items(): select.set_option(key, value) # extra code not needed here. setting web_state to true in the config # is sufficient, still not perfect yet. if not current: pass else: search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") ) select.set_value(search_key) button = my.get_sequence_button() text_span.add(select) text_span.add(button) return text_span
def get_hier_sel(self, search_type): sel = SelectWdg(self.RELATED_SEARCH_TYPE, label='Related Search Type: ') sel.add_empty_option() schema = Schema.get() search_type_list = [search_type] if schema: parent_search_type = schema.get_parent_type(search_type) if parent_search_type: search_type_list.append(parent_search_type) child_types = schema.get_child_types(search_type) search_type_list.extend(child_types) sel.set_option('values', search_type_list) sel.set_value(self.related_search_type) return sel
def _add_week(my, main_div, week, widget): '''add week display''' week_name = 'week_%s' %my.task.get_search_key() year_name = 'year_%s' %my.task.get_search_key() weeks = [i for i in xrange(1, 53)] week_filter = SelectWdg(week_name) week_filter.add_class('med') week_filter.set_option('values', weeks) week_filter.set_value(week) #widget.add_ajax_input(week_text) # add the name to the TimecardHourCmd widget.get_cmd().add_element_name(week_name) refresh_script = widget.get_refresh_script() week_filter.add_event('onchange', refresh_script) script = [TimecardTaskRowWdg.get_script(week_name, year_name, add=False)] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_LEFT) link = HtmlElement.js_href(';'.join(script), data=img) div = _get_div(20) div.add(link) main_div.add(div) div = _get_div(70) div.add("Wk ") div.add(week_filter) main_div.add(div) div = _get_div(20) script = [TimecardTaskRowWdg.get_script(week_name, year_name, add=True)] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_RIGHT) link = HtmlElement.js_href(';'.join(script), data=img) div.add(link) main_div.add(div)
def get_hier_sel(my, search_type): sel = SelectWdg(my.RELATED_SEARCH_TYPE, label='Related Search Type: ') sel.add_empty_option() schema = Schema.get() search_type_list = [search_type] if schema: parent_search_type = schema.get_parent_type(search_type) if parent_search_type: search_type_list.append(parent_search_type) child_types = schema.get_child_types(search_type) search_type_list.extend(child_types) sel.set_option('values', search_type_list) sel.set_value(my.related_search_type) return sel
def get_display(my): current = my.get_current_sobject() parent_search_type = current.get_value('search_type') if not parent_search_type: return "No parent type" search_type = parent_search_type web = WebContainer.get_web() is_edit = not current.is_insert() # start a search search = Search(search_type) widget = Widget() # avoid a search key == '|' parent_search_key = '' if is_edit and current.get_value("search_type"): parent_search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") ) #parent_search_key = web.get_form_value("edit|parent") my.categorize(widget, search_type, search) select = SelectWdg(my.get_input_name()) widget.add(select) select.set_option('web_state', my.get_option('web_state') ) search.add_order_by("code") sobjects = [] if is_edit: if parent_search_key: sobjects = [Search.get_by_search_key(parent_search_key)] else: sobjects = search.get_sobjects() # Task planner task don't have a parent if not sobjects and search_type !='sthpw/task': span = SpanWdg("No Parents Defined. Parents for this task should be inserted first.") span.add_style("color: #f44") widget.add(span) return widget values = [x.get_search_key() for x in sobjects] labels = [] code_col = my.get_option('code_col') for x in sobjects: name = x.get_name() code = x.get_code() if code_col and x.has_value(code_col): code = x.get_value(code_col) if name == code: labels.append(code) else: labels.append("%s - %s" % (code, name) ) select.set_option("values", values) select.set_option("labels", labels) # transfer the options for key, value in my.options.items(): select.set_option(key, value) # extra code not needed here. setting web_state to true in the config # is sufficient, still not perfect yet. if current.is_insert(): pass else: select.set_value(parent_search_key) return widget
def init(self): self.column_select = SelectWdg("%s_column" % self.name) self.relation_select = SelectWdg("%s_relation" % self.name) self.value_text = TextWdg("%s_value" % self.name) self.columns = []
class GeneralFilterWdg(BaseFilterWdg): '''Represents a very generic filter matching a column to a value''' def init(self): self.column_select = SelectWdg("%s_column" % self.name) self.relation_select = SelectWdg("%s_relation" % self.name) self.value_text = TextWdg("%s_value" % self.name) self.columns = [] def set_columns(self, columns): self.columns = columns def set_columns_from_search_type(self, search_type): self.columns = SearchType.get(search_type).get_columns(show_hidden=False) def get_display(self): if not self.columns: print self.options search_type = self.options.get("search_type") if search_type: self.set_columns_from_search_type(search_type) if not self.columns: self.columns = [] span = SpanWdg() self.column_select.set_option("values", self.columns) self.column_select.set_persist_on_submit() span.add(self.column_select) relations = ["is", "is not", "contains", "does not contain", "is empty"] self.relation_select.set_option("values", relations) self.relation_select.set_persist_on_submit() span.add(self.relation_select) self.value_text.set_persist_on_submit() span.add(self.value_text) return span def alter_search(self, search): value = self.value_text.get_value() column = self.column_select.get_value() relation = self.relation_select.get_value() if relation == "is empty": search.add_where("(\"%s\" = '' or \"%s\" is NULL)" % (column, column) ) return if not value or not column or not relation: return if relation == "is": search.add_filter(column, value) elif relation == "is not": search.add_where("\"%s\" != '%s'" % (column, value) ) elif relation == "contains": search.add_regex_filter(column, value, op="EQI") elif relation == "does not contain": search.add_regex_filter(column, value, op="NEQI") elif relation == "is empty": search.add_where("(\"%s\" = '' or %s is NULL)" % (column, column) )
def get_context_wdg(self, search_type): '''drop down which selects which context to checkin''' # add a filter # use a regular SelectWdg with submit instead of FilterSelectWdg filter_div = FloatDivWdg("Context / subcontext:") select = SelectWdg("publish_context") labels, values = self.get_context_data(search_type, self.process) select.set_option("values", "|".join(values)) select.set_option("labels", "|".join(labels)) select.append_option('publish','publish') select.add_style("font-size: 0.8em") select.add_style("margin: 0px 3px") # explicitly set the value current = select.get_value() if current in values: context = current elif values: context = values[0] else: context = "" web = WebContainer.get_web() web.set_form_value("publish_context", context) select.set_value( context ) # set it to a instance variable self.context_select = select filter_div.add(select) # if specified, add a sub_context base_search_type = SearchType(search_type).get_base_key() settings = ProdSetting.get_value_by_key("%s/sub_context" % context,\ base_search_type) filter_div.add( "/ ") sub_context = None if settings: sub_context = SelectWdg("publish_sub_context") sub_context.set_option("values", settings) sub_context.set_submit_onchange() sub_context.add_empty_option("<- Select ->") else: # provide a text field sub_context = TextWdg("publish_sub_context") sub_context.set_attr('size','10') sub_context.set_persistence() filter_div.add( sub_context ) self.sub_context_select = sub_context #filter_div.add_style('padding-right','10px') return filter_div
class TaskAssetCreateSelectWdg(CreateSelectWdg): ''' Create a list of asset for multi task creations''' def init_setup(self): hidden = HiddenWdg(self.DELETE_MODE) self.add_ajax_input(hidden) hidden = HiddenWdg(self.NEW_ITEM) self.add_ajax_input(hidden) hidden = HiddenWdg(self.NEW_ITEM_LABEL) self.add_ajax_input(hidden) hidden = HiddenWdg("code_col") self.add_ajax_input(hidden) if not self.is_from_ajax(): hidden.set_value(self.get_option('code_col')) self.add(hidden) hidden = HiddenWdg('ref_search_type') self.add_ajax_input(hidden) if not self.is_from_ajax(): hidden.set_value(self.web.get_form_value('ref_search_type')) self.add(hidden) hidden = HiddenWdg('search_id') self.add_ajax_input(hidden) if self.is_from_ajax(): col_name = self.web.get_form_value('col_name') else: col_name = self.get_name() self.col_name = HiddenWdg('col_name', col_name) self.add_ajax_input(self.col_name) self.select_items = HiddenWdg('%s|%s' %(col_name, self.SELECT_ITEMS)) self.add_ajax_input(self.select_items) def get_delimiter(self): return '||' def get_search_key(self): search_key = '%s|%s' % (self.web.get_form_value('ref_search_type'), \ self.web.get_form_value('search_id')) return search_key def get_item_list(self, items): self.select = SelectWdg(self.SELECT_NAME) self.select.set_attr("size", '%s' %(len(items)+1)) if items == ['']: return self.select self.select.set_option('values', items) code_col = self.web.get_form_value('code_col') labels = [] # assume they are all the same search type search_ids = [item.split("|", 1)[1] for item in items] search_type = '' if items: search_type = items[0].split('|', 1)[0] if search_type and search_ids: sobjs = Search.get_by_id(search_type, search_ids) for sobj in sobjs: name = sobj.get_name() code = sobj.get_code() if code_col and sobj.has_value(code_col): code = sobj.get_value(code_col) if name == code: labels.append(code) else: labels.append('%s - %s' %(code, name)) self.select.set_option('labels', labels) return self.select def get_type_select(self, item_type): return FloatDivWdg(' ', width=100) def draw_widgets(self, widget, delete_widget, item_span): '''actually drawing the widgets''' widget.add(item_span) widget.add(HtmlElement.br(2)) widget.add(SpanWdg(self.select, css='med')) widget.add(delete_widget) widget.add(HtmlElement.br(2)) def get_sequence_wdg(self): text_span = SpanWdg('New item ') current = self.get_my_sobject() search_type = get_search_type() select = SelectWdg(self.NEW_ITEM) select.set_option('web_state', self.get_option('web_state') ) # get all of the options for this search type search = Search(search_type) search.add_order_by("code") sobjects = search.get_sobjects() if not sobjects: raise SetupException("No Assets defined. Please create assets to add tasks to") values = [x.get_search_key() for x in sobjects] labels = [] code_col = self.web.get_form_value('code_col') for x in sobjects: name = x.get_name() code = x.get_code() if code_col and x.has_value(code_col): code = x.get_value(code_col) if name == code: labels.append(code) else: labels.append("%s - %s" % (code, name) ) select.set_option("values", values) select.set_option("labels", labels) # transfer the options for key, value in self.options.items(): select.set_option(key, value) # extra code not needed here. setting web_state to true in the config # is sufficient, still not perfect yet. if not current: pass else: search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") ) select.set_value(search_key) button = self.get_sequence_button() text_span.add(select) text_span.add(button) return text_span def get_sequence_button(self): # add button widget = Widget() from pyasm.prod.web import ProdIconButtonWdg add = ProdIconButtonWdg('Add') script = ["append_item('%s','%s')" % (self.SELECT_NAME, self.NEW_ITEM )] script.append( self.get_refresh_script() ) add.add_event('onclick', ';'.join(script)) widget.add(add) hint = HintWdg('Add one or more items to the list.', title='Tip') widget.add(hint) return widget
def get_display(self): current = self.get_current_sobject() parent_search_type = current.get_value('search_type') if not parent_search_type: return "No parent type" search_type = parent_search_type web = WebContainer.get_web() is_edit = not current.is_insert() # start a search search = Search(search_type) widget = Widget() # avoid a search key == '|' parent_search_key = '' if is_edit and current.get_value("search_type"): parent_search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") ) #parent_search_key = web.get_form_value("edit|parent") self.categorize(widget, search_type, search) select = SelectWdg(self.get_input_name()) widget.add(select) select.set_option('web_state', self.get_option('web_state') ) search.add_order_by("code") sobjects = [] if is_edit: if parent_search_key: sobjects = [Search.get_by_search_key(parent_search_key)] else: sobjects = search.get_sobjects() # Task planner task don't have a parent if not sobjects and search_type !='sthpw/task': span = SpanWdg("No Parents Defined. Parents for this task should be inserted first.") span.add_style("color: #f44") widget.add(span) return widget values = [x.get_search_key() for x in sobjects] labels = [] code_col = self.get_option('code_col') for x in sobjects: name = x.get_name() code = x.get_code() if code_col and x.has_value(code_col): code = x.get_value(code_col) if name == code: labels.append(code) else: labels.append("%s - %s" % (code, name) ) select.set_option("values", values) select.set_option("labels", labels) # transfer the options for key, value in self.options.items(): select.set_option(key, value) # extra code not needed here. setting web_state to true in the config # is sufficient, still not perfect yet. if current.is_insert(): pass else: select.set_value(parent_search_key) return widget
def get_context_wdg(my, search_type): '''drop down which selects which context to checkin''' # add a filter # use a regular SelectWdg with submit instead of FilterSelectWdg filter_div = FloatDivWdg("Context / subcontext:") select = SelectWdg("publish_context") labels, values = my.get_context_data(search_type, my.process) select.set_option("values", "|".join(values)) select.set_option("labels", "|".join(labels)) select.append_option('publish','publish') select.add_style("font-size: 0.8em") select.add_style("margin: 0px 3px") # explicitly set the value current = select.get_value() if current in values: context = current elif values: context = values[0] else: context = "" web = WebContainer.get_web() web.set_form_value("publish_context", context) select.set_value( context ) # set it to a instance variable my.context_select = select filter_div.add(select) # if specified, add a sub_context base_search_type = SearchType(search_type).get_base_key() settings = ProdSetting.get_value_by_key("%s/sub_context" % context,\ base_search_type) filter_div.add( "/ ") sub_context = None if settings: sub_context = SelectWdg("publish_sub_context") sub_context.set_option("values", settings) sub_context.set_submit_onchange() sub_context.add_empty_option("<- Select ->") else: # provide a text field sub_context = TextWdg("publish_sub_context") sub_context.set_attr('size','10') sub_context.set_persistence() filter_div.add( sub_context ) my.sub_context_select = sub_context #filter_div.add_style('padding-right','10px') return filter_div
def init(my): my.column_select = SelectWdg("%s_column" % my.name) my.relation_select = SelectWdg("%s_relation" % my.name) my.value_text = TextWdg("%s_value" % my.name) my.columns = []