Skip to content

Commit

Permalink
Merge 2b4700c into 060139f
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Jul 12, 2021
2 parents 060139f + 2b4700c commit eb5e54c
Show file tree
Hide file tree
Showing 49 changed files with 2,313 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pip-tools
pip-compile examples/requirements/${{ matrix.requirements }}.in
pip install -r examples/requirements/${{ matrix.requirements }}.txt
pip-compile examples/requirements/${{ matrix.requirements }}_and_flask.in
pip install -r examples/requirements/${{ matrix.requirements }}_and_flask.txt
pip-compile examples/requirements/test.in
pip install -r examples/requirements/test.txt
- name: Run Tests
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ profiler.py.prof
/examples/static/
/examples/django_example/project/db.sqlite3
/examples/django_example/project/static/
/examples/sqlalchemy_example/
/examples/sqlalchemy_example/admin/sample_db.sqlite

var/
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.3.2
-----
2021-07-13

- Add basic SQLAlchemy support.

0.3.1
-----
2021-07-01
Expand Down
46 changes: 46 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Prerequisites
- Core package requires Python 3.6, 3.7, 3.8 or 3.9.
- Django integration package (``valuta.contrib.django_integration``) requires
Django 2.2, 3.0, 3.1 or 3.2.
- SQLAlchemy integration package (``valuta.contrib.sqlalchemy_integration``)
has been tested with SQLAlchemy 1.4.x.

Documentation
=============
Expand Down Expand Up @@ -688,6 +690,50 @@ Sample template tags renderer
"template_tag_price_display_in_currency_units.html", {"instance": instance}
)
SQLAlchemy integration
----------------------
Similarly to Django integration package, the SQLAlchemy integration package is
a simple ``CurrencyType`` representing the ISO-4217 codes of the currencies.

No magic methods are implemented yet (although planned to). What you get
is a simple SQLAlchemy type for storing the data. For the rest you will have
to make use of the ``valuta.shortcuts``.

See `sqlalchemy-integration/examples/sqlalchemy_example/valuta_admin/models.py <https://github.com/barseghyanartur/valuta/blob/feature/sqlalchemy-integration/examples/sqlalchemy_example/valuta_admin/models.py#L50>`
as a good example.

Model definition
~~~~~~~~~~~~~~~~
**Sample model**

*product/models.py*

.. code-block:: python
from valuta.contrib.sqlalchemy_integration.types import CurrencyType
from . import db # Standard SQLAlchemy way
class Product(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(64), unique=True)
price = db.Column(db.Integer())
price_with_tax = db.Column(db.Integer())
currency = db.Column(CurrencyType())
**Sample data**

.. code-block:: python
import valuta
from product.models import Product
product = Product(
name="My test product",
price=100,
price_with_tax=120,
currency=valuta.AMD.uid,
)
Supported currencies
====================
Currencies marked with `(*)` are custom (added manually). The rest is obtained
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.3.2
-----
2021-07-13

- Add basic SQLAlchemy support.

0.3.1
-----
2021-07-01
Expand Down
46 changes: 46 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Prerequisites
- Core package requires Python 3.6, 3.7, 3.8 or 3.9.
- Django integration package (``valuta.contrib.django_integration``) requires
Django 2.2, 3.0, 3.1 or 3.2.
- SQLAlchemy integration package (``valuta.contrib.sqlalchemy_integration``)
has been tested with SQLAlchemy 1.4.x.

Documentation
=============
Expand Down Expand Up @@ -688,6 +690,50 @@ Sample template tags renderer
"template_tag_price_display_in_currency_units.html", {"instance": instance}
)
SQLAlchemy integration
----------------------
Similarly to Django integration package, the SQLAlchemy integration package is
a simple ``CurrencyType`` representing the ISO-4217 codes of the currencies.

No magic methods are implemented yet (although planned to). What you get
is a simple SQLAlchemy type for storing the data. For the rest you will have
to make use of the ``valuta.shortcuts``.

See `sqlalchemy-integration/examples/sqlalchemy_example/valuta_admin/models.py <https://github.com/barseghyanartur/valuta/blob/feature/sqlalchemy-integration/examples/sqlalchemy_example/valuta_admin/models.py#L50>`
as a good example.

Model definition
~~~~~~~~~~~~~~~~
**Sample model**

*product/models.py*

