Added AccountConverter and apply it to the URL patterns in the accounting application.
This commit is contained in:
parent
3b522af41b
commit
1a2bada988
@ -108,6 +108,36 @@ class DateConverter:
|
|||||||
return value.strftime("%Y-%m-%d")
|
return value.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
|
class AccountConverter:
|
||||||
|
"""The path converter for the account."""
|
||||||
|
regex = "[1-9]{1,5}"
|
||||||
|
|
||||||
|
def to_python(self, value):
|
||||||
|
"""Returns the account by the account code.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (str): The account code.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Account: The account.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return Account.objects.get(code=value)
|
||||||
|
except Account.DoesNotExist:
|
||||||
|
raise ValueError
|
||||||
|
|
||||||
|
def to_url(self, value):
|
||||||
|
"""Returns the code of an account.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (Account): The account.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The account code.
|
||||||
|
"""
|
||||||
|
return value.code
|
||||||
|
|
||||||
|
|
||||||
class CashAccountConverter:
|
class CashAccountConverter:
|
||||||
"""The path converter for the cash account."""
|
"""The path converter for the cash account."""
|
||||||
regex = "0|(11|12|21|22)[1-9]{1,3}"
|
regex = "0|(11|12|21|22)[1-9]{1,3}"
|
||||||
|
@ -28,6 +28,7 @@ from mia_core.digest_auth import login_required
|
|||||||
from . import converters, views
|
from . import converters, views
|
||||||
|
|
||||||
register_converter(converters.PeriodConverter, "period")
|
register_converter(converters.PeriodConverter, "period")
|
||||||
|
register_converter(converters.AccountConverter, "account")
|
||||||
register_converter(converters.CashAccountConverter, "cash-account")
|
register_converter(converters.CashAccountConverter, "cash-account")
|
||||||
register_converter(converters.LedgerAccountConverter, "ledger-account")
|
register_converter(converters.LedgerAccountConverter, "ledger-account")
|
||||||
register_converter(converters.TransactionTypeConverter, "txn-type")
|
register_converter(converters.TransactionTypeConverter, "txn-type")
|
||||||
@ -91,7 +92,7 @@ urlpatterns = [
|
|||||||
views.txn_sort, name="transactions.sort"),
|
views.txn_sort, name="transactions.sort"),
|
||||||
# TODO: To be done
|
# TODO: To be done
|
||||||
path("accounts",
|
path("accounts",
|
||||||
mia_core_views.todo, name="accounts"),
|
views.AccountListView.as_view(), name="accounts"),
|
||||||
# TODO: To be done
|
# TODO: To be done
|
||||||
path("accounts/create",
|
path("accounts/create",
|
||||||
mia_core_views.todo, name="accounts.create"),
|
mia_core_views.todo, name="accounts.create"),
|
||||||
@ -101,15 +102,15 @@ urlpatterns = [
|
|||||||
path("accounts/options",
|
path("accounts/options",
|
||||||
views.account_options, name="accounts.options"),
|
views.account_options, name="accounts.options"),
|
||||||
# TODO: To be done
|
# TODO: To be done
|
||||||
path("accounts/<str:account_code>",
|
path("accounts/<account:account>",
|
||||||
mia_core_views.todo, name="accounts.show"),
|
mia_core_views.todo, name="accounts.show"),
|
||||||
# TODO: To be done
|
# TODO: To be done
|
||||||
path("accounts/<str:account_code>/edit",
|
path("accounts/<account:account>/edit",
|
||||||
mia_core_views.todo, name="accounts.edit"),
|
mia_core_views.todo, name="accounts.edit"),
|
||||||
# TODO: To be done
|
# TODO: To be done
|
||||||
path("accounts/<str:account_code>/update",
|
path("accounts/<account:account>/update",
|
||||||
mia_core_views.todo, name="accounts.update"),
|
mia_core_views.todo, name="accounts.update"),
|
||||||
# TODO: To be done
|
# TODO: To be done
|
||||||
path("accounts/<str:account_code>/delete",
|
path("accounts/<account:account>/delete",
|
||||||
mia_core_views.todo, name="accounts.delete"),
|
mia_core_views.todo, name="accounts.delete"),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user