def _add_template_todo(template_todo, todolist_template, parent_todo, project, step, conditional_props, additional_data): remove = _to_exclude(conditional_props, template_todo.get('remove_if', [])) if not remove: if parent_todo.skipped_datetime: skipped_datetime = parent_todo.skipped_datetime else: to_skip = _to_exclude(conditional_props, template_todo.get('skip_if', [])) skipped_datetime = timezone.now() if to_skip else None if skipped_datetime: status = Todo.Status.DECLINED.value else: status = Todo.Status.PENDING.value todo = Todo(project=project, step=step, title=template_todo['description'], template=todolist_template, parent_todo=parent_todo, skipped_datetime=skipped_datetime, status=status, additional_data=additional_data) todo.save() for template_todo_item in template_todo.get('items', []): _add_template_todo(template_todo_item, todolist_template, todo, project, step, conditional_props, additional_data)
def add_todolist_template(todolist_template_slug, project_id, step_slug, additional_data=None): todolist_template = TodoListTemplate.objects.get( slug=todolist_template_slug) project = Project.objects.get(id=project_id) step = get_step_by_project_id_and_step_slug(project_id, step_slug) template_todos = todolist_template.todos.get('items', []) additional_data = additional_data if additional_data else {} root_todo = Todo(project=project, step=step, title=todolist_template.name, template=todolist_template, additional_data=additional_data, status=Todo.Status.PENDING.value) root_todo.save() cond_props = {} path = todolist_template.conditional_property_function.get('path', None) if path: try: get_cond_props = locate(path) cond_props = get_cond_props(project) except Exception: logger.exception('Invalid conditional function path.') for template_todo in template_todos: _add_template_todo(template_todo, todolist_template, root_todo, project, step, cond_props, additional_data)
def _add_template_todo(template_todo, todolist_template, parent_todo, task): todo = Todo(task=task, description=template_todo['description'], template=todolist_template, parent_todo=parent_todo) todo.save() for template_todo_item in template_todo.get('items', []): _add_template_todo(template_todo_item, todolist_template, todo, task)
def add_todolist_template(todolist_template_slug, task_id): todolist_template = TodoListTemplate.objects.get( slug=todolist_template_slug) task = Task.objects.get(id=task_id) template_todos = todolist_template.todos.get('items', []) root_todo = Todo(task=task, description=todolist_template.name, template=todolist_template) root_todo.save() for template_todo in template_todos: _add_template_todo(template_todo, todolist_template, root_todo, task)
def _add_template_todo(template_todo, todolist_template, parent_todo, task, conditional_props): remove = _to_exclude(conditional_props, template_todo.get('remove_if', [])) if not remove: if parent_todo.skipped_datetime: skipped_datetime = parent_todo.skipped_datetime else: to_skip = _to_exclude(conditional_props, template_todo.get('skip_if', [])) skipped_datetime = timezone.now() if to_skip else None todo = Todo(task=task, description=template_todo['description'], template=todolist_template, parent_todo=parent_todo, skipped_datetime=skipped_datetime) todo.save() for template_todo_item in template_todo.get('items', []): _add_template_todo(template_todo_item, todolist_template, todo, task, conditional_props)
def add_todolist_template(todolist_template_slug, task_id): todolist_template = TodoListTemplate.objects.get( slug=todolist_template_slug) task = Task.objects.get(id=task_id) template_todos = todolist_template.todos.get('items', []) root_todo = Todo(task=task, description=todolist_template.name, template=todolist_template) root_todo.save() cond_props = {} path = todolist_template.conditional_property_function.get('path', None) if path: try: get_cond_props = locate(path) cond_props = get_cond_props(task.project) except Exception: logger.exception('Invalid conditional function path.') for template_todo in template_todos: _add_template_todo(template_todo, todolist_template, root_todo, task, cond_props)
def create(self, validated_data): validated_data = self._set_step_to_validated_data(validated_data) instance = Todo(**validated_data) if isinstance(self._kwargs['data'], dict): instance.save() return instance