2017-02-06 15:13:27 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
|
|
|
import base64
|
|
|
|
from rest_framework import serializers
|
|
|
|
from audits.models import CommandLog
|
|
|
|
from audits.backends import command_store
|
|
|
|
|
|
|
|
|
|
|
|
class CommandLogSerializer(serializers.ModelSerializer):
|
|
|
|
"""使用这个类作为基础Command Log Serializer类, 用来序列化"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = CommandLog
|
|
|
|
fields = '__all__'
|
|
|
|
|
2017-02-07 13:51:44 +00:00
|
|
|
def create(self, validated_data):
|
2017-02-06 15:13:27 +00:00
|
|
|
try:
|
2017-02-07 13:51:44 +00:00
|
|
|
output = validated_data['output']
|
|
|
|
validated_data['output'] = base64.b64decode(output)
|
2017-02-06 15:13:27 +00:00
|
|
|
except IndexError:
|
|
|
|
pass
|
2017-02-07 13:51:44 +00:00
|
|
|
return command_store.save(**dict(validated_data))
|