Skip to content
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

Merged
merged 1 commit into from
Oct 12, 2023
Merged

Conversation

abhinna1
Copy link
Contributor

Refactored view for export recurring expenses endpoint and implemented export as JSON.

Copy link
Owner

@iokiwi iokiwi left a 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 %}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this!

Comment on lines +170 to +172
for expense in expenses:
amount_nzd = (1 / fx_rates[expense.currency]) * float(expense.amount)
expense.amount_nzd = amount_nzd
Copy link
Owner

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

Comment on lines +199 to +200
if export_format not in _EXPORT_FORMATS:
return HttpResponse(status=204)
Copy link
Owner

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

@iokiwi iokiwi merged commit 49c7e28 into iokiwi:main Oct 12, 2023
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants