Skip to content

Commit

Permalink
feat(package/calendar): delete list in the To-Do List module
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed May 19, 2019
1 parent 12e8f5c commit 8575e9e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
7 changes: 4 additions & 3 deletions packages/calendar/data/answers/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"You do not have any list.",
"There is no list to show."
],
"list_does_not_exists": [
"list_does_not_exist": [
"Sorry I can't because the \"%list%\" does not exist.",
"I cannot do that because the \"%list%\" does not exist."
],
Expand All @@ -27,7 +27,7 @@
"I renamed the \"%old_list%\" list to \"%new_list%\" list."
],
"list_deleted": [
"I deleted the \"%list%\" list and all the todos it contained."
"I deleted the \"%list%\" list and all the todos it was contained."
],
"list_list": [
"You have %lists_nb% lists. Please let me list them below for you:<br><br><ul>%result%</ul>"
Expand All @@ -40,7 +40,8 @@
"I added \"%todo%\" to your \"%list%\" list."
],
"todo_completed": [
"I completed \"%todo%\" from your \"%list%\" list, congrats!"
"I completed \"%todo%\" from your \"%list%\" list, congrats!",
"Well done! I completed \"%todo%\" from your \"%list%\" list."
]
}
}
9 changes: 5 additions & 4 deletions packages/calendar/data/answers/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Je n'ai trouvé aucune liste.",
"Il n'y a pas de liste à montrer."
],
"list_does_not_exists": [
"list_does_not_exist": [
"Désolé je ne peux pas car la liste \"%list%\" n'éxiste pas.",
"Je ne peux pas parce que la liste \"%list%\" n'éxiste pas."
],
Expand All @@ -27,7 +27,7 @@
"J'ai renommé la liste \"%old_list%\" en liste \"%new_list%\"."
],
"list_deleted": [
"J'ai supprimé la liste \"%list%\" et toutes les tâches qu'elle contenait."
"J'ai supprimé la liste \"%list%\" et tous les éléments qu'elle contenait."
],
"list_list": [
"Vous avez %lists_nb% listes. Permettez-moi de vous les lister :<br><br><ul>%result%</ul>"
Expand All @@ -37,10 +37,11 @@
"<li>\"%list%\", contenant %todos_nb% éléments.</li>"
],
"todo_added": [
"J'ai ajouté la tâche \"%todo%\" à votre liste \"%list%\"."
"J'ai ajouté l'élément \"%todo%\" à votre liste \"%list%\"."
],
"todo_completed": [
"J'ai complété la tâche \"%todo%\" de votre liste \"%list%\", bravo !"
"J'ai complété l'élément \"%todo%\" de votre liste \"%list%\", bravo !",
"Bien joué ! J'ai complété l'élément \"%todo%\" de votre liste \"%list%\"."
]
}
}
31 changes: 25 additions & 6 deletions packages/calendar/todolist.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create_list(string, entities):
# Find entities
for item in entities:
if item['entity'] == 'list':
listname = item['sourceText']
listname = item['sourceText'].lower()

# Verify if a list name has been provided
if not listname:
Expand Down Expand Up @@ -81,17 +81,17 @@ def rename_list(string, entities):
# Find entities
for item in entities:
if item['entity'] == 'old_list':
old_listname = item['sourceText']
old_listname = item['sourceText'].lower()
elif item['entity'] == 'new_list':
new_listname = item['sourceText']
new_listname = item['sourceText'].lower()

# Verify if an old and new list name have been provided
if not old_listname or not new_listname:
return utils.output('end', 'new_or_old_list_name_not_provided', utils.translate('new_or_old_list_name_not_provided'))

# Verify if the old list exists
if lists.count(List.name == old_listname) == 0:
return utils.output('end', 'list_does_not_exists', utils.translate('list_does_not_exists', { 'list': old_listname }))
return utils.output('end', 'list_does_not_exist', utils.translate('list_does_not_exist', { 'list': old_listname }))

# Verify if the new list name already exists
if lists.count(List.name == new_listname) > 0:
Expand All @@ -109,9 +109,28 @@ def rename_list(string, entities):
}))

def delete_list(string, entities):
"""WIP"""
"""Delete a to-do list"""

# List name
listname = ''

# Find entities
for item in entities:
if item['entity'] == 'list':
listname = item['sourceText'].lower()

# Verify if a list name has been provided
if not listname:
return utils.output('end', 'list_name_not_provided', utils.translate('list_name_not_provided'))

# Verify if the list exists
if lists.count(List.name == listname) == 0:
return utils.output('end', 'list_does_not_exist', utils.translate('list_does_not_exist', { 'list': listname }))

# Delete the to-do list
lists.remove(List.name == listname)

return utils.output('end', 'list_deleted', utils.translate('list_deleted', { 'list': 'fake' }))
return utils.output('end', 'list_deleted', utils.translate('list_deleted', { 'list': listname }))

def add_todos(string, entities):
"""WIP"""
Expand Down

0 comments on commit 8575e9e

Please sign in to comment.