Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
240e9d6
Science fiction for expense report example application.
tseaver Aug 28, 2014
6a913d3
Update science-fiction CLI.
tseaver Oct 3, 2014
580fb03
Initial CLI skeleton to support datastore narrative example.
tseaver Oct 3, 2014
01d8f95
PEP8
tseaver Oct 9, 2014
6426aba
Suppress two useless PEP8 errors.
tseaver Oct 9, 2014
943f9df
Progress toward sample implementation.
tseaver Oct 13, 2014
e95392e
Get exp report creation actually working.
tseaver Oct 20, 2014
4f8c242
Use same Oauth envvars as regression tests.
tseaver Oct 22, 2014
d9c3af1
Enforce distinction between creating / updating expense reports.
tseaver Oct 22, 2014
afb287e
Add 'delete' command.
tseaver Oct 22, 2014
e836913
Add checks for valid report status to update / delete commands.
tseaver Oct 22, 2014
ebae693
Record metadata (description, created, updated) for expense reports.
tseaver Oct 22, 2014
666b6a4
Make 'review_expenses list' work with live data.
tseaver Oct 22, 2014
578d40a
Make 'review_expenses show' work with live data.
tseaver Oct 22, 2014
31dd159
Housekeeping.
tseaver Oct 22, 2014
7da8592
Reconcile command output w/ Sphinx.
tseaver Oct 22, 2014
7a58c95
Drop unneeded base exception.
tseaver Oct 22, 2014
b209068
Get 'review_expenses {approve,reject}' working w/ live data.
tseaver Oct 22, 2014
a98b440
Wire in the datastore narrative example.
tseaver Oct 22, 2014
42ecfe8
'csv' is not a known highlight syntax.
tseaver Oct 22, 2014
10e9f9f
Describe top-down flow of creating an expense report from a CSV file.
tseaver Oct 22, 2014
5090a3b
Add narrative for 'update_report'.
tseaver Oct 22, 2014
44812da
Typos, clarifications.
tseaver Oct 23, 2014
911ed7c
Add discussion of 'review_expenses list'.
tseaver Oct 23, 2014
8eadf43
Require 'employee_id' arg for 'review_expenses show'.
tseaver Oct 23, 2014
7f38c3a
Add discussion of 'review_expenses show'.
tseaver Oct 23, 2014
239d86f
Add discussion of 'review_expenses {approve,reject}'.
tseaver Oct 23, 2014
021b797
Cross-ref overview narrative to functional sections.
tseaver Oct 23, 2014
1579110
Add discussion of 'submit_expenses delete'.
tseaver Oct 23, 2014
4879512
Typo.
tseaver Oct 23, 2014
bdc32ab
Revert "Suppress two useless PEP8 errors."
tseaver Oct 23, 2014
bf5e420
PEP8.
tseaver Oct 23, 2014
b7e7f9c
pylint (reduced set, as in tests / demos / regression).
tseaver Oct 23, 2014
64cc17a
Typos.
tseaver Oct 23, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Progress toward sample implementation.
  • Loading branch information
tseaver committed Oct 23, 2014
commit 943f9df93b47627823968fcf55ca3d296504fca8
12 changes: 6 additions & 6 deletions docs/datastore-narrative_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Sally can review a submitted expense report using the its ID:

.. code-block:: bash

$ review_expenses show --report-id=sally/expenses-2014-09-01
$ review_expenses show --employee-id=sally --report-idexpenses-2014-09-01
Report-ID: sally/expenses-2014-09-01
Report-Status: Pending
Employee-ID: sally
Expand All @@ -63,7 +63,7 @@ While in "Pending" status, Sally can edit the CSV and resubmit it:

.. code-block:: bash

$ submit_expenses update --report-id=sally/expenses-2014-09-01 expenses-20140901-amended.csv
$ submit_expenses update --employee-id=sally --report-idexpenses-2014-09-01 expenses-20140901-amended.csv
Processed 15 rows.
Updated, report ID: sally/expenses-2014-09-01

Expand All @@ -73,20 +73,20 @@ Sally's boss, Pat, can review all open expense reports:

$ review_expenses list --status=Pending

"Report ID","Description","Status","Memo"
"sally/2014-09-01","Frotz project kickoff, San Jose","Pending",""
"Employee ID","Report ID","Description","Status","Memo"
"sally","2014-09-01","Frotz project kickoff, San Jose","Pending",""

and download the expenses just as above. Pat can approve Sally's expense
report:

.. code-block:: bash

$ review_expenses approve --report-id=sally/expenses-2014-09-01 --check-number=4093
$ review_expenses approve --employee-id=sally --report-idexpenses-2014-09-01 --check-number=4093
Approved, report ID: sally/expenses-2014-09-01, check #4093

or reject it:

.. code-block:: bash

$ review_expenses reject --report-id=sally/expenses-2014-09-01 --reason="Travel not authorized by client"
$ review_expenses reject --employee-id=sally --report-idexpenses-2014-09-01 --reason="Travel not authorized by client"
Rejected, report ID: sally/expenses-2014-09-01, reason: Travel not authorized by client
49 changes: 49 additions & 0 deletions docs/examples/expenses/expenses/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
# package
import os

from gcloud import dataset
from gcloud.dataset.key import Key
from gcloud.dataset.query import Query

def get_dataset():
client_email = os.environ['EXPENSES_CLIENT_EMAIL']
private_key_path = os.environ['EXPENSES_PRIVATE_KEY_PATH']
dataset_id = os.environ['EXPENSES_DATASET_ID']
conn = dataset.get_connection(client_email, private_key_path)
return conn.dataset_id(dataset_id)

def get_employee(dataset, employee_id):
key = Key(dataset, path=[{'kind': 'Employee', 'name': employee_id}])
employee = dataset.get_entity(key)
if employee is None:
employee = dataset.entity('Employee').key(key)
employee.save()
return employee

def get_report(dataset, employee_id, report_id):
key = Key(dataset,
path=[{'kind': 'Employee', 'name': employee_id},
{'kind': 'Expense Report', 'name': report_id},
])
report = dataset.get_entity(key)
if report is None:
report = dataset.entity('Report').key(key)
report.save()
return report

def upsert_report(employee_id, report_id, rows):
dataset = get_dataset()
with dataset.transaction():
employee = get_employee(dataset, employee_id)
report = get_report(dataset, employee_id, report_id)
query = Query('Expense Item', dataset.connection())
# Delete any existing items.
for existing in query.ancestor(report.key()).fetch():
existing.delete()
# Add items based on rows.
for i, row in enumerate(rows):
path = report.key.path() + [{'kind': 'Expense Item', 'id': i}]
key = Key(dataset, path=path)
item = dataset.entity('Expense Item').key(key)
for k, v in rows.items():
item[k] = v
item.save()