From c940a4c0fb882a49112c80ba9f196b401af45527 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 23 Mar 2017 00:15:25 +0800 Subject: [PATCH] =?UTF-8?q?[Fixture]=20=E5=A2=9E=E5=8A=A0=20task=20list=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/tasks.py | 3 +- apps/assets/templates/assets/asset_list.html | 38 +--------------- apps/ops/api.py | 15 ++++++ apps/ops/api/__init__.py | 1 - apps/ops/api/exc.py | 16 ------- apps/ops/api/permissions.py | 19 -------- apps/ops/api/serializers.py | 4 -- apps/ops/api/views.py | 7 --- apps/ops/hands.py | 4 ++ apps/ops/serializers.py | 13 ++++++ apps/ops/templates/ops/task_list.html | 48 ++++---------------- apps/ops/urls/api_urls.py | 8 +++- 12 files changed, 50 insertions(+), 126 deletions(-) create mode 100644 apps/ops/api.py delete mode 100644 apps/ops/api/__init__.py delete mode 100644 apps/ops/api/exc.py delete mode 100644 apps/ops/api/permissions.py delete mode 100644 apps/ops/api/serializers.py delete mode 100644 apps/ops/api/views.py create mode 100644 apps/ops/hands.py create mode 100644 apps/ops/serializers.py diff --git a/apps/assets/tasks.py b/apps/assets/tasks.py index 89e2e410e..b716dc644 100644 --- a/apps/assets/tasks.py +++ b/apps/assets/tasks.py @@ -12,8 +12,7 @@ def update_assets_hardware_info(assets): task_tuple = ( ('setup', ''), ) - task_name = ','.join([asset.hostname for asset in assets]) - summary, result = run_AdHoc(task_tuple, assets, record=True, task_name=task_name) + summary, result = run_AdHoc(task_tuple, assets, record=False) for hostname, info in result['contacted'].items(): if info: info = info[0]['ansible_facts'] diff --git a/apps/assets/templates/assets/asset_list.html b/apps/assets/templates/assets/asset_list.html index d12462cab..6641fb0e6 100644 --- a/apps/assets/templates/assets/asset_list.html +++ b/apps/assets/templates/assets/asset_list.html @@ -104,37 +104,6 @@ function tagShow() { } } //onload; -function objDelete(obj, name, url) { - function doDelete() { - 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 + "] ", - type: "warning", - showCancelButton: true, - cancelButtonText: 'Cancel', - confirmButtonColor: "#DD6B55", - confirmButtonText: 'Confirm', - closeOnConfirm: false - }, function () { - doDelete() - }); -} $(document).ready(function(){ var options = { @@ -214,15 +183,10 @@ $(document).ready(function(){ .on('click', '.btn_asset_delete', function () { var $this = $(this); - var $data_table = $("#asset_list_table").DataTable(); var name = $(this).closest("tr").find(":nth-child(2)").children('a').html(); var uid = $this.data('uid'); var the_url = '{% url "api-assets:asset-detail" pk=99991937 %}'.replace('99991937', uid); - console.log(the_url); - objDelete($this, name, the_url); - setTimeout( function () { - $data_table.ajax.reload(); - }, 3000); + objectDelete($this, name, the_url); }) .on('click', '#btn_bulk_update', function () { diff --git a/apps/ops/api.py b/apps/ops/api.py new file mode 100644 index 000000000..3a9e45b25 --- /dev/null +++ b/apps/ops/api.py @@ -0,0 +1,15 @@ +# ~*~ coding: utf-8 ~*~ + + +from rest_framework import viewsets + +from .hands import IsSuperUser +from .models import Task +from .serializers import TaskSerializer + + +class TaskViewSet(viewsets.ModelViewSet): + queryset = Task.objects.all() + serializer_class = TaskSerializer + permission_classes = (IsSuperUser,) + diff --git a/apps/ops/api/__init__.py b/apps/ops/api/__init__.py deleted file mode 100644 index c8b15abe0..000000000 --- a/apps/ops/api/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from views import * \ No newline at end of file diff --git a/apps/ops/api/exc.py b/apps/ops/api/exc.py deleted file mode 100644 index 81deb805c..000000000 --- a/apps/ops/api/exc.py +++ /dev/null @@ -1,16 +0,0 @@ -# ~*~ coding: utf-8 ~*~ -from __future__ import unicode_literals, print_function - -from rest_framework.exceptions import APIException -from django.utils.translation import ugettext as _ - - -class ServiceUnavailable(APIException): - status_code = default_code = 503 - default_detail = _('Service temporarily unavailable, try again later.') - - -class ServiceNotImplemented(APIException): - status_code = default_code = 501 - default_detail = _('This service maybe implemented in the future, but now not implemented!') - diff --git a/apps/ops/api/permissions.py b/apps/ops/api/permissions.py deleted file mode 100644 index 0fc0d0861..000000000 --- a/apps/ops/api/permissions.py +++ /dev/null @@ -1,19 +0,0 @@ -# ~*~ coding: utf-8 ~*~ -from __future__ import unicode_literals - -from rest_framework import permissions - - -class AdminUserRequired(permissions.BasePermission): - """ - Custom permission to only allow admin user to access the resource. - """ - - def has_object_permission(self, request, view, obj): - # Read permissions are allowed to any request, - # so we'll always allow GET, HEAD or OPTIONS requests. - if request.method in permissions.SAFE_METHODS: - return True - - # Write permissions are only allowed to the admin role. - return request.user.is_staff diff --git a/apps/ops/api/serializers.py b/apps/ops/api/serializers.py deleted file mode 100644 index af472b3cb..000000000 --- a/apps/ops/api/serializers.py +++ /dev/null @@ -1,4 +0,0 @@ -# ~*~ coding: utf-8 ~*~ -from __future__ import unicode_literals - - diff --git a/apps/ops/api/views.py b/apps/ops/api/views.py deleted file mode 100644 index affa9cdc7..000000000 --- a/apps/ops/api/views.py +++ /dev/null @@ -1,7 +0,0 @@ -# ~*~ coding: utf-8 ~*~ -from __future__ import unicode_literals -from rest_framework import viewsets - -from serializers import * -from permissions import * - diff --git a/apps/ops/hands.py b/apps/ops/hands.py new file mode 100644 index 000000000..d7175db18 --- /dev/null +++ b/apps/ops/hands.py @@ -0,0 +1,4 @@ +# ~*~ coding: utf-8 ~*~ + +from users.permissions import IsSuperUser + diff --git a/apps/ops/serializers.py b/apps/ops/serializers.py new file mode 100644 index 000000000..986ee66e6 --- /dev/null +++ b/apps/ops/serializers.py @@ -0,0 +1,13 @@ +# ~*~ coding: utf-8 ~*~ +from __future__ import unicode_literals +from rest_framework import serializers + +from .models import Task + + +class TaskSerializer(serializers.ModelSerializer): + class Meta: + model = Task + fields = '__all__' + + diff --git a/apps/ops/templates/ops/task_list.html b/apps/ops/templates/ops/task_list.html index cb64849a4..dac614805 100644 --- a/apps/ops/templates/ops/task_list.html +++ b/apps/ops/templates/ops/task_list.html @@ -35,7 +35,7 @@ {% endblock %} {% block table_head %} - + {% trans 'Name' %} {% trans 'Asset' %} {% trans 'Success' %} @@ -69,6 +69,7 @@ {{ object.timedelta }} s {% trans "Run again" %} + {% trans "Delete" %} {% endfor %} @@ -92,45 +93,14 @@ forceParse: false, autoclose: true }); + + }).on('click', '.btn-del', function () { + var $this = $(this); + var name = $(this).closest("tr").find(":nth-child(2)").children('a').html(); + var uid = $this.data('uid'); + var the_url = '{% url "api-ops:task-detail" pk=99991937 %}'.replace('99991937', uid); + objectDelete($this, name, the_url); }) -{# function terminateConnection(data) {#} -{# function success() {#} -{# window.setTimeout(function () {#} -{# window.location.reload()#} -{# }, 300)#} -{# }#} -{# var the_url = "{% url 'api-applications:terminate-connection' %}";#} -{# APIUpdateAttr({url: the_url, method: 'POST', body: JSON.stringify(data), success: success, success_message: 'Terminate success'});#} -{# }#} -{# $(document).ready(function() {#} -{# $('table').DataTable({#} -{# "searching": false,#} -{# "paging": false,#} -{# "bInfo" : false,#} -{# "order": []#} -{# });#} -{# $('.select2').select2();#} -{# $('#date .input-daterange').datepicker({#} -{# dateFormat: 'mm/dd/yy',#} -{# keyboardNavigation: false,#} -{# forceParse: false,#} -{# autoclose: true#} -{# });#} -{# }).on('click', '.btn-term', function () {#} -{# var $this = $(this);#} -{# var proxy_log_id = $this.attr('value');#} -{# var data = {#} -{# proxy_log_id: proxy_log_id#} -{# };#} -{# terminateConnection(data)#} -{# }).on('click', '#btn_bulk_update', function () {#} -{# var data = [];#} -{# $('.cbx-term:checked').each(function () {#} -{# data.push({proxy_log_id: $(this).attr('value')})#} -{# });#} -{# terminateConnection(data)#} -{# })#} -{# #} {% endblock %} diff --git a/apps/ops/urls/api_urls.py b/apps/ops/urls/api_urls.py index d97d28a4a..c96bfb926 100644 --- a/apps/ops/urls/api_urls.py +++ b/apps/ops/urls/api_urls.py @@ -2,6 +2,12 @@ from __future__ import unicode_literals from rest_framework.routers import DefaultRouter +from .. import api -urlpatterns = [] \ No newline at end of file +router = DefaultRouter() +router.register(r'v1/tasks', api.TaskViewSet, 'task') + +urlpatterns = [] + +urlpatterns += router.urls -- GitLab