from django.shortcuts import render

# Create your views here.
import json

from rest_framework.viewsets import ModelViewSet
from rest_framework import permissions
from rest_framework import filters
from rest_framework.decorators import action
from rest_framework.response import Response

from .models import Configures
from apps.configures.serializers import ConfiguresSerializer
from apps.interfaces.models import Interfaces
from utils import handle_datas

class ConfiguresViewSet(ModelViewSet):
    """
    list:
    返回配置信息列表数据

    create:
    创建配置信息

    retrieve:
    反馈配置信息详情数据

    update:
    更新配置信息

    partial_update:
    更新配置信息（部分）

    destroy:
    删除配置信息
    """

    queryset = Configures.objects.filter(is_delete=False)
    serializer_class = ConfiguresSerializer
    permission_classes = [permissions.IsAuthenticated,]
    ordering_fields = ('id','name')

    def perform_destroy(self, instance):
        instance.is_delete = True
        instance.save()

    def retrieve(self, request, *args, **kwargs):
        config_obj = self.get_object()
        config_request = json.loads(config_obj.request,encoding='utf-8')
        # 处理请求头数据
        config_headers = config_request['config']['request'].get('headers')
        config_headers_list = handle_datas.handle_data4(config_headers)

        # 处理全局变量数据
        config_variables = config_request['config'].get('variables')
        config_variables_list = handle_datas.handle_data2(config_variables)

        config_name = config_request['config']['name']
        selected_interface_id = config_obj.interface_id
        selected_project_id = Interfaces.objects.get(id=selected_interface_id).project_id

        datas = {
            "authon":config_obj.author,
            "configure_name":config_name,
            "selected_interface_id":selected_interface_id,
            "selected_project_id":selected_project_id,
            "header":config_headers_list,
            "globalVar":config_variables_list
        }
        return Response(datas)
7b6377422850816b25b1c8f2a1ae966d0eefda90
<mask token>


class ConfiguresViewSet(ModelViewSet):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def perform_destroy(self, instance):
        instance.is_delete = True
        instance.save()

    def retrieve(self, request, *args, **kwargs):
        config_obj = self.get_object()
        config_request = json.loads(config_obj.request, encoding='utf-8')
        config_headers = config_request['config']['request'].get('headers')
        config_headers_list = handle_datas.handle_data4(config_headers)
        config_variables = config_request['config'].get('variables')
        config_variables_list = handle_datas.handle_data2(config_variables)
        config_name = config_request['config']['name']
        selected_interface_id = config_obj.interface_id
        selected_project_id = Interfaces.objects.get(id=selected_interface_id
            ).project_id
        datas = {'authon': config_obj.author, 'configure_name': config_name,
            'selected_interface_id': selected_interface_id,
            'selected_project_id': selected_project_id, 'header':
            config_headers_list, 'globalVar': config_variables_list}
        return Response(datas)

<mask token>


class ConfiguresViewSet(ModelViewSet):
    <mask token>
    queryset = Configures.objects.filter(is_delete=False)
    serializer_class = ConfiguresSerializer
    permission_classes = [permissions.IsAuthenticated]
    ordering_fields = 'id', 'name'

    def perform_destroy(self, instance):
        instance.is_delete = True
        instance.save()

    def retrieve(self, request, *args, **kwargs):
        config_obj = self.get_object()
        config_request = json.loads(config_obj.request, encoding='utf-8')
        config_headers = config_request['config']['request'].get('headers')
        config_headers_list = handle_datas.handle_data4(config_headers)
        config_variables = config_request['config'].get('variables')
        config_variables_list = handle_datas.handle_data2(config_variables)
        config_name = config_request['config']['name']
        selected_interface_id = config_obj.interface_id
        selected_project_id = Interfaces.objects.get(id=selected_interface_id
            ).project_id
        datas = {'authon': config_obj.author, 'configure_name': config_name,
            'selected_interface_id': selected_interface_id,
            'selected_project_id': selected_project_id, 'header':
            config_headers_list, 'globalVar': config_variables_list}
        return Response(datas)

<mask token>


