Skip to content

Commit

Permalink
Merge pull request #23 from chriswebb09/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
chriswebb09 authored Apr 11, 2023
2 parents 5cf7c75 + 4f27287 commit 73ad6fd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
13 changes: 6 additions & 7 deletions DirectReport/browserview/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ def home():
return render_template('index.html', title='Home', data=[])


@app.route("/list", methods=['GET'])
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html', error=e), 404


@app.route("/list", methods=['GET', 'POST'])
def list():
"""List"""
items = EntryStorage('SQLite_Python.db')
week = items.get_all_entries_json()
return render_template('list.html', title='List', data=week)


@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html', error=e), 404


@app.route('/entry/<id>', methods=['GET'])
def detail(id=None):
Expand All @@ -40,7 +40,6 @@ def delete(id=None):
item = EntryStorage('SQLite_Python.db')
item.delete_entry(id)
return redirect("/list", code=302)
# return render_template('detail.html', title='Detail', data=entry)


if __name__ == "__main__":
Expand Down
43 changes: 29 additions & 14 deletions DirectReport/commandline/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import click
import sys
from pathlib import Path
import webbrowser

file = Path(__file__).resolve()
package_root_directory = file.parents[1]
Expand Down Expand Up @@ -30,7 +31,7 @@ def list_items():


@cli.group()
def new_item():
def item():
pass


Expand All @@ -40,54 +41,68 @@ def web_browser():


@click.command()
@click.option('--weekly', 'transformation', flag_value='weekly', default=True)
@click.option('--daily', 'transformation', flag_value='daily')
@click.option('--week', 'transformation', flag_value='week', default=True)
@click.option('--day', 'transformation', flag_value='day')
@click.option('--all', 'transformation', flag_value='all')
def show_list(transformation):
def list(transformation):
if transformation == "weekly":
week = ListBuilder.list_this_week()
if week is not None:
for week_item in week:
print(str(week_item) + "\n")
else:
print("week is none")
elif transformation == "daily":
today = ListBuilder.list_today()
if today is not None:
for today_item in today:
print(str(today_item) + "\n")
else:
print("Today is none")
elif transformation == "all":
all = ListBuilder.list_all()
if all is not None:
for all_item in all:
print(str(all_item) + "\n")
else:
print("All is none")


@click.command()
@click.option('--entry', help="Add new entry to list", prompt='What have you been working on')
@click.option('--entry', help="Add new entry to list", prompt='What have you been working on? ')
def new(entry):
topic = ""
if click.confirm('Do you wan to add in topic?'):
topic = click.prompt('Enter topic', type=str)
builder.new(entry, topic)


@click.command()
@click.option('--id', help="Delete item with id", prompt='What is the id of the entry you wish to delete?')
def delete(id):
ListBuilder.delete(id)


@click.command()
@click.option("--url", default="http://127.0.0.1:5000", help="URL to open in the web browser")
def launch(url):
click.launch(url)
app.run()


list_items.add_command(show_list)
new_item.add_command(new)
@click.command()
def mail():
recipient="[email protected]"
subject="work for week"
week = ListBuilder.list_this_week()
body = ""
if week is not None:
for week_item in week:
body += str(week_item["topic"]) + "\n" + str(week_item["message"]) + "\n" + "\n"
webbrowser.open('mailto:?to=' + recipient + '&subject=' + subject + '&body=' + body, new=1)


list_items.add_command(list)
item.add_command(new)
item.add_command(delete)
web_browser.add_command(launch)
web_browser.add_command(mail)

cli = click.CommandCollection(sources=[list_items, new_item, web_browser])
cli = click.CommandCollection(sources=[list_items, item, web_browser])

if __name__ == '__main__':
cli()
11 changes: 8 additions & 3 deletions DirectReport/models/list_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def get_daily_id():

@staticmethod
def add_new_weekly():
today = datetime.date.today()
today = datetime.date.today().strftime("%m/%d/%Y, %H:%M:%S")
weekly = WeekUUIDTable('SQLite_Python.db')
id = str(uuid.uuid4())
weekly.add_uuid(today, id)
return id

@staticmethod
def add_new_daily():
today = datetime.date.today()
today = datetime.date.today().strftime("%m/%d/%Y, %H:%M:%S")
daily = DailyUUIDTable('SQLite_Python.db')
daily.create_table()
weekly_id = str(ListBuilder.get_weekly_id())
Expand All @@ -74,10 +74,15 @@ def new(entry, topic=None):
topic = "Entry for work on " + str(datetime.datetime.now().strftime("%b %d, %Y"))

new_entry = Entry(
uuid.uuid4(), topic, entry, datetime.datetime.now(), datetime.datetime.now(), weekly_id, daily_id
uuid.uuid4(), topic, entry, datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S"), datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S"), weekly_id, daily_id
)
storage.add_entry(new_entry)

@staticmethod
def delete(id):
storage = EntryStorage('SQLite_Python.db')
storage.delete_entry(id)

@staticmethod
def list_all_daily_ids():
storage = DailyUUIDTable('SQLite_Python.db')
Expand Down
10 changes: 5 additions & 5 deletions DirectReport/tests/test_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from click.testing import CliRunner
from DirectReport.commandline.commandline import new
from DirectReport.commandline.commandline import show_list
from DirectReport.commandline.commandline import list
from DirectReport.commandline.commandline import launch

runner = CliRunner()
Expand All @@ -18,22 +18,22 @@ def test_prompt_new():


def test_cli_list():
response = runner.invoke(show_list)
response = runner.invoke(list)
assert response.exit_code == 0


def test_cli_list_daily():
result = runner.invoke(show_list, ['--daily'])
result = runner.invoke(list, ['--day'])
assert result.exit_code == 0


def test_cli_list_weekly():
result = runner.invoke(show_list, ['--weekly'])
result = runner.invoke(list, ['--week'])
assert result.exit_code == 0


def test_cli_list_all():
result = runner.invoke(show_list, ['--all'])
result = runner.invoke(list, ['--all'])
assert result.exit_code == 0


Expand Down

0 comments on commit 73ad6fd

Please sign in to comment.