aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Hiar <codyfh@gmail.com>2018-03-23 21:26:36 -0600
committerCody Hiar <codyfh@gmail.com>2018-03-23 21:26:36 -0600
commit6246cae841bd5c0171115dd5bb488640430093c2 (patch)
treea284b559c53602eb42dac8a041e580bb1d23b985
parent2e6f852f0d8941c4afe876952ed5a47a1d35cbf8 (diff)
Split prompts into separate functions
-rwxr-xr-xcli.py50
1 files changed, 40 insertions, 10 deletions
diff --git a/cli.py b/cli.py
index 389edb8..768c0e8 100755
--- a/cli.py
+++ b/cli.py
@@ -4,6 +4,7 @@
import datetime
import getpass
import os
+from typing import Dict
from blessings import Terminal
@@ -17,15 +18,18 @@ from utils import timestamp_field_to_datetime
t = Terminal()
-def create_time_record(ac):
- """Super Innefficient calls to create a time record."""
- # Get Project
+def prompt_user_for_project(ac) -> Dict:
+ """Prompt user for a project."""
projects = ac.get_projects()
suggestions = [x['name'] for x in projects]
completer = FuzzyCompleter(suggestions)
text = prompt('(Project)> ', completer=completer)
project = next(x for x in projects if x['name'] == text)
- # Get Task
+ return project
+
+
+def prompt_user_for_task(ac, project) -> Dict:
+ """Prompt the user for a task."""
tasks = ac.get_tasks_by_project(project['id'])['tasks']
suggestions = [x['name'] for x in tasks]
completer = FuzzyCompleter(suggestions)
@@ -34,26 +38,52 @@ def create_time_record(ac):
task = next(x for x in tasks if x['name'] == text)
else:
task = None
- # Get Value
+ return task
+
+
+def prompt_user_for_time_value(ac) -> str:
+ """Prompt the user for a time value."""
value = prompt('(Value)> ')
# If integer is passed then treat it as minutes
if ('.' not in value) and (':' not in value):
value = float(value) / 60
- # Get Job Type
+ return value
+
+
+def prompt_user_for_job_type(ac) -> Dict:
+ """Prompt the user for a job type."""
job_types = ac.get_job_types()
suggestions = [x['name'] for x in job_types]
completer = FuzzyCompleter(suggestions)
text = prompt('(Job Type)> ', completer=completer)
job_type = next(x for x in job_types if x['name'] == text)
- # Get Date
+ return job_type
+
+
+def prompt_user_for_date(ac) -> str:
+ """Prompt the user for a date."""
completer = DateFuzzyCompleter()
text = prompt('(Date)> ', completer=completer)
choosen_date = datetime.datetime.strptime(text, '%a, %Y-%m-%d')
- # Get Billable
+ return choosen_date.strftime('%Y-%m-%d')
+
+
+def prompt_user_for_billable_status(ac) -> int:
+ """Prompt the user for a billable status."""
billable_choices = {True: 1, False: 0}
billable = confirm('(Billable (y/n))> ')
billable = billable_choices[billable]
- # Get Summary
+ return billable
+
+
+def create_time_record(ac):
+ """Super Innefficient calls to create a time record."""
+ project = prompt_user_for_project(ac)
+ task = prompt_user_for_task(ac, project)
+ value = prompt_user_for_time_value(ac)
+ job_type = prompt_user_for_job_type(ac)
+ billable = prompt_user_for_billable_status(ac)
+ date = prompt_user_for_date(ac)
summary = prompt('(Summary)> ', enable_open_in_editor=True)
# Get User
users = ac.get_users()
@@ -63,7 +93,7 @@ def create_time_record(ac):
'task_id': task['id'] if task else None,
'user_id': user['id'],
'job_type_id': job_type['id'],
- 'record_date': choosen_date.strftime('%Y-%m-%d'),
+ 'record_date': date,
'billable_status': billable,
'summary': summary,
}