本文整理汇总了Python中pyasm.biz.Task.sort_tasks方法的典型用法代码示例。如果您正苦于以下问题:Python Task.sort_tasks方法的具体用法?Python Task.sort_tasks怎么用?Python Task.sort_tasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.biz.Task
的用法示例。
在下文中一共展示了Task.sort_tasks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tasks_wdg
# 需要导入模块: from pyasm.biz import Task [as 别名]
# 或者: from pyasm.biz.Task import sort_tasks [as 别名]
#.........这里部分代码省略.........
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
示例2: process_tasks
# 需要导入模块: from pyasm.biz import Task [as 别名]
# 或者: from pyasm.biz.Task import sort_tasks [as 别名]
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