class ConfiguresViewSet(ModelViewSet):
    """
    list:
    返回配置信息列表数据

    create:
    创建配置信息

    retrieve:
    反馈配置信息详情数据

    update:
    更新配置信息

    partial_update:
    更新配置信息（部分）

    destroy:
    删除配置信息
    """
    queryset = Configures.objects.filter(is_delete=False)
    serializer_class = ConfiguresSerializer
    permission_classes = [permissions.IsAuthenticated]
    ordering_fields = 'id', 'name'

    def perform_destroy(self, instance):
        instance.is_delete = True
        instance.save()

    def retrieve(self, request, *args, **kwargs):
        config_obj = self.get_object()
        config_request = json.loads(config_obj.request, encoding='utf-8')
        config_headers = config_request['config']['request'].get('headers')
        config_headers_list = handle_datas.handle_data4(config_headers)
        config_variables = config_request['config'].get('variables')
        config_variables_list = handle_datas.handle_data2(config_variables)
        config_name = config_request['config']['name']
        selected_interface_id = config_obj.interface_id
        selected_project_id = Interfaces.objects.get(id=selected_interface_id
            ).project_id
        datas = {'authon': config_obj.author, 'configure_name': config_name,
            'selected_interface_id': selected_interface_id,
            'selected_project_id': selected_project_id, 'header':
            config_headers_list, 'globalVar': config_variables_list}
        return Response(datas)

from django.shortcuts import render
import json
from rest_framework.viewsets import ModelViewSet
from rest_framework import permissions
from rest_framework import filters
from rest_framework.decorators import action
from rest_framework.response import Response
from .models import Configures
from apps.configures.serializers import ConfiguresSerializer
from apps.interfaces.models import Interfaces
from utils import handle_datas


class ConfiguresViewSet(ModelViewSet):
    """
    list:
    返回配置信息列表数据

    create:
    创建配置信息

    retrieve:
    反馈配置信息详情数据

    update:
    更新配置信息

    partial_update:
    更新配置信息（部分）

    destroy:
    删除配置信息
    """
    queryset = Configures.objects.filter(is_delete=False)
    serializer_class = ConfiguresSerializer
    permission_classes = [permissions.IsAuthenticated]
    ordering_fields = 'id', 'name'

    def perform_destroy(self, instance):
        instance.is_delete = True
        instance.save()

    def retrieve(self, request, *args, **kwargs):
        config_obj = self.get_object()
        config_request = json.loads(config_obj.request, encoding='utf-8')
        config_headers = config_request['config']['request'].get('headers')
        config_headers_list = handle_datas.handle_data4(config_headers)
        config_variables = config_request['config'].get('variables')
        config_variables_list = handle_datas.handle_data2(config_variables)
        config_name = config_request['config']['name']
        selected_interface_id = config_obj.interface_id
        selected_project_id = Interfaces.objects.get(id=selected_interface_id
            ).project_id
        datas = {'authon': config_obj.author, 'configure_name': config_name,
            'selected_interface_id': selected_interface_id,
            'selected_project_id': selected_project_id, 'header':
            config_headers_list, 'globalVar': config_variables_list}
        return Response(datas)

from django.shortcuts import render

# Create your views here.
import json

from rest_framework.viewsets import ModelViewSet
from rest_framework import permissions
from rest_framework import filters
from rest_framework.decorators import action
from rest_framework.response import Response

from .models import Configures
from apps.configures.serializers import ConfiguresSerializer
from apps.interfaces.models import Interfaces
from utils import handle_datas

class ConfiguresViewSet(ModelViewSet):
    """
    list:
    返回配置信息列表数据

    create:
    创建配置信息

    retrieve:
    反馈配置信息详情数据

    update:
    更新配置信息

    partial_update:
    更新配置信息（部分）

    destroy:
    删除配置信息
    """

    queryset = Configures.objects.filter(is_delete=False)
    serializer_class = ConfiguresSerializer
    permission_classes = [permissions.IsAuthenticated,]
    ordering_fields = ('id','name')

    def perform_destroy(self, instance):
        instance.is_delete = True
        instance.save()

    def retrieve(self, request, *args, **kwargs):
        config_obj = self.get_object()
        config_request = json.loads(config_obj.request,encoding='utf-8')
        # 处理请求头数据
        config_headers = config_request['config']['request'].get('headers')
        config_headers_list = handle_datas.handle_data4(config_headers)

        # 处理全局变量数据
        config_variables = config_request['config'].get('variables')
        config_variables_list = handle_datas.handle_data2(config_variables)

        config_name = config_request['config']['name']
        selected_interface_id = config_obj.interface_id
        selected_project_id = Interfaces.objects.get(id=selected_interface_id).project_id

        datas = {
            "authon":config_obj.author,
            "configure_name":config_name,
            "selected_interface_id":selected_interface_id,
            "selected_project_id":selected_project_id,
            "header":config_headers_list,
            "globalVar":config_variables_list
        }
        return Response(datas)