Skip to content

Commit

Permalink
Add an option to pass required field for todos created from a template (
Browse files Browse the repository at this point in the history
  • Loading branch information
junusheva committed Jul 29, 2021
1 parent 48d8770 commit 6b83381
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion orchestra/orchestra_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ def get_todo_templates():


def create_todos_from_template(todolist_template_slug, project_id,
step_slug, additional_data):
step_slug, additional_data, required=False):
data = {
'todolist_template_slug': todolist_template_slug,
'project_id': project_id,
'step_slug': step_slug,
'additional_data': additional_data,
'required': required
}
response = _make_api_request('post', 'create_todos_from_template',
data=json.dumps(data))
Expand Down
4 changes: 3 additions & 1 deletion orchestra/project_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def create_todos_from_template(request):
'todolist_template_slug': 'some-template-slug-123',
'step_slug': 'some-step-slug-123',
'project_id': 'some-project-id-123'
'required: False,
'additional_data': {
'some_key': 'some_value'
}
Expand All @@ -186,9 +187,10 @@ def create_todos_from_template(request):
step_slug = data.get('step_slug')
project_id = data.get('project_id')
additional_data = data.get('additional_data')
required = data.get('required', False)
if step_slug and project_id and todolist_template_slug:
add_todolist_template(todolist_template_slug, project_id,
step_slug, additional_data)
step_slug, additional_data, required)
todos = Todo.objects.filter(
template__slug=todolist_template_slug,
project__id=project_id,
Expand Down
15 changes: 10 additions & 5 deletions orchestra/todos/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

@transaction.atomic
def add_todolist_template(todolist_template_slug, project_id,
step_slug, additional_data=None):
step_slug, additional_data=None,
required=False):
todolist_template = TodoListTemplate.objects.get(
slug=todolist_template_slug)

Expand All @@ -36,6 +37,7 @@ def add_todolist_template(todolist_template_slug, project_id,
title=todolist_template.name,
template=todolist_template,
additional_data=additional_data,
required=required,
status=Todo.Status.PENDING.value
)
root_todo.save()
Expand All @@ -52,7 +54,8 @@ def add_todolist_template(todolist_template_slug, project_id,
for template_todo in template_todos:
_add_template_todo(
template_todo, todolist_template,
root_todo, project, step, cond_props, additional_data)
root_todo, project, step, cond_props, additional_data,
required)


def _to_exclude(props, conditions):
Expand All @@ -79,7 +82,7 @@ def _to_exclude(props, conditions):
def _add_template_todo(
template_todo, todolist_template,
parent_todo, project, step, conditional_props,
additional_data):
additional_data, required=False):
remove = _to_exclude(conditional_props, template_todo.get('remove_if', []))
if not remove:
if parent_todo.status == Todo.Status.DECLINED.value:
Expand All @@ -100,10 +103,12 @@ def _add_template_todo(
template=todolist_template,
parent_todo=parent_todo,
status=status,
additional_data=additional_data
additional_data=additional_data,
required=required
)
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)
project, step, conditional_props, additional_data,
required)

0 comments on commit 6b83381

Please sign in to comment.