Skip to content

Commit

Permalink
add currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
madisvain committed Dec 28, 2023
1 parent 2e66d43 commit 19d891d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apscheduler
babel
django
django-cors-headers
gunicorn
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ anyio==4.2.0
APScheduler==3.10.4
asgiref==3.7.2
attrs==23.1.0
Babel==2.14.0
certifi==2023.11.17
charset-normalizer==3.3.2
click==8.1.7
Expand Down
13 changes: 13 additions & 0 deletions vatcomply/tests/test_currencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.conf import settings
from django.test import TestCase
from django.core.management import call_command

from vatcomply.models import Country


class CurrenciesTest(TestCase):
def test_currencies_api(self):
response = self.client.get("/currencies")
self.assertEqual(response.status_code, 200)
self.assertIsInstance(response.json(), dict)
self.assertEqual(len(response.json()), len(settings.CURRENCY_SYMBOLS))
3 changes: 2 additions & 1 deletion vatcomply/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# from django.contrib import admin
from django.urls import path

from vatcomply.views import CountriesView, GeolocateView, RatesView, VATView
from vatcomply.views import CountriesView, CurrenciesView, GeolocateView, RatesView, VATView


urlpatterns = [
# path("admin/", admin.site.urls),
# API
path("countries", CountriesView.as_view()),
path("currencies", CurrenciesView.as_view()),
path("geolocate", GeolocateView.as_view()),
path("vat", VATView.as_view()),
path("rates", RatesView.as_view()),
Expand Down
13 changes: 13 additions & 0 deletions vatcomply/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pendulum
import zeep
from babel.numbers import get_currency_name, get_currency_symbol
from django.conf import settings
from django.utils.decorators import method_decorator
from django.views import View
Expand Down Expand Up @@ -39,6 +40,18 @@ async def get(self, request):
return JsonResponse(countries)


@method_decorator(csrf_exempt, name="dispatch")
class CurrenciesView(View):
async def get(self, request):
currencies = {}
for symbol in list(settings.CURRENCY_SYMBOLS):
currencies[symbol] = {
"name": get_currency_name(symbol, locale="en"),
"symbol": get_currency_symbol(symbol, locale="en"),
}
return JsonResponse(currencies)


@method_decorator(csrf_exempt, name="dispatch")
class GeolocateView(View):
async def get(self, request):
Expand Down

1 comment on commit 19d891d

@vercel
Copy link

@vercel vercel bot commented on 19d891d Dec 28, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.