from django.shortcuts import render
from django.http import HttpResponse,HttpRequest
from search.models import Whitecommand,Whitebaoxiu,WhiteIps

def add(request):
    if request.method == "GET":
        return render(request, 'search/add.html')

def show(request):
    if request.method == 'GET':
        return render(request, 'search/show.html')
    elif request.method == 'POST':
        value1 = request.POST.get('value')
        value2 = value1.upper()
        print("value1: ", value1)
        print("value2:", value2)
        res1 = Whitecommand.objects.filter(remark__contains=value1)
        res2 = Whitecommand.objects.filter(remark__contains=value2)
        print("res1", res1)
        print("res2", res2)
        # json.dumps(res2,)
        res = ""
        for i in res1:
            commandName = i.commandname
            remark = i.remark
            respart = commandName + "  " + remark
            res = res + "<hr>" + respart
        for j in res2:
            commandName = j.commandname
            remark = j.remark
            respart = commandName + "  " + remark
            res = res + "<hr>" + respart
        return HttpResponse(res)
    else:
        pass