[Update] 创建/更新 用户组使用api (#2914)

* [Update] 创建/更新 用户组使用api

* [Update] 修改小问题
pull/2938/head
八千流 2019-07-11 18:17:47 +08:00 committed by BaiJiangJie
parent 5f9f970abd
commit 4e3e166132
2 changed files with 23 additions and 0 deletions

View File

@ -47,5 +47,26 @@ $(document).ready(function () {
closeOnSelect: false
});
})
.on("submit", "form", function (evt) {
evt.preventDefault();
var the_url = '{% url 'api-users:user-group-list' %}';
var redirect_to = '{% url "users:user-group-list" %}';
var method = "POST";
{% if type == "update" %}
the_url = '{% url 'api-users:user-group-detail' pk=object.id %}';
method = "PUT";
{% endif %}
var form = $("form");
var data = form.serializeObject();
objectAttrsIsList(data, ['users']);
var props = {
url: the_url,
data: data,
method: method,
form: form,
redirect_to: redirect_to
};
formSubmit(props);
})
</script>
{% endblock %}

View File

@ -44,6 +44,7 @@ class UserGroupCreateView(PermissionsMixin, SuccessMessageMixin, CreateView):
context = {
'app': _('Users'),
'action': _('Create user group'),
'type': 'create'
}
kwargs.update(context)
return super().get_context_data(**kwargs)
@ -61,6 +62,7 @@ class UserGroupUpdateView(PermissionsMixin, SuccessMessageMixin, UpdateView):
context = {
'app': _('Users'),
'action': _('Update user group'),
'type': 'update'
}
kwargs.update(context)