From bb9a067293703525d34369e295e17de97e37fcf7 Mon Sep 17 00:00:00 2001
From: ibuler <ibuler@qq.com>
Date: Wed, 19 Oct 2016 01:05:28 +0800
Subject: [PATCH] Finish command log

---
 apps/audits/api.py         | 6 ++++--
 apps/audits/models.py      | 6 +++---
 apps/audits/serializers.py | 3 +--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/apps/audits/api.py b/apps/audits/api.py
index 7a86156f0..4801c2e5e 100644
--- a/apps/audits/api.py
+++ b/apps/audits/api.py
@@ -6,7 +6,7 @@ from rest_framework import generics
 
 import serializers
 
-from .models import ProxyLog
+from .models import ProxyLog, CommandLog
 from .hands import IsSuperUserOrTerminalUser, Terminal
 
 
@@ -45,5 +45,7 @@ class ProxyLogDetailApi(generics.RetrieveUpdateDestroyAPIView):
     permission_classes = (IsSuperUserOrTerminalUser,)
 
 
-class CommandLogCreateApi(generics.CreateAPIView):
+class CommandLogCreateApi(generics.ListCreateAPIView):
+    queryset = CommandLog.objects.all()
     serializer_class = serializers.CommandLogSerializer
+    permission_classes = (IsSuperUserOrTerminalUser,)
diff --git a/apps/audits/models.py b/apps/audits/models.py
index 76d086810..29cd7b981 100644
--- a/apps/audits/models.py
+++ b/apps/audits/models.py
@@ -60,14 +60,14 @@ class ProxyLog(models.Model):
 
 class CommandLog(models.Model):
     proxy_log = models.ForeignKey(ProxyLog, on_delete=models.CASCADE, related_name='command_log')
+    command_no = models.IntegerField()
     command = models.CharField(max_length=1000, blank=True)
     output = models.TextField(blank=True)
-    date_start = models.DateTimeField(null=True)
-    date_finished = models.DateTimeField(null=True)
+    datetime = models.DateTimeField(null=True)
 
     def __unicode__(self):
         return '%s: %s' % (self.id, self.command)
 
     class Meta:
         db_table = 'command_log'
-        ordering = ['-date_start', 'command']
+        ordering = ['command_no', 'command']
diff --git a/apps/audits/serializers.py b/apps/audits/serializers.py
index 74adc8ee0..97be972ae 100644
--- a/apps/audits/serializers.py
+++ b/apps/audits/serializers.py
@@ -16,5 +16,4 @@ class CommandLogSerializer(serializers.ModelSerializer):
         model = models.CommandLog
 
 
-if __name__ == '__main__':
-    pass
+