.. code-block:: python
from valuta.contrib.sqlalchemy_integration.types import CurrencyType
from . import db # Standard SQLAlchemy way
class Product(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(64), unique=True)
price = db.Column(db.Integer())
price_with_tax = db.Column(db.Integer())
currency = db.Column(CurrencyType())
**Sample data**

.. code-block:: python
import valuta
from product.models import Product
product = Product(
name="My test product",
price=100,
price_with_tax=120,
currency=valuta.AMD.uid,
)
Supported currencies
====================
Currencies marked with `(*)` are custom (added manually). The rest is obtained
Expand Down
4 changes: 4 additions & 0 deletions examples/django_example/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=====================================
Django example project for ``valuta``
=====================================
*Used to demonstrate admin features a well as for testing.*
48 changes: 24 additions & 24 deletions examples/requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# This file is autogenerated by pip-compile with python 3.6
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile examples/requirements/dev.in
# pip-compile dev.in
#
appdirs==1.4.4
# via virtualenv
Expand All @@ -11,7 +11,7 @@ asgiref==3.3.4
attrs==21.2.0
# via pytest
babel==2.9.1
# via -r examples/requirements/common.in
# via -r common.in
bleach==3.3.0
# via readme-renderer
certifi==2021.5.30
Expand All @@ -26,25 +26,25 @@ colorama==0.4.4
# via twine
coverage[toml]==5.5
# via
# -r examples/requirements/test.in
# -r test.in
# pytest-cov
cryptography==3.4.7
# via secretstorage
distlib==0.3.2
# via virtualenv
django-debug-toolbar==3.2.1
# via -r django_3_2.in
django==3.2.4
# via
# -r examples/requirements/django_3_2.in
# -r django_3_2.in
# django-debug-toolbar
django-debug-toolbar==3.2.1
# via -r examples/requirements/django_3_2.in
docutils==0.17.1
# via readme-renderer
factory_boy==2.11.1
# via -r examples/requirements/test.in
# via -r test.in
faker==8.1.4
# via
# -r examples/requirements/test.in
# -r test.in
# factory-boy
filelock==3.0.12
# via
Expand Down Expand Up @@ -80,7 +80,7 @@ packaging==20.9
pep517==0.10.0
# via pip-tools
pip-tools==6.1.0
# via -r examples/requirements/deployment.in
# via -r deployment.in
pkginfo==1.7.0
# via twine
pluggy==0.13.1
Expand All @@ -89,7 +89,7 @@ pluggy==0.13.1
# tox
py==1.10.0
# via
# -r examples/requirements/test.in
# -r test.in
# pytest
# tox
pycparser==2.20
Expand All @@ -98,21 +98,21 @@ pygments==2.9.0
# via readme-renderer
pyparsing==2.4.7
# via packaging
pytest-cov==2.12.0
# via -r test.in
pytest-django==4.3.0
# via -r test.in
pytest-ordering==0.6
# via -r test.in
pytest-pythonpath==0.7.3
# via -r test.in
pytest==6.2.4
# via
# -r examples/requirements/test.in
# -r test.in
# pytest-cov
# pytest-django
# pytest-ordering
# pytest-pythonpath
pytest-cov==2.12.0
# via -r examples/requirements/test.in
pytest-django==4.3.0
# via -r examples/requirements/test.in
pytest-ordering==0.6
# via -r examples/requirements/test.in
pytest-pythonpath==0.7.3
# via -r examples/requirements/test.in
python-dateutil==2.8.1
# via faker
pytz==2021.1
Expand All @@ -121,12 +121,12 @@ pytz==2021.1
# django
readme-renderer==29.0
# via twine
requests-toolbelt==0.9.1
# via twine
requests==2.25.1
# via
# requests-toolbelt
# twine
requests-toolbelt==0.9.1
# via twine
rfc3986==1.5.0
# via twine
secretstorage==3.3.1
Expand All @@ -151,11 +151,11 @@ toml==0.10.2
# pytest
# tox
tox==3.23.1
# via -r examples/requirements/test.in
# via -r test.in
tqdm==4.61.1
# via twine
twine==3.4.1
# via -r examples/requirements/deployment.in
# via -r deployment.in
typing-extensions==3.10.0.0
# via
# asgiref
Expand Down
6 changes: 6 additions & 0 deletions examples/requirements/django_2_2_and_flask.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-r common.in
-r test.in
-r flask.in

Django>=2.2,<3.0
django-debug-toolbar>=3.2,<3.3
Loading

0 comments on commit eb5e54c

Please sign in to comment.