Exemplo n.º 1
0
def user_home_netease(request):
	'''展示网易收藏'''
	profile = {'status':True,'titleMsg':'发生错误'}
	if request.method=="GET":
		if request.session.get('is_login',False):
			username = request.session.get('username')
			profile['username'] = username
			user = User.objects.get(username=username)
			bound_netease = user.bound_netease
			netease_username = user.netease_username
			netease_uid = user.netease_uid

			if bound_netease : 
				#收藏的歌单
				profile['bound_netease'] = True
				profile['bound_xiami'] = user.bound_xiami
				nu = NU(netease_username)
				ret = nu.get_favor_song(netease_uid)
				if ret[0]:
					profile['favor_song_netease'] = ret[1]
				#个性化推荐 歌单 做不了 是post请求,需要密码。
				#ret = nu.get_personal_customized(cookies)
				#if ret[0]:
				#	profile['customized_netease'] = ret[1]
			
				return render(request,'home_netease.html',{'profile':profile,})

			else:
				return HttpResponseRedirect('/home/')

		else:
			return HttpResponseRedirect('/login/')
		
	return HttpResponseRedirect('/login/')
Exemplo n.º 2
0
def bound_netease(request):
	message = {'status':True,'titleMsg':'发生错误'}
	#如果已绑定,跳走(还要解绑,检查cookie有效期)
	if request.method=="GET":
		if not request.session.get('is_login',False):
			#未登录
			return HttpResponseRedirect('/login/')
		else:
			#已绑定
			username = request.session.get('username')
			user = User.objects.get(username=username)
			if user.bound_netease:
				return HttpResponseRedirect('/setting/')

	if request.method=="POST":
		netease_id = request.POST.get('netease_id')
		passwd = request.POST.get('passwd')
		
		if netease_id.replace(' ','') == '':
			return render(request,'bound_netease.html',{'message':message,})
		if passwd.replace(' ','') == '':
			return render(request,'bound_netease.html',{'message':message,})

		nu = NU(netease_id)
		message = nu.login(passwd)
		
		#print message
		if message['status']:
			username = request.session.get('username')
			user = User.objects.get(username=username)
			user.bound_netease = True
			user.netease_uid = message['uid']
			user.netease_username = message['nickname']
			user.netease_cookies = str(message['netease_cookie'])
			ret = nu.get_favor_song(message['uid'])
			user.netease_playlist = ret[1][0]['id']
			user.save()
			profile = {
				'username' : username,
				'netease_username' : message['nickname']
			}
			return HttpResponseRedirect('/setting/')
		
	return render(request,'bound_netease.html',{'message':message,})