def follow_question(request): "关注问题" if request.method == "POST": qid = request.POST.get("qid", None) typecode = request.POST.get("type", None) question = get_question_from_redis(int(qid)) if qid and typecode: if typecode == "0": follow = QustionFollow(question=question, user=request.user) follow.follow_question(request.user) follow_question_to_redis(qid, request.user.id) else: follow = QustionFollow.objects.filter(question=question, user=request.user)[0] follow.cancel_follow(request.user) cancel_follow_question_to_redis(qid, request.user.id) return HttpResponse() else: return Http404
def get_activity_list(self,userid,**kwargs): """获取好友最新动态 使用了存储过程 目前动态有0、1、2、3四类 分别代表 提问、回答问题、关注问题、赞或反对问题 """ activity_list=[] question_submit_count=0 answer_count=0 page=kwargs.pop('page',1) pagecount=kwargs.pop('pagecount',15) cursor=connection.cursor() cursor.callproc("sp_friendactiviy",(userid,(page-1)*15,pagecount)) for row in cursor.fetchall(): #import pdb;pdb.set_trace() if row[0]==0: question=Question(id=row[13],title=row[14]) user=User(id=row[15],name=row[16],surname=row[17],avatar=row[18]) question.user=user activity_list.append({'activitytype':row[0],'addtime':row[1],"data":question,"fuser":User(id=row[20],name=row[21],\ surname=row[22],avatar=row[23])}) question_submit_count+=1 elif row[0]==1: answer=Answer(id=row[3],content=row[4],addtime=row[5],commentcount=row[6],favorcount=row[7],opposecount=row[8]) answer.user=User(id=row[9],name=row[10],surname=row[11],avatar=row[12]) answer.question=Question(id=row[13],title=row[14],user=User(id=row[15],name=row[16],surname=row[17],avatar=row[18])) activity_list.append({'activitytype':row[0],'addtime':row[1],"data":answer,"fuser":User(id=row[20],name=row[21],\ surname=row[22],avatar=row[23])}) answer_count +=1 elif row[0]==2: follow=QustionFollow(id=row[19]) question=Question(id=row[13],title=row[14]) user=User(id=row[15],name=row[16],surname=row[17],avatar=row[18]) question.user=user follow.question=question activity_list.append({'activitytype':row[0],'addtime':row[1],"data":follow,"fuser":User(id=row[20],name=row[21],\ surname=row[22],avatar=row[23])}) elif row[0]==3: evalue=AnswerEvaluation(status=row[2]) answer=Answer(id=row[3],content=row[4],addtime=row[5],commentcount=row[6],favorcount=row[7],opposecount=row[8]) answer.user=User(id=row[9],name=row[10],surname=row[11],avatar=row[12]) answer.question=Question(id=row[13],title=row[14],user=User(id=row[15],name=row[16],surname=row[17],avatar=row[18])) evalue.answer=answer activity_list.append({'activitytype':row[0],'addtime':row[1],"data":evalue,"fuser":User(id=row[20],name=row[21],\ surname=row[22],avatar=row[23])}) return {"activity_list":activity_list,"statistics":{"submit_question":question_submit_count,"answer":answer_count}}