mirror of https://github.com/jumpserver/jumpserver
[Update] 创建/更新 标签 使用api (#2919)
* [Update] 创建/更新 标签 使用api * [Update] 修改小问题 * [Update] 修改小问题pull/2932/head
parent
63f3fa98db
commit
95f1a19a0a
|
@ -13,7 +13,13 @@ class LabelSerializer(BulkOrgResourceModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Label
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
'id', 'name', 'value', 'category', 'is_active', 'comment',
|
||||
'date_created', 'asset_count', 'assets', 'get_category_display'
|
||||
]
|
||||
read_only_fields = (
|
||||
'category', 'date_created', 'asset_count', 'get_category_display'
|
||||
)
|
||||
list_serializer_class = AdaptedBulkListSerializer
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -51,5 +51,26 @@ $(document).ready(function () {
|
|||
$('#id_assets').val(assets).trigger('change');
|
||||
$("#asset_list_modal").modal('hide');
|
||||
})
|
||||
.on("submit", "form", function (evt) {
|
||||
evt.preventDefault();
|
||||
var the_url = '{% url 'api-assets:label-list' %}';
|
||||
var redirect_to = '{% url "assets:label-list" %}';
|
||||
var method = "POST";
|
||||
{% if type == "update" %}
|
||||
the_url = '{% url 'api-assets:label-detail' pk=object.id %}';
|
||||
method = "PUT";
|
||||
{% endif %}
|
||||
var form = $("form");
|
||||
var data = form.serializeObject();
|
||||
objectAttrsIsList(data, ['assets']);
|
||||
var props = {
|
||||
url: the_url,
|
||||
data: data,
|
||||
method: method,
|
||||
form: form,
|
||||
redirect_to: redirect_to
|
||||
};
|
||||
formSubmit(props);
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -44,6 +44,7 @@ class LabelCreateView(PermissionsMixin, CreateView):
|
|||
context = {
|
||||
'app': _('Assets'),
|
||||
'action': _('Create label'),
|
||||
'type': 'create'
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
@ -71,6 +72,7 @@ class LabelUpdateView(PermissionsMixin, UpdateView):
|
|||
context = {
|
||||
'app': _('Assets'),
|
||||
'action': _('Update label'),
|
||||
'type': 'update'
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
|
Loading…
Reference in New Issue