def get_view_wdg(my, sobject, view): div = DivWdg() #div.add_style("overflow: hidden") kwargs = { 'view': view, } from tactic.ui.panel import CustomLayoutWdg layout = CustomLayoutWdg(**kwargs) layout.set_sobject(sobject) div.add(layout.get_buffer_display()) return div
def get_view_wdg(my, sobject, view): div = DivWdg() #div.add_style("overflow: hidden") kwargs = { 'view': view, } from tactic.ui.panel import CustomLayoutWdg layout = CustomLayoutWdg(**kwargs) layout.set_sobject(sobject) div.add(layout.get_buffer_display()) return div
class SObjectCalendarWdg(CalendarWdg): ARGS_KEYS = { #'expression': 'expression used to get the tasks' 'start_date_col': 'Start date column', 'end_date_col': 'End date column', 'handler': 'handler class to display each day', 'sobject_display_expr': 'display expression for each sobject', 'search_type': 'search type to search for', 'search_expr': 'Initial SObjects Expression', 'view': 'Day view', 'sobject_view': 'Day sobject view when the user clicks on each day', 'detail_view': 'Custom view when the user clicks on each day' } def __init__(self, **kwargs): if kwargs.get("show_border") == None: kwargs['show_border'] = 'false' super(SObjectCalendarWdg, self).__init__(**kwargs) def handle_search(self): parent_key = self.kwargs.get("parent_key") # this is an absolute expression self.search_expr = self.kwargs.get("search_expr") self.search_type = self.kwargs.get("search_type") if not self.search_type: self.search_type = 'sthpw/task' if self.search_expr: result = Search.eval(self.search_expr) if isinstance(result, list): search = Search(self.search_type) codes = [x.get_code() for x in result] search.add_filters("code", codes) else: search = result else: self.op_filters = self.kwargs.get("filters") if self.op_filters: if isinstance(self.op_filters, basestring): self.op_filters = eval(self.op_filters) search = Search(self.search_type) if self.op_filters: search.add_op_filters(self.op_filters) self.start_column = self.kwargs.get('start_date_col') if not self.start_column: self.start_column = 'bid_start_date' self.end_column = self.kwargs.get('end_date_col') if not self.end_column: self.end_column = 'bid_end_date' if parent_key: parent = Search.get_by_search_key(parent_key) search.add_parent_filter(parent) search.add_op('begin') if self.handler: self.handler.alter_search(search) search.add_op('or') self.start_date = datetime(self.year, self.month, 1) next_month = self.month + 1 next_year = self.year if next_month > 12: next_month = 1 next_year += 1 self.end_date = datetime(next_year, next_month, 1) self.end_date = self.end_date - timedelta(days=1) # outer begin search.add_op('begin') search.add_op('begin') search.add_date_range_filter(self.start_column, self.start_date, self.end_date) search.add_date_range_filter(self.end_column, self.start_date, self.end_date) search.add_op('or') search.add_op('begin') search.add_filter(self.start_column, self.start_date, op='<=') search.add_filter(self.end_column, self.end_date, op='>=') search.add_op('and') search.add_op('or') extra_codes = self.kwargs.get("extra_codes") if extra_codes: search.add_op('and') extra_codes = extra_codes.split("|") search.add_filters("code", extra_codes) search.add_op('or') search.add_order_by(self.start_column) self.sobjects = search.get_sobjects() def init(self): super(SObjectCalendarWdg, self).init() custom_view = self.kwargs.get('view') self.custom_sobject_view = self.kwargs.get('sobject_view') self.custom_detail_view = self.kwargs.get("detail_view") if not self.custom_sobject_view and not self.custom_detail_view: self.custom_sobject_view = 'table' self.custom_layout = None if custom_view: from tactic.ui.panel import CustomLayoutWdg #custom_kwargs = self.kwargs.copy() custom_kwargs = self.kwargs.get("kwargs") if not custom_kwargs: custom_kwargs = {} elif isinstance(custom_kwargs, basestring): custom_kwargs = eval(custom_kwargs) custom_kwargs['view'] = custom_view self.custom_layout = CustomLayoutWdg(**custom_kwargs) class_name = "tactic.ui.widget.BaseCalendarDayWdg" else: class_name = self.kwargs.get('handler') if not class_name: class_name = 'tactic.ui.widget.TaskCalendarDayWdg' self.custom_layout = None self.handler = Common.create_from_class_path(class_name, [], self.kwargs) self.sobject_display_expr = self.kwargs.get('sobject_display_expr') # set the border style self.kwargs['border_type'] = 'all' self.handle_search() self.width = self.kwargs.get("cell_width") if not self.width: self.width = '100%' self.height = self.kwargs.get("cell_height") if not self.height: self.height = '80px' # preprocess the sobjects so that they are order by date self.date_sobjects = {} # get all of the weeks in this month self.sobjects_week_index = [] for i in self.weeks: self.sobjects_week_index.append([]) for index, sobject in enumerate(self.sobjects): start_date = sobject.get_value(self.start_column) if not start_date: continue start_date = parser.parse(start_date) end_date = sobject.get_value(self.end_column) if not end_date: continue end_date = parser.parse(end_date) for i, week in enumerate(self.weeks): first_day = week[0] first_day = datetime(first_day.year, first_day.month, first_day.day) last_day = week[6] + timedelta(days=1) last_day = datetime(last_day.year, last_day.month, last_day.day) is_in_week = False # if this sobject falls in this week if start_date >= first_day and start_date < last_day: is_in_week = True elif end_date >= first_day and end_date < last_day: is_in_week = True elif start_date < first_day and end_date > last_day: is_in_week = True if is_in_week: self.sobjects_week_index[i].append(sobject) # for each day in the sobject's timeline, add it to the appropriate # day list days = list( rrule.rrule(rrule.DAILY, dtstart=start_date, until=end_date)) for date in days: date_str = date.strftime("%Y-%m-%d") sobj_list = self.date_sobjects.get(date_str) if not sobj_list: # create a new list for that day sobj_list = [] self.date_sobjects[date_str] = sobj_list sobj_list.append(sobject) self.current_week = -1 def get_day_header_wdg(self, day): self.size = self.kwargs.get("size") if not self.size: self.size = 3 if self.size: weekday = self.WEEKDAYS[day.weekday()][0:self.size] else: weekday = self.WEEKDAYS[day.weekday()] div = DivWdg() div.add_style("font-weight: bold") div.add_style("font-size: 1.2em") div.add_style("padding: 8px") div.add(weekday) return div def get_legend_wdg(self): return None def get_header_wdg(self): outer = DivWdg() div = DivWdg() outer.add(div) div.add_color("background", "background", -3) div.add_style("padding: 5px") div.add_border() table = Table() table.add_style("margin-left: auto") table.add_style("margin-right: auto") table.add_color("color", "color") table.add_style("font-size: 1.5em") table.add_style("font-weight: bold") table.add_row() # add the month navigators date_str = "%s, %s" % (self.MONTHS[self.month - 1], self.year) month_wdg = DivWdg() month_wdg.add_style("width: 150px") month_wdg.add(date_str) prev_month_wdg = self.get_prev_month_wdg() next_month_wdg = self.get_next_month_wdg() table.add_cell(prev_month_wdg) td = table.add_cell(month_wdg) td.add_style("text-align: center") table.add_cell(next_month_wdg) div.add(table) return outer def get_week_left_wdg(self, week): return self.handler.get_week_left_wdg(week) def get_week_right_wdg(self, week): return self.handler.get_week_right_wdg(week) def get_day_wdg(self, month, day): # find the day of the week wday = day.strftime("%w") # if it's the first day ... if wday == "0": self.current_week += 1 sobjects_week_index = self.sobjects_week_index[self.current_week] self.handler.set_sobjects_index(sobjects_week_index) self.handler.set_current_week(self.current_week) sobjects = self.date_sobjects.get(str(day)) div = DivWdg() div.add_style("vertical-align: top") div.add_class("spt_calendar_day") div.add_class("hand") if self.custom_layout: self.custom_layout.kwargs['day_obj'] = day self.custom_layout.kwargs['day'] = str(day) if sobjects: # this causes mako processing error complaining about timestamp # send in just the search_keys for the day for now #sobject_dict_list = [ x.get_sobject_dict() for x in sobjects] #self.custom_layout.kwargs['search_objects'] = sobject_dict_list sobject_keys = [x.get_search_key() for x in sobjects] self.custom_layout.kwargs['search_keys'] = sobject_keys wdg = self.custom_layout.get_buffer_display() self.custom_layout.kwargs['search_keys'] = [] div.add(wdg) return div day_div = DivWdg() div.add(day_div) day_div.add(day.day) day_div.add_style("float: right") day_div.add_style("margin: 2px") div.add("<br clear='all'/>") """ mode = self.kwargs.get("mode") if mode in ["line","square"]: day_div.add_style("font-size: 0.6em") day_div.add_style("padding: 1px 0px 2px 2px") else: day_div.add_style("font-size: 1.2em") day_div.add_style("padding: 3px 0 3px 5px") """ if self.width: div.add_style("width: %s" % self.width) div.add_style("min-height: %s" % self.height) div.add_style("overflow: hidden") div.add_style("padding: 2px 0 2px 0") div.add_color("color", "color") div.add_style("vertical-align: top") st_title = SearchType.get(self.search_type).get_value('title') if sobjects: #ids = "".join( [ "['id','%s']" % x.get_id() for x in sobjects ]) ids = [str(x.get_id()) for x in sobjects] ids_filter = "['id' ,'in', '%s']" % '|'.join(ids) expression = "@SOBJECT(%s%s)" % (self.search_type, ids_filter) div.add_behavior({ 'type': "click", 'sobject_view': self.custom_sobject_view, 'detail_view': self.custom_detail_view, 'search_type': self.search_type, 'day': str(day), 'st_title': st_title, 'expression': expression, 'cbjs_action': ''' var class_name = 'tactic.ui.widget.SObjectCalendarDayDetailWdg'; var title = bvr.st_title + ' ' + bvr.day; var kwargs = { 'search_type': bvr.search_type, 'day': bvr.day, 'st_title': bvr.st_title, 'view': bvr.sobject_view, 'detail_view': bvr.detail_view, 'show_insert': 'false', 'expression': bvr.expression }; //spt.app_busy.show("Loading...") setTimeout(function() { //spt.panel.load_popup( title, class_name, kwargs ); spt.tab.set_main_body_tab(); spt.tab.add_new(title, title, class_name, kwargs); //spt.app_busy.hide(); }, 200) ''' }) content = DivWdg() content.add_style("vertical-align: top") content.add_class("spt_calendar_day_content") content.add_style("height: 100%") #content.add_style("width: 400px") content.add_style("min-height: %s" % self.height) self.handler.set_sobjects(sobjects) else: content = DivWdg() content.add_style("vertical-align: top") content.add_style("height: 100%") #content.add_style("width: 400px") content.add_style("min-height: %s" % self.height) self.handler.set_sobjects([]) # force it to be 120px for now if self.width: content.add_style("width: %spx" % self.width) self.handler.set_date(day) content.add(self.handler.get_buffer_display()) div.add(content) today = datetime.today() # store date like the database does YYYY-MM-DD date_str = "%04d-%02d-%02d" % (day.year, day.month, day.day) div.add_attr('spt_date', date_str) div.add_class('spt_date_day') color1 = div.get_color("background") color2 = div.get_color("background", -10) # put a different color for days that are not in the current month if day.month != month: div.add_style("color: #c22") div.add_style("opacity: 0.7") #div.add_style("background-image", "linear-gradient(135deg, #ccc 0%, #ccc 25%, #bbb 25%, #bbb 50%, #ccc 50%, #ccc 75%, #bbb 75%);"); div.add_style("background-size", "15px 15px") div.add_style("background-color", "") div.add_style( "background-image", "linear-gradient(135deg, rgba(0, 0, 0, 0.06) 25%, rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.06) 50%, rgba(0, 0, 0, 0.06) 75%, rgba(0, 0, 0, 0) 75%, rgba(0, 0, 0, 0));" ) elif day.year == today.year and day.month == today.month and day.day == today.day: div.add_color("background", "background", [-10, -10, 20]) color1 = div.get_color("background", [-10, -10, 20]) div.add_event("onmouseover", "$(this).setStyle('background-color','%s')" % color2) div.add_event("onmouseout", "$(this).setStyle('background-color','%s')" % color1) return div
class SObjectCalendarWdg(CalendarWdg): ARGS_KEYS = { #'expression': 'expression used to get the tasks' 'start_date_col': 'Start date column', 'end_date_col': 'End date column', 'handler': 'handler class to display each day', 'sobject_display_expr': 'display expression for each sobject', 'search_type': 'search type to search for', 'search_expr': 'Initial SObjects Expression', 'view': 'Day view', 'sobject_view': 'Day sobject view when the user clicks on each day', 'detail_view': 'Custom view when the user clicks on each day' } def __init__(self, **kwargs): if kwargs.get("show_border") == None: kwargs['show_border'] = 'false' super(SObjectCalendarWdg, self).__init__(**kwargs) def handle_search(self): parent_key = self.kwargs.get("parent_key") # this is an absolute expression self.search_expr = self.kwargs.get("search_expr") self.search_type = self.kwargs.get("search_type") if not self.search_type: self.search_type = 'sthpw/task' if self.search_expr: result = Search.eval(self.search_expr) if isinstance(result, list): search = Search(self.search_type) codes = [x.get_code() for x in result] search.add_filters("code", codes) else: search = result else: self.op_filters = self.kwargs.get("filters") if self.op_filters: if isinstance(self.op_filters, basestring): self.op_filters = eval(self.op_filters) search = Search(self.search_type) if self.op_filters: search.add_op_filters(self.op_filters) self.start_column = self.kwargs.get('start_date_col') if not self.start_column: self.start_column = 'bid_start_date' self.end_column = self.kwargs.get('end_date_col') if not self.end_column: self.end_column = 'bid_end_date' if parent_key: parent = Search.get_by_search_key(parent_key) search.add_parent_filter(parent) search.add_op('begin') if self.handler: self.handler.alter_search(search) search.add_op('or') self.start_date = datetime(self.year, self.month, 1) next_month = self.month+1 next_year = self.year if next_month > 12: next_month = 1 next_year += 1 self.end_date = datetime(next_year, next_month, 1) self.end_date = self.end_date - timedelta(days=1) # outer begin search.add_op('begin') search.add_op('begin') search.add_date_range_filter(self.start_column, self.start_date, self.end_date) search.add_date_range_filter(self.end_column, self.start_date, self.end_date) search.add_op('or') search.add_op('begin') search.add_filter(self.start_column, self.start_date, op='<=') search.add_filter(self.end_column, self.end_date, op='>=') search.add_op('and') search.add_op('or') extra_codes = self.kwargs.get("extra_codes") if extra_codes: search.add_op('and') extra_codes = extra_codes.split("|") search.add_filters("code", extra_codes) search.add_op('or') search.add_order_by(self.start_column) self.sobjects = search.get_sobjects() def init(self): super(SObjectCalendarWdg,self).init() custom_view = self.kwargs.get('view') self.custom_sobject_view = self.kwargs.get('sobject_view') self.custom_detail_view = self.kwargs.get("detail_view") if not self.custom_sobject_view and not self.custom_detail_view: self.custom_sobject_view = 'table' self.custom_layout = None if custom_view: from tactic.ui.panel import CustomLayoutWdg #custom_kwargs = self.kwargs.copy() custom_kwargs = self.kwargs.get("kwargs") if not custom_kwargs: custom_kwargs = {} elif isinstance(custom_kwargs, basestring): custom_kwargs = eval(custom_kwargs) custom_kwargs['view'] = custom_view self.custom_layout = CustomLayoutWdg(**custom_kwargs) class_name = "tactic.ui.widget.BaseCalendarDayWdg" else: class_name = self.kwargs.get('handler') if not class_name: class_name = 'tactic.ui.widget.TaskCalendarDayWdg' self.custom_layout = None self.handler = Common.create_from_class_path(class_name, [], self.kwargs) self.sobject_display_expr = self.kwargs.get('sobject_display_expr') # set the border style self.kwargs['border_type'] = 'all' self.handle_search() self.width = self.kwargs.get("cell_width") if not self.width: self.width = '100%' self.height = self.kwargs.get("cell_height") if not self.height: self.height = '80px' # preprocess the sobjects so that they are order by date self.date_sobjects = {} # get all of the weeks in this month self.sobjects_week_index = [] for i in self.weeks: self.sobjects_week_index.append([]) for index, sobject in enumerate(self.sobjects): start_date = sobject.get_value(self.start_column) if not start_date: continue start_date = parser.parse(start_date) end_date = sobject.get_value(self.end_column) if not end_date: continue end_date = parser.parse(end_date) for i, week in enumerate(self.weeks): first_day = week[0] first_day = datetime(first_day.year, first_day.month, first_day.day) last_day = week[6] + timedelta(days=1) last_day = datetime(last_day.year, last_day.month, last_day.day) is_in_week = False # if this sobject falls in this week if start_date >= first_day and start_date < last_day: is_in_week = True elif end_date >= first_day and end_date < last_day: is_in_week = True elif start_date < first_day and end_date > last_day: is_in_week = True if is_in_week: self.sobjects_week_index[i].append(sobject) # for each day in the sobject's timeline, add it to the appropriate # day list days = list(rrule.rrule(rrule.DAILY, dtstart=start_date, until=end_date)) for date in days: date_str = date.strftime("%Y-%m-%d") sobj_list = self.date_sobjects.get(date_str) if not sobj_list: # create a new list for that day sobj_list = [] self.date_sobjects[date_str] = sobj_list sobj_list.append(sobject) self.current_week = -1 def get_day_header_wdg(self, day): self.size = self.kwargs.get("size") if not self.size: self.size = 3 if self.size: weekday = self.WEEKDAYS[day.weekday()][0:self.size] else: weekday = self.WEEKDAYS[day.weekday()] div = DivWdg() div.add_style("font-weight: bold") div.add_style("font-size: 1.2em") div.add_style("padding: 8px") div.add( weekday ) return div def get_legend_wdg(self): return None def get_header_wdg(self): outer = DivWdg() div = DivWdg() outer.add(div) div.add_color("background", "background", -3) div.add_style("padding: 5px") div.add_border() table = Table() table.add_style("margin-left: auto") table.add_style("margin-right: auto") table.add_color("color", "color") table.add_style("font-size: 1.5em") table.add_style("font-weight: bold") table.add_row() # add the month navigators date_str = "%s, %s" % (self.MONTHS[self.month-1], self.year) month_wdg = DivWdg() month_wdg.add_style("width: 150px") month_wdg.add(date_str) prev_month_wdg = self.get_prev_month_wdg() next_month_wdg = self.get_next_month_wdg() table.add_cell(prev_month_wdg) td = table.add_cell(month_wdg) td.add_style("text-align: center") table.add_cell(next_month_wdg) div.add(table) return outer def get_week_left_wdg(self, week): return self.handler.get_week_left_wdg(week) def get_week_right_wdg(self, week): return self.handler.get_week_right_wdg(week) def get_day_wdg(self, month, day): # find the day of the week wday = day.strftime("%w") # if it's the first day ... if wday == "0": self.current_week += 1 sobjects_week_index = self.sobjects_week_index[self.current_week] self.handler.set_sobjects_index( sobjects_week_index ) self.handler.set_current_week(self.current_week) sobjects = self.date_sobjects.get(str(day)) div = DivWdg() div.add_style("vertical-align: top") div.add_class("spt_calendar_day") div.add_class("hand") if self.custom_layout: self.custom_layout.kwargs['day_obj'] = day self.custom_layout.kwargs['day'] = str(day) if sobjects: # this causes mako processing error complaining about timestamp # send in just the search_keys for the day for now #sobject_dict_list = [ x.get_sobject_dict() for x in sobjects] #self.custom_layout.kwargs['search_objects'] = sobject_dict_list sobject_keys = [ x.get_search_key() for x in sobjects] self.custom_layout.kwargs['search_keys'] = sobject_keys wdg = self.custom_layout.get_buffer_display() self.custom_layout.kwargs['search_keys'] = [] div.add(wdg) return div day_div = DivWdg() div.add( day_div ) day_div.add(day.day) day_div.add_style("float: right") day_div.add_style("margin: 2px") div.add("<br clear='all'/>") """ mode = self.kwargs.get("mode") if mode in ["line","square"]: day_div.add_style("font-size: 0.6em") day_div.add_style("padding: 1px 0px 2px 2px") else: day_div.add_style("font-size: 1.2em") day_div.add_style("padding: 3px 0 3px 5px") """ if self.width: div.add_style("width: %s" % self.width); div.add_style("min-height: %s" % self.height); div.add_style("overflow: hidden"); div.add_style("padding: 2px 0 2px 0") div.add_color("color", "color") div.add_style("vertical-align: top") st_title = SearchType.get(self.search_type).get_value('title') if sobjects: #ids = "".join( [ "['id','%s']" % x.get_id() for x in sobjects ]) ids = [ str(x.get_id()) for x in sobjects ] ids_filter = "['id' ,'in', '%s']" %'|'.join(ids) expression = "@SOBJECT(%s%s)" % (self.search_type, ids_filter) div.add_behavior( { 'type': "click", 'sobject_view' : self.custom_sobject_view, 'detail_view' : self.custom_detail_view, 'search_type': self.search_type, 'day': str(day), 'st_title': st_title, 'expression': expression, 'cbjs_action': ''' var class_name = 'tactic.ui.widget.SObjectCalendarDayDetailWdg'; var title = bvr.st_title + ' ' + bvr.day; var kwargs = { 'search_type': bvr.search_type, 'day': bvr.day, 'st_title': bvr.st_title, 'view': bvr.sobject_view, 'detail_view': bvr.detail_view, 'show_insert': 'false', 'expression': bvr.expression }; //spt.app_busy.show("Loading...") setTimeout(function() { //spt.panel.load_popup( title, class_name, kwargs ); spt.tab.set_main_body_tab(); spt.tab.add_new(title, title, class_name, kwargs); //spt.app_busy.hide(); }, 200) ''' } ) content = DivWdg() content.add_style("vertical-align: top") content.add_class("spt_calendar_day_content") content.add_style("height: 100%") #content.add_style("width: 400px") content.add_style("min-height: %s" % self.height); self.handler.set_sobjects(sobjects) else: content = DivWdg() content.add_style("vertical-align: top") content.add_style("height: 100%") #content.add_style("width: 400px") content.add_style("min-height: %s" % self.height); self.handler.set_sobjects([]) # force it to be 120px for now if self.width: content.add_style("width: %spx" % self.width) self.handler.set_date(day) content.add( self.handler.get_buffer_display() ) div.add(content) today = datetime.today() # store date like the database does YYYY-MM-DD date_str = "%04d-%02d-%02d" % (day.year, day.month, day.day) div.add_attr('spt_date', date_str) div.add_class('spt_date_day') color1 = div.get_color("background") color2 = div.get_color("background", -10) # put a different color for days that are not in the current month if day.month != month: div.add_style("color: #c22") div.add_style("opacity: 0.7") #div.add_style("background-image", "linear-gradient(135deg, #ccc 0%, #ccc 25%, #bbb 25%, #bbb 50%, #ccc 50%, #ccc 75%, #bbb 75%);"); div.add_style("background-size", "15px 15px") div.add_style("background-color", "") div.add_style("background-image", "linear-gradient(135deg, rgba(0, 0, 0, 0.06) 25%, rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.06) 50%, rgba(0, 0, 0, 0.06) 75%, rgba(0, 0, 0, 0) 75%, rgba(0, 0, 0, 0));") elif day.year == today.year and day.month == today.month and day.day == today.day: div.add_color("background", "background", [-10, -10, 20]) color1 = div.get_color("background", [-10, -10, 20]) div.add_event("onmouseover", "$(this).setStyle('background-color','%s')" % color2) div.add_event("onmouseout", "$(this).setStyle('background-color','%s')" % color1) return div