Commit 806d38bb authored by yumaojun03's avatar yumaojun03

模拟数据测试

parent 84613e51
......@@ -29,6 +29,24 @@ class Tasker(models.Model):
def total_hosts(self):
return self.hosts.split(',')
@classmethod
def generate_fake(cls, count=100):
from random import seed
import forgery_py
from django.db import IntegrityError
seed()
for i in range(count):
group = cls(name=forgery_py.name.full_name(),
comment=forgery_py.lorem_ipsum.sentence(),
created_by='Fake')
try:
group.save()
logger.debug('Generate fake asset group: %s' % group.name)
except IntegrityError:
print('Error continue')
continue
class AnsiblePlay(models.Model):
tasker = models.ForeignKey(Tasker, related_name='plays', blank=True, null=True)
......
......@@ -78,11 +78,14 @@ class Sudo(models.Model):
:param privileges: <list> [(user, host, runas, command, nopassword),]
"""
name = models.CharField(max_length=128, unique=True, verbose_name=_('Name'),
help_text=_('Name for this sudo'))
created_by = models.CharField(max_length=32, blank=True, verbose_name=_('Created by'),
help_text=_('The create time of this sudo'))
assets = models.ManyToManyField(Asset, blank=True, related_name='sudos')
asset_groups = models.ManyToManyField(AssetGroup, blank=True, related_name='sudos')
extra_lines = models.ManyToManyField(Extra_conf, related_name='sudos', blank=True)
privilege_items = models.ManyToManyField(Privilege, related_name='sudos', blank=True)
created_by = models.CharField(max_length=32, blank=True, verbose_name=_('Created by'))
@property
def all_assets(self):
......
# ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals
from ansible import *
from cron import *
from sudo import *
def generate_fake():
for cls in (AssetGroup, IDC, AdminUser, SystemUser, Asset):
cls.generate_fake()
\ No newline at end of file
......@@ -5,7 +5,7 @@
{% block table_container %}
<div class="uc pull-left m-l-5 m-r-5"><a href="{% url "users:user-create" %}" class="btn btn-sm btn-primary"> {% trans "Create user" %} </a></div>
<div class="uc pull-left"><a href="javascript:void(0);" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#user_import_modal"> {% trans "Import user" %} </a></div>
<table class="table table-striped table-bordered table-hover " id="user_list_table" >
<table class="table table-striped table-bordered table-hover " id="sudo_list_table">
<thead>
<tr>
<th class="text-center">
......@@ -13,11 +13,9 @@
<input id="" type="checkbox" class="ipt_check_all">
</th>
<th class="text-center">{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Username' %}</th>
<th class="text-center">{% trans 'Role' %}</th>
<th class="text-center">{% trans 'User group' %}</th>
<th class="text-center">{% trans 'Active' %}</th>
<th class="text-center">{% trans 'Action' %}</th>
<th class="text-center">{% trans 'Privileges' %}</th>
<th class="text-center">{% trans 'Extra Lines' %}</th>
<th class="text-center">{% trans 'Created' %}</th>
</tr>
</thead>
<tbody>
......@@ -46,7 +44,7 @@
<script>
$(document).ready(function(){
var options = {
ele: $('#user_list_table'),
ele: $('#sudo_list_table'),
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
var detail_btn = '<a href="{% url "users:user-detail" pk=99991937 %}">' + cellData + '</a>';
......@@ -89,7 +87,7 @@ $(document).ready(function(){
}).on('click', '#btn_bulk_update', function(){
var action = $('#slct_bulk_update').val();
var $data_table = $('#user_list_table').DataTable();
var $data_table = $('#sudo_list_table').DataTable();
var id_list = [];
var plain_id_list = [];
$data_table.rows({selected: true}).every(function(){
......@@ -121,7 +119,7 @@ $(document).ready(function(){
var success = function() {
var msg = "{% trans 'User Deleted.' %}";
swal("{% trans 'User Delete' %}", msg, "success");
$('#user_list_table').DataTable().ajax.reload();
$('#sudo_list_table').DataTable().ajax.reload();
};
var fail = function() {
var msg = "{% trans 'User Deleting failed.' %}";
......@@ -157,7 +155,7 @@ $(document).ready(function(){
var success = function() {
var msg = "{% trans 'User Deleted.' %}";
swal("{% trans 'User Delete' %}", msg, "success");
$('#user_list_table').DataTable().ajax.reload();
$('#sudo_list_table').DataTable().ajax.reload();
};
var fail = function() {
var msg = "{% trans 'User Deleting failed.' %}";
......@@ -198,7 +196,7 @@ $(document).ready(function(){
new_groups = body.groups.map(Number);
body.groups = new_groups;
}
var $data_table = $('#user_list_table').DataTable()
var $data_table = $('#sudo_list_table').DataTable()
var post_list = [];
$data_table.rows({selected: true}).every(function(){
var content = Object.assign({id: this.data().id}, body);
......@@ -211,7 +209,7 @@ $(document).ready(function(){
var success = function() {
var msg = "{% trans 'The selected users has been updated successfully.' %}";
swal("{% trans 'User Updated' %}", msg, "success");
$('#user_list_table').DataTable().ajax.reload();
$('#sudo_list_table').DataTable().ajax.reload();
jumpserver.checked = false;
};
APIUpdateAttr({url: the_url, method: 'PATCH', body: JSON.stringify(post_list), success: success});
......@@ -225,7 +223,7 @@ $(document).ready(function(){
$('<span />', {class: 'help-block text-danger'}).html(data.msg).insertAfter($('#id_excel'));
} else {
$('#user_import_modal').modal('hide');
var $data_table = $('#user_list_table').DataTable();
var $data_table = $('#sudo_list_table').DataTable();
toastr.success("{% trans 'Import User Success.' %}");
$data_table.ajax.reload();
}
......
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