def SearchResults_doSearch(request): 
	if request.method == 'POST': # If the form has been submitted...
		form = ResultForm(request.POST) # A form bound to the POST data
	elif request.method == 'GET': # If the form has been submitted...
		form = ResultForm(request.GET) # A form bound to the GET data
	if form.is_valid(): # All validation rules pass
		filter = {}
		summaries = {}
		
		summary = form.cleaned_data["run_to_use"]
		
		filters =  form.cleaned_data["conditions"]
		summary_entry = form.cleaned_data["summary"]
		protocol=  form.cleaned_data["protocol"]
		if "All" in protocol or not protocol:
			protocol = None

		ciphers = []		
		ciph =  form.cleaned_data["ciphers_include"]
		if ciph:
			for x in ciph:
				if x in ["AES", "RC4", "3DES"]:
					ciphers += ProbeData.CipherName.objects.filter(ciphername__startswith="TLS", ciphername__contains = "_"+x+"_").values_list("id",flat=True)
				else:
					ciphers += ProbeData.CipherName.objects.filter(ciphervalue = int(x)).values_list("id",flat=True)
			ciphers = ProbeData.CipherName.objects.filter(id__in = ciphers)

		ciphers_ex = []		
		ciph =  form.cleaned_data["ciphers_exclude"]
		if ciph:
			for x in ciph:
				if x in ["AES", "RC4", "3DES"]:
					ciphers_ex += ProbeData.CipherName.objects.filter(ciphername__startswith="TLS", ciphername__contains = "_"+x+"_").values_list("id",flat=True)
				else:
					ciphers_ex += ProbeData.CipherName.objects.filter(ciphervalue = int(x)).values_list("id",flat=True)
			ciphers_ex = ProbeData.CipherName.objects.filter(id__in = ciphers_ex)
		
		alexagroup = form.cleaned_data["alexagroup"]
		if not alexagroup:
			alexagroup = -1
		
		profile_q = None
		profile = int(request.GET.get("profile",0))
		if profile:
			profile_q = Q(result_entry__common_result=profile)
		else:
			profile = int(request.GET.get("bprofile",0)	)
			if profile:
				profile_q = Q(result_entry__common_result__basic_result=profile)
			else:
				profile = int(request.GET.get("fprofile",0))
				if profile:
					profile_q = Q(result_entry__common_result__fundamental_result=profile)
					
		extraparam = {}
		if profile_q:
			extraparam["limitresult"] = profile_q
			
		result = summary.GetAnalyze(filter=dict([(Results.ResultSummaryList.QUERY_CONDITION, form.cleaned_data["conditions"]),
										(Results.ResultSummaryList.QUERY_ALEXA_RESTRICT,alexagroup),
										] +
										 ([(Results.ResultSummaryList.QUERY_PROTOCOL_RESTRICT, protocol)] if protocol else [])+ 
										 ([(Results.ResultSummaryList.QUERY_RESTRICT_RUN,[x.part_of_run_id for x in form.cleaned_data["run_to_limit"]])] if form.cleaned_data["run_to_limit"] else [])+
										 ([(Results.ResultSummaryList.QUERY_CIPHER, ciphers)]  if ciphers else [])+
										 ([(Results.ResultSummaryList.QUERY_CIPHER_EXCLUDE, ciphers_ex)]  if ciphers_ex else [])
										), 
					summaries={
							"data":([summary_entry] if summary_entry != "Total" else []),
							 },
					**extraparam
					)
		
		value_fun = {
					Results.ResultSummaryList.RESULT_HOSTS:lambda x: x.servername.full_servername,
					Results.ResultSummaryList.RESULT_HOSTS_ALEXA:lambda x: x.servername.full_servername,
					Results.ResultSummaryList.RESULT_URLS_TEXT:lambda x: x.servername.full_servername,
					Results.ResultSummaryList.RESULT_HOST_RUNLIST:lambda x: (x.servername.servername, x.servername.port),
					Results.ResultSummaryList.RESULT_CONDITION:lambda x:dict(Results.ResultCondition.RESULTC_VALUES)[x.condition],
					Results.ResultSummaryList.RESULT_DOMAIN:lambda x: x.full_domain_name,
					Results.ResultSummaryList.RESULT_IP:lambda x: x.full_ip_mask,
					Results.ResultSummaryList.RESULT_PRIMARYAGENT:lambda x: x.agent_name,
					Results.ResultSummaryList.RESULT_SHORTPRIMARYAGENT:lambda x: x.agent_name,
					Results.ResultSummaryList.RESULT_SECONDARYAGENT:lambda x: x.agent_name,
					Results.ResultSummaryList.RESULT_SHORTSECONDARYAGENT:lambda x: x.agent_name,
					Results.ResultSummaryList.RESULT_CIPHER:lambda x: x.ciphername,
					Results.ResultSummaryList.RESULT_CIPHERGROUP:lambda x:  " ".join(sorted([y.ciphername for y in x.cipher_suites.cipher_suites.all()])),
					Results.ResultSummaryList.RESULT_PROTOCOLS:lambda x: dict(Results.ResultCondition.RESULTC_VALUES)[x.condition],
					Results.ResultSummaryList.RESULT_HOST_PROFILES:lambda x:x.key,
					Results.ResultSummaryList.RESULT_HOST_BASEPROFILES:lambda x:x.key,
					Results.ResultSummaryList.RESULT_HOST_FUNDPROFILES:lambda x:x.key,
					}[summary_entry] if summary_entry != "Total" else None
		data = result.get("data",[]) if summary_entry != "Total" else []
		if not data:
			data = []

						
		entries = [ (
						value_fun(x),
						x.filtered_count, 
						x.total_count, 
						(float(x.filtered_count)/float(x.total_count) if x.total_count else 0 )*100, 
						x,
						)						
						for x in data
					]
		if summary_entry in [Results.ResultSummaryList.RESULT_HOSTS_ALEXA, Results.ResultSummaryList.RESULT_URLS_TEXT, Results.ResultSummaryList.RESULT_HOST_RUNLIST]:
			entries.sort(key = lambda x:(x[-1].servername.alexa_rating if x[-1].servername.alexa_rating >0 else 100000000,x[-1].servername.full_servername))
		else:
			entries.sort(key = lambda x:(-x[1], x[0]))

		if summary_entry ==Results.ResultSummaryList.RESULT_URLS_TEXT:
			response = HttpResponse(mimetype="text/plain")
			response["Content-Disposition"] = "attachment; filename=urls.txt"
			
			for x in entries:
				response.write('https://'+x[-1].servername.servername+":"+str(x[-1].servername.port)+'/\n')
					
			return response  
		elif summary_entry ==Results.ResultSummaryList.RESULT_HOST_RUNLIST:
			response = HttpResponse(mimetype="text/csv")
			response["Content-Disposition"] = "attachment; filename=runlist.csv"
			
			import csv
			
			writer = csv.writer(response)
			i = 0
			for x in entries:
				i+=1
				writer.writerow([i] + list(x[0]))
					
			return response  
		elif summary_entry in [Results.ResultSummaryList.RESULT_HOST_PROFILES, Results.ResultSummaryList.RESULT_HOST_BASEPROFILES, Results.ResultSummaryList.RESULT_HOST_FUNDPROFILES]:
			return render_to_response('searchprofileresults.html', {
				"run":summary.part_of_run_id,
				"matching":result["_matching"],
				"total":result["_total"],
				"match_percentage":(float(result["_matching"])/float(result["_total"]) if result["_total"] else 0 )*100,
				"entries":entries,
				"debug_output":[x for x in connection.queries],
			
			})
				

		return render_to_response('searchresults.html', {
			"matching":result["_matching"],
			"total":result["_total"],
			"show_alexa":summary_entry == Results.ResultSummaryList.RESULT_HOSTS_ALEXA,
			"match_percentage":(float(result["_matching"])/float(result["_total"]) if result["_total"] else 0 )*100,
			"entries":entries,
			"debug_output":[x for x in connection.queries],
			
		})
	else:
		return 	SearchResults(request, method = request.method)
Creates a single mail. This is also used in workflow mail send process.
dataset/ETHPy150Open operasoftware/tlsprober/probedb/resultdb2/views.py/SearchResults_doSearch--crossover with--dataset/ETHPy150Open allink/pennyblack/pennyblack/models/job.py/Job.create_mail