def new_friend(request): try: useremail= request.COOKIES['useremail'] username = User.objects.get(email = useremail).name renwu=fengyun() follows=Followship.objects.filter(fans__email=useremail) friends=[] for follow in follows: friend=follow.followed friends.append(friend) users=User.objects.all() user_list = [] for user in users: n=0 for friend in friends: if friend.email== user.email: n=1 break; if user.email != useremail and n==0: user_list.append(user) people=find_friends(user_list,useremail,friends) if(len(people)>5): people=people[0:5] return render_to_response('new_friend1.html',{'username':username,'fpeoples':renwu,'peoples':user_list}) except: return HttpResponseRedirect('/quanzi/login/')
def searchm(req): #try: useremail= req.COOKIES.get('useremail') follows=Followship.objects.filter(fans__email=useremail) friends=[] for follow in follows: friend=follow.followed friends.append(friend) user=User.objects.get(email=useremail) if(req.POST['gender']=='True'): gender=True else: gender=False school=req.POST['school'] time=req.POST['time'] num=req.POST['num'] low=int(req.POST['low']) high=int(req.POST['high']) now=datetime.datetime.now() day=datetime.date.today() list=[] time=time.encode('utf-8') if time=='一分钟前': a=60 elif time=='一个小时前': a=3600 elif time=='一天前': a=86400 elif time=='三天前': a=259200 elif time=='一周前': a=604800 else: a=2592000 for i in User.objects.all() : old=((day-i.birthday).days)/365 b=(i.last_login).replace(tzinfo=None) cha=(now-b).seconds if(i.is_boy==gender and i.school==school and old>=low and old<=high and cha<=a and i!=user and (i not in friends)): list.append(i) if(num=='越多越好'): list=find_friends(list,useremail,friends) return render_to_response('find_friends.html',{'friends':list,'username':user.name}) #except: return HttpResponseRedirect('/quanzi/login/')
def haoyou(request): try: useremail = request.COOKIES.get('useremail') username = User.objects.get(email = useremail).name follows=Followship.objects.filter(fans__email=useremail) friends=[] for follow in follows: friend=follow.followed friends.append(friend) fri_num=len(friends) fri1_num=len(Followship.objects.filter(followed__email=useremail)) friends.append(User.objects.get(email=useremail)) dongtais = [] for friend in friends: shares = Share.objects.filter(host__email = friend.email).order_by("-datetime") for share in shares: dic = {} dic['name'] = share.host.name dic['email'] = str(share.host.email) dic['dong'] = share dongtais.append(dic) users=User.objects.all() user_list = [] for user in users: n=0 for friend in friends: if friend.email== user.email: n=1 break; if user.email != useremail and n==0: user_list.append(user) people=find_friends(user_list,useremail,friends) if(len(people)>5): people=people[0:5] return render_to_response('haoyoudongtai2.html',{'dongtais':dongtais,'friends':fri_num,\ 'friendeds':fri1_num, 'peoples':people,'username':username }) except: return HttpResponseRedirect('/quanzi/login/')