def create_task(title, manager, agent_list=[], status=TSD['Unassigned'], task_type='Visit'): task = Task( title=title, task_type=task_type, manager=manager, status=status, org=manager.org, ) task.save() if len(agent_list) > 0 and status == TSD['Unassigned']: task.status = TSD['Remaining'] for agent in agent_list: agent.is_present = True if status == TSD['In progress']: agent.userstate.active_task = task agent.is_working = True agent.save() agent.userstate.save() task.agent_list.add(agent) task.save() return task
def create_tasks_sync(task_list, organizer): for task in task_list: # print(task['agents']) agents = task['agents'] new_task = Task(manager=task['manager'], title=task['title'], address=task['address'], deadline=set_duration(task['duration'])) new_task.task_type = 'Custom Upload' custom_fields = {} if task['image_req']: new_task.image_required = True if task['demand']: custom_fields.update({ 'demand_keys': ['Item', 'Quantity'], 'Demands': [] }) for field in task['other_fields']: custom_fields.update({field: ''}) new_task.custom_fields = custom_fields new_task.save() if len(agents) > 1: new_task.agent_list.add(*agents) new_task.save() organizer.org.subscription.current_usage.consumed_tasks += len(task_list) organizer.org.subscription.current_usage.save()