Update some bug

pull/530/head
ibuler 2016-10-24 19:32:53 +08:00
parent 6b161d5971
commit 6a510dad6c
8 changed files with 65 additions and 37 deletions

View File

@ -146,7 +146,7 @@
"aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0 ] }],
"bAutoWidth": false,
"language": {
"url": "/static/js/plugins/dataTables/i18n/zh-hans.json"
"url": "/static/js/plugins/dataTables/i18n/zh-hans.json"
},
columns: [
{data: "checkbox"},

View File

@ -74,8 +74,6 @@ class AssetCreateView(AdminUserRequiredMixin,CreateAssetTagsMiXin,CreateView):
return super(AssetCreateView, self).get_context_data(**kwargs)
class AssetUpdateView(AdminUserRequiredMixin,UpdateAssetTagsMiXin,UpdateView):
model = Asset
form_class = AssetCreateForm
@ -118,13 +116,13 @@ class AssetDetailView(DetailView):
kwargs.update(context)
return super(AssetDetailView, self).get_context_data(**kwargs)
class AssetModalListView(AdminUserRequiredMixin, ListView):
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
model = Asset
context_object_name = 'asset_modal_list'
template_name = 'assets/asset_modal_list.html'
def get_context_data(self, **kwargs):
group_id = self.request.GET.get('group_id')
tag_id = self.request.GET.get('tag_id')
@ -142,6 +140,7 @@ class AssetModalListView(AdminUserRequiredMixin, ListView):
kwargs.update(context)
return super(AssetModalListView, self).get_context_data(**kwargs)
class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
model = AssetGroup
form_class = AssetGroupForm
@ -160,7 +159,6 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
kwargs.update(context)
return super(AssetGroupCreateView, self).get_context_data(**kwargs)
def form_valid(self, form):
asset_group = form.save()
assets_id_list = self.request.POST.getlist('assets', [])
@ -170,6 +168,7 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
asset_group.save()
return super(AssetGroupCreateView, self).form_valid(form)
class AssetGroupListView(AdminUserRequiredMixin, ListView):
model = AssetGroup
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
@ -218,6 +217,7 @@ class AssetGroupDetailView(SingleObjectMixin, AdminUserRequiredMixin, ListView):
kwargs.update(context)
return super(AssetGroupDetailView, self).get_context_data(**kwargs)
class AssetGroupUpdateView(AdminUserRequiredMixin, UpdateView):
model = AssetGroup
form_class = AssetGroupForm
@ -296,6 +296,7 @@ class IDCCreateView(AdminUserRequiredMixin, CreateView):
# IDC_add_success_next(user)
return super(IDCCreateView, self).form_valid(form)
class IDCUpdateView(AdminUserRequiredMixin, UpdateView):
model = IDC
form_class = IDCForm
@ -327,7 +328,6 @@ class IDCDeleteView(AdminUserRequiredMixin, DeleteView):
success_url = reverse_lazy('assets:idc-list')
class AdminUserListView(AdminUserRequiredMixin, ListView):
model = AdminUser
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE

View File

@ -197,7 +197,7 @@ function APIUpdateAttr(props) {
type: props.method || "PATCH",
data: props.body,
contentType: props.content_type || "application/json; charset=utf-8",
dataType: props.data_type || "json",
dataType: props.data_type || "json"
}).done(function(data, textStatue, jqXHR) {
if (typeof props.success === 'function') {
return props.success(data);
@ -215,28 +215,37 @@ function APIUpdateAttr(props) {
}
// Sweet Alert for Delete
function objectDelete(obj, name, url){
function objectDelete(obj, name, url) {
var $this = $(this);
function doDelete() {
var uid = $this.data('uid');
var body = {};
var success = function() {
swal('Deleted!', "[ "+name+"]"+" has been deleted ", "success");
$(obj).parent().parent().remove();
};
var fail = function() {
swal("Failed", "Delete"+"[ "+name+" ]"+"failed", "error");
};
APIUpdateAttr({
url: url,
body: JSON.stringify(body),
method: 'DELETE',
success: success,
error: fail
});
}
swal({
title: 'Are you sure delete ?',
text: "【" + name + "】",
text: " [" + name + "] ",
type: "warning",
showCancelButton: true,
cancelButtonText: 'Cancel',
confirmButtonColor: "#DD6B55",
confirmButtonText: 'Yes, delete it!',
confirmButtonText: 'Confirm',
closeOnConfirm: false
}, function () {
$.ajax({
type : "post",
url : url,
data : {
},
dataType : "text",
success : function(data) {
swal('Deleted!' , "【"+name+"】"+"has been deleted.", "success");
$(obj).parent().parent().remove();
}
});
doDelete()
});
}
@ -279,7 +288,7 @@ jumpserver.initDataTable = function (options) {
$(td).html('<div class="checkbox checkbox-default"><input type="checkbox" class="ipt_check"><label></label></div>');
}
},
{className: 'text-center', targets: '_all'},
{className: 'text-center', targets: '_all'}
];
columnDefs = options.columnDefs ? options.columnDefs.concat(columnDefs) : columnDefs;
var table = ele.DataTable({
@ -342,6 +351,6 @@ jumpserver.initDataTable = function (options) {
jumpserver.checked = false;
table.rows().deselect();
}
})
});
return table;
}
};

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
from rest_framework.generics import ListCreateAPIView, CreateAPIView
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView
from rest_framework.views import APIView, Response
from rest_framework.permissions import AllowAny
@ -18,7 +18,6 @@ class TerminalCreateListApi(ListCreateAPIView):
def post(self, request, *args, **kwargs):
name = unsign(request.data.get('name', ''))
print(name)
if name:
terminal = get_object_or_none(Terminal, name=name)
if terminal:
@ -36,12 +35,18 @@ class TerminalCreateListApi(ListCreateAPIView):
terminal = Terminal.objects.create(name=name, ip=ip)
return Response(data={'data': {'name': name, 'ip': terminal.ip},
'msg': 'Need admin active it'},
status=204)
status=201)
else:
return Response(data={'msg': 'Secrete key invalid'}, status=401)
class TerminalHeatbeatApi(CreateAPIView):
class TerminalHeatbeatApi(ListCreateAPIView):
model = TerminalHeatbeat
serializer_class = TerminalHeatbeatSerializer
permission_classes = (IsSuperUserOrTerminalUser,)
class TerminalApiDetailUpdateDetailApi(RetrieveUpdateDestroyAPIView):
queryset = Terminal.objects.all()
serializer_class = TerminalSerializer
permission_classes = (IsSuperUserOrTerminalUser,)

