def process_tasks(self, tasks, search): '''ensure that all the tasks of an sobject are shown either in this or next Page. sort the tasks according to pipeline within each sobject''' if tasks: task_ids = set() for task in tasks: task_ids.add(task.get_id()) # reset the search limits to reuse the search search.set_offset(0) search.set_limit(0) # do the last sobject, reusing the last search sobject = tasks[-1].get_parent() search.add_filter("search_type", sobject.get_search_type()) search.add_filter("search_id", sobject.get_id()) sobject_tasks = search.do_search(redo=True) for sobject_task in sobject_tasks: task_id = sobject_task.get_id() if task_id not in task_ids: tasks.append(sobject_task) task_ids.add(task_id) tasks_to_remove = set() tasks_to_insert = [] task_ids_to_remove = set() first_sobject_tasks = [] # find the task candidates to be removed if len(tasks) > 1: last_search_id = tasks[0].get_value('search_id') for task in tasks: search_type = task.get_value('search_type') search_id = task.get_value('search_id') if last_search_id == search_id: tasks_to_remove.add(task) task_ids_to_remove.add(task.get_id()) # do the first sobject, reusing the last search sobject = tasks[0].get_parent() search.add_filter("search_type", sobject.get_search_type()) search.add_filter("search_id", sobject.get_id()) first_sobject_tasks = search.do_search(redo=True) for sobject_task in first_sobject_tasks: task_id = sobject_task.get_id() if task_id not in task_ids: tasks_to_insert.append(sobject_task) # remove the first set of tasks if it is incomplete and has been # shown before. Note: this is still not perfect if the search limit is set # too low like below 20 if len(tasks_to_remove) < len(first_sobject_tasks): # or len(tasks_to_remove) > search_limit.get_limit() : for task_to_remove in tasks_to_remove: tasks.remove(task_to_remove) # these ids are not used for now task_ids = task_ids - task_ids_to_remove else: for task_to_insert in tasks_to_insert: tasks.insert(0, task_to_insert) sorted_tasks = Task.sort_tasks(tasks) #sorted_tasks = tasks return sorted_tasks
def get_tasks_wdg(my): widget = Widget() help = HelpItemWdg('Tasks', 'Tasks tab lets users view tasks assigned to him from multiple projects. For convenience, you can select a Time Preset like [this week] or [this month] to view what tasks fall within the chosen time range. Alternatively, you can click on the year, month, or week labels of the calendar to set a time range.') widget.add(help) search = Search("sthpw/task") search.add_order_by("bid_start_date") div = DivWdg(css="filter_box") div = FilterboxWdg() week_filter = my.get_week_filter() div.add(week_filter) range_checkbox = FilterCheckboxWdg("all_tasks", label="Show All Assigned Tasks") range_flag = range_checkbox.get_value() div.add(range_checkbox) hint = HintWdg("If not checked, only the tasks that fall within the defined date range are displayed") div.add(hint) project_filter = ProjectFilterWdg() project_filter.get_navigator().set_submit_onchange(False) project_code = project_filter.get_value() div.add_advanced_filter(project_filter) div.add_advanced_filter(HtmlElement.br()) task_filter = TaskStatusFilterWdg() div.add_advanced_filter(task_filter) search.add_project_filter(project_code) task_statuses = task_filter.get_processes() task_statuses_selected = task_filter.get_values() # one way to show tasks with obsolete statuses when the user # check all the task status checkboxes if task_statuses != task_statuses_selected: search.add_filters("status", task_filter.get_values() ) widget.add(div) user = Environment.get_user_name() search.add_filter("assigned", user) # add a date filter # TODO: should somehow get this from CalendarBarWdg if not range_flag: from pyasm.widget import CalendarBarWdg left_bound_hid = HiddenWdg('cal_left_control_hid') left_bound_hid.set_persistence() cal_left = left_bound_hid.get_value() right_bound_hid = HiddenWdg('cal_right_control_hid') right_bound_hid.set_persistence() cal_right = right_bound_hid.get_value() if not cal_left or not cal_right: # TODO: should be this month start_year = "2007" start_month_str = "Jan" end_year = "2007" end_month_str = "Dec" else: start_year, start_month_str = cal_left.split(":") end_year, end_month_str = cal_right.split(":") months = CalendarBarWdg.MONTHS start_month = 1 end_month = 12 if not start_year: date = Date() start_year = date.get_year() end_year = date.get_year() try: start_month = months.index(start_month_str)+1 except ValueError: pass try: end_month = months.index(end_month_str)+2 except ValueError: pass if end_month == 13: end_month = 1 end_year = int(end_year)+1 start_date = "%s-%0.2d-01" % (start_year, start_month) end_date = "%s-%0.2d-01" % (end_year, end_month) preset_week = HiddenWdg('cal_week_hid').get_value() if preset_week: # handle cross-year scenario if int(preset_week) == 1 and start_month == 12: start_year = int(start_year) + 1 day_list = Calendar.get_monthday_time(\ start_year, int(preset_week), month_digit=True)[0] year = day_list[2][0] month = int(day_list[0]) month_day = day_list[1] start_date = "%s-%0.2d-%s" % (year, month, month_day) start_date_obj = Date(db_date=start_date) start_date_obj.add_days(7) end_date = start_date_obj.get_db_date() search.add_where(''' ( (bid_start_date >= '%s' and bid_start_date <= '%s') or (bid_end_date >= '%s' and bid_end_date <= '%s') or (bid_start_date <= '%s' and bid_end_date >='%s')) ''' % (start_date, end_date, start_date, end_date, start_date, end_date) ) table = TableWdg("sthpw/task", "my_task") sobjects = search.get_sobjects() sorted_tasks = Task.sort_tasks(sobjects) table.set_sobjects(sorted_tasks) widget.add(table) return widget
def process_tasks(self, tasks, search): '''ensure that all the tasks of an sobject are shown either in this or next Page. sort the tasks according to pipeline within each sobject''' if tasks: task_ids = set() for task in tasks: task_ids.add(task.get_id()) # reset the search limits to reuse the search search.set_offset(0) search.set_limit(0) # do the last sobject, reusing the last search sobject = tasks[-1].get_parent() search.add_filter("search_type", sobject.get_search_type()) search.add_filter("search_id", sobject.get_id()) sobject_tasks = search.do_search(redo=True) for sobject_task in sobject_tasks: task_id = sobject_task.get_id() if task_id not in task_ids: tasks.append(sobject_task) task_ids.add(task_id) tasks_to_remove = set() tasks_to_insert = [] task_ids_to_remove = set() first_sobject_tasks = [] # find the task candidates to be removed if len(tasks) > 1: last_search_id = tasks[0].get_value('search_id') for task in tasks: search_type = task.get_value('search_type') search_id = task.get_value('search_id') if last_search_id == search_id: tasks_to_remove.add(task) task_ids_to_remove.add(task.get_id()) # do the first sobject, reusing the last search sobject = tasks[0].get_parent() search.add_filter("search_type", sobject.get_search_type()) search.add_filter("search_id", sobject.get_id()) first_sobject_tasks = search.do_search(redo=True) for sobject_task in first_sobject_tasks: task_id = sobject_task.get_id() if task_id not in task_ids: tasks_to_insert.append(sobject_task) # remove the first set of tasks if it is incomplete and has been # shown before. Note: this is still not perfect if the search limit is set # too low like below 20 if len(tasks_to_remove) < len(first_sobject_tasks) : # or len(tasks_to_remove) > search_limit.get_limit() : for task_to_remove in tasks_to_remove: tasks.remove(task_to_remove) # these ids are not used for now task_ids = task_ids - task_ids_to_remove else: for task_to_insert in tasks_to_insert: tasks.insert(0, task_to_insert) sorted_tasks = Task.sort_tasks(tasks) #sorted_tasks = tasks return sorted_tasks