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

This commit is contained in:
依瑪貓 2020-08-14 00:53:10 +08:00
parent 0398fb609e
commit c353e17db2
4 changed files with 3 additions and 5 deletions

View File

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

View File

@ -42,7 +42,7 @@ First written: 2020/8/9
</a> </a>
</div> </div>
<form id="user-form" action="{% if request|is_in_section:"mia_core:my-account" %}{% url "mia_core:my-account.update" %}{% elif form.user %}{% url "mia_core:users.update" form.user %}{% else %}{% url "mia_core:users.store" %}{% endif %}" method="POST"> <form id="user-form" action="{% if request|is_in_section:"mia_core:my-account" %}{% url "mia_core:my-account.update" %}{% elif form.user %}{% url "mia_core:users.update" form.user %}{% else %}{% url "mia_core:users.create" %}{% endif %}" method="POST">
{% csrf_token %} {% csrf_token %}
<input id="exists-url" type="hidden" value="{% url "mia_core:api.users.exists" "ID" %}" /> <input id="exists-url" type="hidden" value="{% url "mia_core:api.users.exists" "ID" %}" />
<input id="user-login-id-original" type="hidden" value="{{ form.user.login_id }}" /> <input id="user-login-id-original" type="hidden" value="{{ form.user.login_id }}" />

View File

@ -32,9 +32,7 @@ urlpatterns = [
path("logout", views.logout, name="logout"), path("logout", views.logout, name="logout"),
path("users", views.UserListView.as_view(), name="users"), path("users", views.UserListView.as_view(), name="users"),
path("users/create", views.UserFormView.as_view(), name="users.create"), path("users/create", views.UserFormView.as_view(), name="users.create"),
path("users/store", views.UserFormView.as_view(), name="users.store"),
path("users/<user:user>", views.UserView.as_view(), name="users.detail"), path("users/<user:user>", views.UserView.as_view(), name="users.detail"),
path("users/<user:user>/edit", views.UserFormView.as_view(), name="users.edit"),
path("users/<user:user>/update", views.UserFormView.as_view(), name="users.update"), path("users/<user:user>/update", views.UserFormView.as_view(), name="users.update"),
path("users/<user:user>/delete", views.user_delete, name="users.delete"), path("users/<user:user>/delete", views.user_delete, name="users.delete"),
path("api/users/<str:login_id>/exists", views.api_users_exists, path("api/users/<str:login_id>/exists", views.api_users_exists,

View File

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