Commit cdb1602e authored by 江世峰's avatar 江世峰

asset:add assets_bulk

parent 80baecc8
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _
from rest_framework import viewsets, serializers,generics
from .models import AssetGroup, Asset, IDC, AssetExtend
from common.mixins import BulkDeleteApiMixin
from rest_framework_bulk import BulkListSerializer, BulkSerializerMixin
class AssetBulkUpdateSerializer(BulkSerializerMixin, serializers.ModelSerializer):
# group_display = serializers.SerializerMethodField()
# active_display = serializers.SerializerMethodField()
#groups = serializers.PrimaryKeyRelatedField(many=True, queryset=AssetGroup.objects.all())
class Meta(object):
model = Asset
list_serializer_class = BulkListSerializer
fields = ['id', 'is_active', 'hostname']
# def get_group_display(self, obj):
# return " ".join([group.name for group in obj.groups.all()])
#
# def get_active_display(self, obj):
# # TODO: user ative state
# return not (obj.is_expired and obj.is_active)
\ No newline at end of file
{% extends '_modal.html' %}
{% load i18n %}
{% block modal_id %}asset_bulk_update_modal{% endblock %}
{% block modal_class %}modal-lg{% endblock %}
{% block modal_title%}{% trans "Update Asset" %}{% endblock %}
{% block modal_body %}
{% load bootstrap %}
<p class="text-success text-center">{% trans "Hint: only change the field you want to update." %}</p>
<div class="ydxbd" id="ydxbd" style="display: block;">
<div>
<p id="tags_p">
<a href="/assets/asset-by-tag/5">
<span class="label label-default">三年质保(0)</span>
</a>
</p>
</div>
</div>
<form method="post" class="form-horizontal" action="" id="fm_asset_bulk_update">
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_role">{% trans "Role" %}</label>
<div class=" col-sm-9 col-lg-9 ">
<select class=" select2 form-control" id="id_role" name="role">
<option value="">---------</option>
<option value="Admin">{% trans "Admin" %}</option>
<option value="User">{% trans "User" %}</option>
</select>
</div>
</div>
<div class="form-group">
<label for="groups" class="col-sm-2 control-label">{% trans 'Groups' %}</label>
<div class="col-sm-9" id="select2-container">
<select name="groups" id="select2_groups" data-placeholder="{% trans 'Select Group' %}" class="select2 form-control m-b" multiple>
{% for group in groups %}
<option value="{{ group.id }}">{{ group.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-lg-9 col-sm-offset-2">
<div class="checkbox checkbox-success">
<input type="checkbox" name="enable_otp" checked id="id_enable_otp"><label for="id_enable_otp">{% trans 'Enable-OTP' %}</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_tags">标签集合</label>
<div class=" col-sm-9 col-lg-9 ">
<select multiple="multiple" class="select2 form-control" data-placeholder="Select asset tags" id="tags" name="tags">
<option value="1">物理机</option>
<option value="2">虚拟机</option>
<option value="3">数据库备份</option>
<option value="4">亦庄机房</option>
<option value="5">三年质保</option>
</select>
<p class="help-block">
最多5个标签,单个标签最长8个汉字,按回车确认
</p>
</div>
</div>
</form>
{% endblock %}
{% block modal_confirm_id %}btn_asset_bulk_update{% endblock %}
\ No newline at end of file
{% extends '_base_create_update.html' %}
{% load static %}
{% load bootstrap %}
{% load i18n %}
{% block form %}
<div class="hr-line-dashed"></div>
<div class="ydxbd" id="ydxbd" style="display: block;">
<div>
<p id="tags_p">
<a>
</a>
{% for f in form %}
<span class="label label-default">{{ f.hostname }}</span>
{% endfor %}
<a href="{% url 'assets:asset-list' %}" ><span class="label label-default">移除选择</span></a>
</p>
</div>
</div>
<div class="hr-line-dashed"></div>
<form action="" method="post" class="form-horizontal">
{% csrf_token %}
<div class="hr-line-dashed"></div>
{{ form.hostname|bootstrap_horizontal }}
{{ form.ip|bootstrap_horizontal }}
{{ form.port|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
{{ form.idc|bootstrap_horizontal }}
{{ form.groups|bootstrap_horizontal }}
{{ form.admin_user|bootstrap_horizontal }}
{{ form.system_users|bootstrap_horizontal }}
{{ form.tags|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="reset">{% trans 'Reset' %}</button>
<button id="submit_button" class="btn btn-primary" type="submit">{% trans 'Submit' %}</button>
</div>
</div>
</form>
{% endblock %}
{% block custom_foot_js %}
<script>
$(document).ready(function () {
$('.select2').select2();
$("#tags").select2({
tags: true,
maximumSelectionLength: 8, //最多能够选择的个数
closeOnSelect: false
});
})
</script>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment