def categorize(my, widget, search_type, search): '''categorize parents based on search_type''' # FIXME: this should not be here. This is a general class for all # search types, not just prod/asset if my.get_option('read_only') != 'true': if search_type == "prod/asset": lib_select = FilterSelectWdg('parent_lib') lib_select.persistence = False search2 = Search("prod/asset_library") lib_select.set_search_for_options(search2, "code", "title") lib_select.add_empty_option("-- Any --") widget.add(lib_select) # get all of the options for this search type parent_lib = lib_select.get_value() if parent_lib: search.add_filter('asset_library', parent_lib) elif search_type == "prod/shot": lib_select = FilterSelectWdg('parent_lib') lib_select.persistence = False search2 = Search("prod/sequence") lib_select.set_search_for_options(search2, "code", "code") lib_select.add_empty_option("-- Any --") widget.add(lib_select) # get all of the options for this search type parent_lib = lib_select.get_value() if parent_lib: search.add_filter('sequence_code', parent_lib) elif search_type == 'prod/texture': lib_select = FilterSelectWdg('parent_lib') lib_select.persistence = False search2 = Search("prod/texture") search2.add_column('category') search2.add_group_by("category") lib_select.set_search_for_options(search2, "category", "category") lib_select.add_empty_option("-- Any --") widget.add(lib_select) # get all of the options for this search type parent_lib = lib_select.get_value() if parent_lib: search.add_filter('category', parent_lib)
def categorize(my, widget, search_type, search): '''categorize parents based on search_type''' # FIXME: this should not be here. This is a general class for all # search types, not just prod/asset if my.get_option('read_only') != 'true': if search_type == "prod/asset": lib_select = FilterSelectWdg('parent_lib') lib_select.persistence = False search2 = Search("prod/asset_library") lib_select.set_search_for_options( search2, "code", "title" ) lib_select.add_empty_option("-- Any --") widget.add(lib_select) # get all of the options for this search type parent_lib = lib_select.get_value() if parent_lib: search.add_filter('asset_library', parent_lib) elif search_type == "prod/shot": lib_select = FilterSelectWdg('parent_lib') lib_select.persistence = False search2 = Search("prod/sequence") lib_select.set_search_for_options( search2, "code", "code" ) lib_select.add_empty_option("-- Any --") widget.add(lib_select) # get all of the options for this search type parent_lib = lib_select.get_value() if parent_lib: search.add_filter('sequence_code', parent_lib) elif search_type == 'prod/texture': lib_select = FilterSelectWdg('parent_lib') lib_select.persistence = False search2 = Search("prod/texture") search2.add_column('category') search2.add_group_by("category") lib_select.set_search_for_options( search2, "category", "category" ) lib_select.add_empty_option("-- Any --") widget.add(lib_select) # get all of the options for this search type parent_lib = lib_select.get_value() if parent_lib: search.add_filter('category', parent_lib)
class TimecardInfoTableElement(BaseTableElementWdg): ''' Info about the time card ''' def get_prefs(self): span = SpanWdg(css='med') self.select = FilterSelectWdg('timecard_view', label='View: ') self.select.set_option('values','compact|detailed') self.select.set_option('default', 'compact') span.add(self.select) return span def init(self): self.select = FilterSelectWdg('timecard_view', label='View: ') self.select.set_option('values','compact|detailed') self.select.set_option('default', 'compact') self.info_dict = {} self.is_preprocessed = False def preprocess(self): if not self.sobjects: return task_dict = {} misc_cards = [] self.info_dict = {} for timecard in self.sobjects: if timecard.get_value('search_type') == Task.SEARCH_TYPE: task_dict[timecard.get_value('search_id')] = timecard.get_id() else: misc_cards.append(timecard) tasks = Search.get_by_id(Task.SEARCH_TYPE, task_dict.keys()) if not tasks: return for task in tasks: self.info_dict[ task_dict.get(task.get_id()) ] = task # store the rest of the timecards which do not have an associated task # or have association with some other sobjects (not implemented yet) for card in misc_cards: self.info_dict[card.get_id()] = card def get_display(self): if not self.is_preprocessed: self.preprocess() self.is_preprocessed = True card = self.get_current_sobject() div = DivWdg() sobj = self.info_dict.get(card.get_id()) if isinstance(sobj, Timecard): # add basic timecard info if sobj.get_value('search_type'): # this is still valid div.add("Timecard for [%s] is not implemented yet" % sobj.get_value('search_type')) else: div.add("General") return div elif isinstance(sobj, Task): # add task info if self.select.get_value() =='detailed': return self.get_detailed(sobj) else: return self.get_compact(sobj) def get_compact(self, sobj): table = Table(css='embed') col = table.add_col() col.add_style("width: 80px") table.add_col(css='med') table.add_col(css='large') table.add_style("width: 200px") table.add_row() src_sobj = sobj.get_parent() thumb = ThumbWdg() thumb.set_icon_size(40) thumb.set_sobject(src_sobj) table.add_cell(thumb) table.add_cell(src_sobj.get_code()) table.add_data(SpanWdg(HtmlElement.b(sobj.get_process()), css='small')) #table.add_row() expand = ExpandableTextWdg() expand.set_max_length(20) desc = sobj.get_value("description") if not desc: desc = ' ' expand.set_value(desc) table.add_row_cell(expand) return table def get_detailed(self, sobj): table = Table(css='embed') table.add_style("width: 200px") col = table.add_col() col.add_style("width: 80px") table.add_col(css='large') table.add_col(css='large') src_sobj = sobj.get_parent() thumb = ThumbWdg() thumb.set_icon_size(40) thumb.set_sobject(src_sobj) table.add_row() td = table.add_cell(thumb) td.set_attr('rowspan','2') self._add_code(table, src_sobj) self._add_process(table, sobj) self._add_desc(table, sobj) return table def _add_code(self, table, sobj): table.add_cell(HtmlElement.i("%s Code: " % sobj.get_search_type_obj().get_title())) table.add_cell( HtmlElement.b(sobj.get_code())) def _add_process(self, table, sobj): table.add_row() table.add_cell(HtmlElement.i("Process: ")) table.add_cell( sobj.get_value("process") ) def _add_desc(self, table, sobj): tr = table.add_row() #tr.set_attr('colspan', '3') table.add_cell(HtmlElement.i("Desc: ")) expand = ExpandableTextWdg() expand.set_max_length(40) desc = sobj.get_value("description") if not desc: desc = ' ' expand.set_value(desc) td = table.add_cell( expand ) td.set_attr('colspan', '2')
class WeekTableElement(BaseTableElementWdg): CAL_NAME = "work_date_selector" DAY_TITLE_WIDTH = 15 WEEK_TITLE_WIDTH = 80 def preprocess(self): self.hours_dict = {} def init(self): self.weekday = None self.mode = 'week' self.sel = FilterSelectWdg('time_card_mode', label='View: ') self.sel.set_option('values', 'week|day') self.prefix = "timecard_filter" def get_prefs(self): self.sel = FilterSelectWdg('time_card_mode', label='View: ') self.sel.set_option('values', 'week|day') return self.sel def get_title(self): from tactic.ui.filter import FilterData values = FilterData.get().get_values_by_index(self.prefix, 0) selected_year = '' date = None selected_date_value = values.get(self.CAL_NAME) work_date_selector = CalendarInputWdg(self.CAL_NAME) if selected_date_value: selected_date = Date(db_date=selected_date_value) else: selected_date = Date() #self.mode = self.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 self.mode == 'day': spacer = FloatDivWdg(' ', width=self.DAY_TITLE_WIDTH) div.add(spacer) self.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=self.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 self.weekday != None and idx != self.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 def get_display(self): mode = self.sel.get_value() div = DivWdg() if self.mode == 'day': spacer = FloatDivWdg(' ', width=self.DAY_TITLE_WIDTH) else: spacer = FloatDivWdg(' ', width=self.WEEK_TITLE_WIDTH) div.add(spacer) timecard = self.get_current_sobject() for idx, i in enumerate(TimecardWdg.WEEK_CALENDAR): if self.weekday != None and idx != self.weekday: continue total = FloatDivWdg(width=50, css='center_content') hours = timecard.get_value(i) hours_label = hours if not hours: hours = 0 hours_label = '-' span = SpanWdg(hours_label) cur_val = self.hours_dict.get(i) if not cur_val: cur_val = 0 self.hours_dict[i] = cur_val + float(hours) total.add(span) div.add(total) return div def get_bottom_wdg(self): div = DivWdg() if self.mode == 'day': spacer = FloatDivWdg('Daily Total: ', width=self.DAY_TITLE_WIDTH, css='right_content') else: spacer = FloatDivWdg('Weekly Total: ', width=self.WEEK_TITLE_WIDTH, css='right_content') div.add(spacer) weekly_hours = 0 timecard = self.get_current_sobject() for idx, i in enumerate(TimecardWdg.WEEK_CALENDAR): if self.weekday != None and idx != self.weekday: continue total = FloatDivWdg(width=50, css='center_content') hours = self.hours_dict.get(i) hours_label = hours if not hours: hours = 0 hours_label = '-' span = SpanWdg(hours_label) weekly_hours += float(hours) if self.weekday == None: total.add(span) div.add(total) weekly_total = FloatDivWdg(width=60, css='center_content') weekly_total.add(HtmlElement.b(weekly_hours)) div.add(weekly_total) return div
class HierarchicalFilterWdg(BaseFilterWdg): '''A filter that takes the hierarchical schema into account''' def init(self): self.schema = Schema.get() if not self.schema: self.parent_type = None self.select = None return web = WebContainer.get_web() self.search_type = web.get_form_value("filter|search_type") if not self.search_type: search_type = self.options.get("search_type") self.parent_type = self.schema.get_parent_type(self.search_type) if not self.parent_type: self.select = None else: self.select = FilterSelectWdg("filter|%s" % self.parent_type) def get_parent_type(self): return self.parent_type def get_display(self): widget = Widget() if not self.select: return widget if not self.schema: Environment.add_warning("No schema defined") widget.add("No schema defined") return widget if not self.search_type: Environment.add_warning("HierarchicalFilterWdg: Cannot find current search_type") widget.add("Cannot find current search_type") return widget span = SpanWdg(css="med") parent_type = self.get_parent_type() if parent_type: parent_type_obj = SearchType.get(parent_type) span.add("%s: " % parent_type_obj.get_value("title")) # assume that there is a code in the parent self.select.add_empty_option("-- Select --") self.select.set_option("query", "%s|code|code" % self.parent_type) span.add(self.select) widget.add(span) return widget def alter_search(self, search): if not self.select: return if not self.parent_type: return if not self.schema: return parent_code = self.select.get_value() parent = Search.get_by_code(self.parent_type, parent_code) if not parent: return parent.children_alter_search(search, self.search_type)