# -*-coding:utf-8 -*-
from django.shortcuts import render,redirect,render_to_response
from django.http import HttpResponse,HttpResponseRedirect,JsonResponse,request,Http404
import re
from django.db.models import Q
from suyusys.models import *
from NewGames.models import *
import sys
reload(sys)
sys.setdefaultencoding('utf8')


def function_search(key_word):
	key_word = key_word
	print key_word
	zh_pattern = re.compile(u'[\u4e00-\u9fa5]+')
	word = key_word.decode()
	match = zh_pattern.search(word)
	if match :
		print u"输入的是中文"
		res = server.objects.filter(name__contains=key_word)
		id = 0
	else:
		res = Hosts.objects.filter(Q(hostWanIp__contains=key_word)|Q(hostLanIp__contains=key_word))
		id = 1
	for a in res:
		print a
		return res,id
	
def action_search(request,key_word):
	print key_word
	result,id = function_search(key_word)
	print id
	context = {
		'result':result,
		'id':id
	}
	return render(request,'suyusys/action_search.html',context)
		