Beispiel #1
0
def my_get(request, sign):
	"""
	个人信息get请求
	"""
	if sign == "info":
		#通过OAuth获取用户open_id
		code = request.GET.get('code')
		open_id = u.get_open_id(code)
		request.session['open_id'] = open_id

		temp = User.objects.filter(open_id=open_id, is_deleted=0)

		if len(temp) == 0:
			msg = "您还未绑定,请先绑定!"
			return render_to_response('regist.html',RequestContext(request,{'msg':msg}))
		else:
			user = User.objects.get(open_id=open_id, is_deleted=0)
			return render_to_response('user_info.html',RequestContext(request,
								  {'name':user.name, 'id_card':user.id_card,
								   'phone':user.phone, 'sex':user.sex}))

	elif sign == "logout":
		"""
		注销绑定
		"""
		open_id = request.session['open_id']
		user = User.objects.get(open_id=open_id, is_deleted=0)
		user.delete()

		return render_to_response('regist.html',RequestContext(request,{}))

	else:
		return render_to_response('develop.html',RequestContext(request,{}))
Beispiel #2
0
def regist(request, sign):
	"""
	手机用户绑定
	"""
	if sign == "first":
		"""
		绑定第一步,检验手机号密码
		"""
		#如果已经注册则直接显示信息
		open_id = request.GET.get("open_id")
		try:
			user = User.objects.get(open_id=open_id, is_deleted=0)
			request.session['user_id'] = user.id
			return render_to_response('user_info.html',RequestContext(request,
								  {'name':user.name, 'id_card':user.id_card,
								   'phone':user.phone, 'sex':user.sex}))
		except:
			pass

		phone = request.POST.get('phone')
		password = request.POST.get('password')
		password2 = request.POST.get('password2')

		#从第一次关注的位置注册
		if phone is None:
			msg = "欢迎注册疾病智能分诊!"
			return render_to_response('regist.html', RequestContext(request,
									  {'phone':'', 'msg':msg}))

		try:
			int(phone)

			if password != password2 and len(password) == 0:
				msg = '输入的密码错误!'
			elif len(phone) != 11:
				msg = '手机号码错误!'
			else:
				try:
					open_id = request.session['open_id']
				except:
					code = request.GET.get('code')
					open_id = u.get_open_id(code)
					request.session['open_id'] = open_id

				#open_id = "jacsice"
				print "password",password
				hash_md5 = hashlib.md5(password)
				hash_data = hash_md5.hexdigest()
				user = User(phone=phone, open_id=open_id,
							password=hash_data, create_time=datetime.datetime.now())
				user.save()
				request.session['phone'] = phone
				return render_to_response('update_info.html', RequestContext(request,{}))

			return render_to_response('regist.html', RequestContext(request,
										 {'phone':phone, 'msg':msg}))
		except:
			msg = '手机号码错误!'
			return render_to_response('regist.html', RequestContext(request,
									  {'phone':phone, 'msg':msg}))

	elif sign == "second":
            """
            绑定第二步,输入用户数据
            """
            name = request.POST.get("name")
            id_card = request.POST.get("id_card")
            #print id_card
            phone = request.session['phone']
            s = id_card[16:17]
        if int(s) % 2 == 0:
            sex = '女'
        else:
            sex='男'

        birth = id_card[6:14]
											
        user = User.objects.get(phone=phone, is_deleted=0)
        user.name = name
        user.id_card = id_card
        user.sex = sex
        user.birth = birth
        user.save()

        user = User.objects.get(phone=phone, is_deleted=0)
        msg = "您已绑定成功!"
        return render_to_response('user_info.html',RequestContext(request,
								  {'name':user.name, 'id_card':user.id_card,
								   'phone':user.phone, 'sex':user.sex, 'msg':msg}))
Beispiel #3
0
def consultant(request, sign):
	if sign == "list":
		user_id = request.GET.get("id")
		consultant = Consultant.objects.get(user_id=user_id, sign=0)
		pass
	elif sign == "my":
		try:
			#查看我的咨询信息
			code = request.GET.get('code')
			open_id = u.get_open_id(code)
			user = User.objects.get(open_id=open_id, is_deleted=0)
			#user = User.objects.get(id=13)
			consultant_list = Consultant.objects.filter(user=user)

			if len(consultant_list) == 0:
				sign = "false"
			else:
				sign = "true"
			return render_to_response('my_consultant.html',RequestContext(request,
									{"consultant_list":consultant_list, "sign":sign}))
		except:
			msg = "您还未绑定,请先绑定!"
			return render_to_response('regist.html', RequestContext(request,
									  {'phone':'', 'msg':msg}))

	elif sign == "possible":
		#可能的答复信息
		title = request.GET.get("title")
		answer_list = Answers.objects.filter(title=title)#排除重复数据的可能
		if len(answer_list) == 0:
			content = "暂无数据"
			answer = None
		else:
			answer = answer_list[0]
			content = answer.content.replace("|", "")
		
		return render_to_response('possible_answer_detail.html',RequestContext(request,
								{"answer":answer, "content":content}))

	elif sign == "result":
		#点击结果后,关闭统计回复
		user_id = request.GET.get("id")
		#user_id = 13
		top_consultants = Consultant.objects.filter(user_id=user_id, is_deleted=0).order_by("-id")[0:1]
                top_consultant = top_consultants[0]
                top_consultant.sign = True
                top_consultant.save()

                #对回复结果分词并查找索引表
                topK = 10 #关键词的个数
                content = top_consultant.content
                key_list = jieba.analyse.extract_tags(content,topK)
                possible_result = {}
                answer_list_id = []

                #生成answer_id对应权重的字典
                for i in xrange(0, len(key_list)):
                        possible_answers = Top_Key.objects.filter(key=key_list[i])
                        for answer in possible_answers:
                                if possible_result.has_key(answer.key):
                                        possible_result[str(answer.answer_id)] = possible_result[str(answer.answer_id)] + int(answer.weight)
                                else:
                                        possible_result[str(answer.answer_id)] = int(answer.weight)

                print possible_result
                #对权重排序,讲answer_id放入list
                max = 0
                a_id = ""
                for i in xrange(0, len(possible_result)):
                        for key in possible_result.keys():
                                if possible_result[key] > max:
                                        max = possible_result[key]
                                        a_id = key
                        del(possible_result[a_id])
                        answer_list_id.append(a_id)
                        max = 0

		result_name = ""
		for i in xrange(0, len(answer_list_id)):
        	    if i < 10:
                	answer = Answers.objects.get(id=answer_list_id[i])
                	result_name = result_name + " "+ answer.title
                	
                return render_to_response('possible_answers.html',RequestContext(request,{"result_name":result_name}))