Combined the create and store URL, and the edit and update URL of the accounts to simplify the URL pattern settings, because they are handled by the same view now in the accounting application.

This commit is contained in:
依瑪貓 2020-08-14 00:51:09 +08:00
parent 21c9db396d
commit 0398fb609e
4 changed files with 3 additions and 7 deletions

View File

@ -70,7 +70,7 @@ First written: 2020/8/8
<i class="fas fa-chevron-circle-left"></i>
{{ _("Back")|force_escape }}
</a>
<a class="btn btn-primary" role="button" href="{% url "accounting:accounts.edit" account %}">
<a class="btn btn-primary" role="button" href="{% url "accounting:accounts.update" account %}">
<i class="fas fa-user-cog"></i>
{{ _("Settings")|force_escape }}
</a>

View File

@ -43,7 +43,7 @@ First written: 2020/8/8
</a>
</div>
<form id="account-form" action="{% if request.resolver_match.kwargs.account %}{% url "accounting:accounts.update" request.resolver_match.kwargs.account %}{% else %}{% url "accounting:accounts.store" %}{% endif %}" method="post">
<form id="account-form" action="{% if request.resolver_match.kwargs.account %}{% url "accounting:accounts.update" request.resolver_match.kwargs.account %}{% else %}{% url "accounting:accounts.create" %}{% endif %}" method="post">
{% csrf_token %}
<input id="all-account-url" type="hidden" value="{% url "accounting:api.accounts" %}" />
<input id="account-code-original" type="hidden" value="{% if request.resolver_match.kwargs.account %}{{ request.resolver_match.kwargs.account.code }}{% endif %}" />

View File

@ -93,12 +93,8 @@ urlpatterns = [
views.AccountListView.as_view(), name="accounts"),
path("accounts/create",
views.AccountFormView.as_view(), name="accounts.create"),
path("accounts/store",
views.AccountFormView.as_view(), name="accounts.store"),
path("accounts/<account:account>",
views.AccountView.as_view(), name="accounts.detail"),
path("accounts/<account:account>/edit",
views.AccountFormView.as_view(), name="accounts.edit"),
path("accounts/<account:account>/update",
views.AccountFormView.as_view(), name="accounts.update"),
path("accounts/<account:account>/delete",

View File

@ -1013,7 +1013,7 @@ class AccountFormView(FormView):
"""Returns the URL on error."""
user = self.get_object()
return reverse("accounting:accounts.create") if user is None\
else reverse("accounting:accounts.edit", args=(user,))
else reverse("accounting:accounts.update", args=(user,))
def get_object(self) -> Optional[Account]:
"""Returns the current object, or None on a create form."""