View File

@ -47,10 +47,6 @@ $(document).ready(function(){
var detail_btn = '<a href="{% url "users:user-detail" pk=99991937 %}">' + cellData + '</a>';
$(td).html(detail_btn.replace('99991937', rowData.id));
}},
{targets: 4, createdCell: function (td, cellData) {
var innerHtml = cellData.length > 8 ? cellData.substring(0, 8) + '...': cellData;
$(td).html('<a href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</a>');
}},
{targets: 5, createdCell: function (td, cellData) {
if (!cellData) {
$(td).html('<i class="fa fa-times text-danger"></i>')
@ -59,9 +55,13 @@ $(document).ready(function(){
}
}},
{targets: 6, createdCell: function (td, cellData, rowData) {
var update_btn = '<a href="{% url "terminal:terminal-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('99991937', cellData);
var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'.replace('99991937', cellData);
$(td).html(update_btn + del_btn)
console.log(rowData.name);
var update_btn = '<a href="{% url "terminal:terminal-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.replace('99991937', cellData);
var delete_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_delete" data-uid="99991937" data-name="99991938">{% trans "Delete" %}</a>'
.replace('99991937', cellData)
.replace('99991938', rowData.name);
$(td).html(update_btn + delete_btn)
}}
],
ajax_url: '{% url "terminal:terminal-list-create-api" %}',
@ -70,6 +70,12 @@ $(document).ready(function(){
op_html: $('#actions').html()
};
jumpserver.initDataTable(options);
}).on('click', '.btn_delete', function(){
var $this = $(this);
var uid = $this.data('uid');
var name = $(this).data('name');
var the_url = '{% url "terminal:terminal-detail-update-delete-api" pk=99991937 %}'.replace('99991937', uid);
objectDelete($this, name, the_url)
})
</script>
{% endblock %}

View File

@ -16,5 +16,7 @@ urlpatterns = [
urlpatterns += [
url(r'^v1/terminal/$', api.TerminalCreateListApi.as_view(), name='terminal-list-create-api'),
url(r'^v1/terminal/(?P<pk>\d+)/$', api.TerminalApiDetailUpdateDetailApi.as_view(),
name='terminal-detail-update-delete-api'),
url(r'^v1/terminal-heatbeat/$', api.TerminalHeatbeatApi.as_view(), name='terminal-heatbeat-api'),
]

View File

@ -1,7 +1,7 @@
# ~*~ coding: utf-8 ~*~
#
from django.views.generic import ListView, UpdateView
from django.views.generic import ListView, UpdateView, DeleteView
from django.utils.translation import ugettext as _
from django.urls import reverse_lazy
@ -29,3 +29,9 @@ class TerminalUpdateView(UpdateView):
context = super(TerminalUpdateView, self).get_context_data(**kwargs)
context.update({'app': _('Terminal'), 'action': _('Update terminal')})
return context
class TerminalDeleteView(DeleteView):
model = Terminal
template_name = 'assets/delete_confirm.html'
success_url = reverse_lazy('terminal:terminal-list')

View File

@ -41,7 +41,7 @@ class TerminalAuthentication(authentication.BaseAuthentication):
else:
raise exceptions.AuthenticationFailed(_('Invalid sign.'))
if not terminal.is_active:
if not terminal or not terminal.is_active:
raise exceptions.AuthenticationFailed(_('Terminal inactive or deleted.'))
terminal.is_authenticated = True
return terminal, None