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
def add_inputs(my): ''' register the inputs ''' if not my.task: return hidden = HiddenWdg('skey_TimecardWdg_%s' % my.task.get_id()) my.add_ajax_input(hidden) week_text = TextWdg('week_%s' % my.task.get_search_key()) my.add_ajax_input(week_text) year_text = HiddenWdg('year_%s' % my.task.get_search_key()) my.add_ajax_input(year_text)
def init_setup(my): '''set the ajax top and register some inputs''' div_id = 'timecard_%s' % my.task.get_id() my.main_div = DivWdg(id=div_id) my.set_ajax_top(my.main_div) # register the inputs first hidden = HiddenWdg('skey_TimecardWdg_%s' % my.task.get_id()) my.add_ajax_input(hidden) week_text = TextWdg('week_%s' % my.task.get_search_key()) my.add_ajax_input(week_text) year_text = HiddenWdg('year_%s' % my.task.get_search_key()) my.add_ajax_input(year_text)
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 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 = []