-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export as JSON implemented. #44
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments for future improvement but I will approve this PR without requesting changes.
I also note that this code is failing the black check. I'm not sure if you are familiar with black - its a code formatter (I think like prettier).
While I will merge PR in its current state, for future PRs you should run black and commit the results as part of your pr.
pip install black
black app
@@ -77,7 +77,11 @@ <h1>Recurring Expenses</h1> | |||
Export | |||
</button> | |||
<ul class="dropdown-menu"> | |||
<li><a class="dropdown-item" href="{% url 'recurring_expenses:export' %}?format=csv">CSV</a></li> | |||
{% for format in export_formats %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this!
for expense in expenses: | ||
amount_nzd = (1 / fx_rates[expense.currency]) * float(expense.amount) | ||
expense.amount_nzd = amount_nzd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic is duplicated for the CSV export and also for the django web view.
To keep the code DRY we should extract this logic to its own method that we run before passing the data to either export_recurring_expenses
We can do this as a future improvement though
if export_format not in _EXPORT_FORMATS: | ||
return HttpResponse(status=204) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this works but it works and I like it. I wonder if it would also work with a HTTP 400 response code?
Something I would be interested to explore in the future. Nice work
Refactored view for export recurring expenses endpoint and implemented export as JSON.