Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @csrf_exempt
- # @login_required(login_url='/login')
- def trending(request):
- if request.method == 'POST':
- data_byte=request.body.decode('utf-8')
- data=json.loads(data_byte)
- post_count = data['post_count']
- latest_surveys = Survey.objects.filter(inGroup = False).order_by('-creationTime')[post_count:post_count+10]
- print("I am here ",latest_surveys)
- sending_list = []
- for S in latest_surveys:
- P = Poll.objects.filter(idSurvey = S)
- O = OptionValues.objects.get(idPoll = P[0])
- U = User.objects.get(pk = S.idUser.pk)
- total_recommends = len(Recommend.objects.filter(idSurvey = S))
- option_list = [O.name0,O.name1,O.name2,O.name3]
- vote_count_list = [O.value0,O.value1,O.value2,O.value3]
- temp_dict = {}
- temp_dict['name']=U.first_name
- temp_dict['photo']='dummy.jpg'
- temp_dict['idSurvey']=S.pk
- temp_dict['title']=S.title
- temp_dict['time']=str(S.creationTime)
- temp_dict['idPoll']=P[0].pk
- temp_dict['pollQuestion']=P[0].description
- temp_dict['pollImage']='dummy.jpg'
- temp_dict['recommend']=total_recommends
- temp_dict['option_list']=option_list
- temp_dict['votes']='100' #dummy.jpg value for now
- temp_dict['vote_count_list']=vote_count_list
- sending_list.append(temp_dict)
- data = json.dumps(sending_list)
- return HttpResponse(data)
- @csrf_exempt
- # @login_required(login_url='/login')
- def home(request):
- if request.method == 'POST':
- data_byte=request.body.decode('utf-8')
- data=json.loads(data_byte)
- post_count = data['post_count']
- idUser = User.objects.get(pk = data['idUser'])
- # latest_surveys = []
- # subscriptions = Subscription.objects.filter(idSubscriber = idUser)
- # for ss in subscriptions:
- # latest_surveys.extend(Survey.objects.filter(idUser = ss.idSubscribee))
- # latest_surveys_new=latest_surveys[post_count:post_count+10];
- latest_surveys = Survey.objects.filter(idUser__userSubscribee__idSubscriber = idUser.pk).order_by('-creationTime')[post_count:post_count+10] # using related name for subscription
- sending_list = []
- for S in latest_surveys:
- P = Poll.objects.filter(idSurvey = S)[:1]
- O = OptionValues.objects.get(idPoll = P[0])
- U = User.objects.get(pk = S.idUser.pk)
- total_recommends = len(Recommend.objects.filter(idSurvey = S))
- option_list = [O.name0,O.name1,O.name2,O.name3]
- vote_count_list = [O.value0,O.value1,O.value2,O.value3]
- temp_dict = {}
- temp_dict['name']=U.first_name
- temp_dict['photo']='dummy.jpg'
- temp_dict['idSurvey']=S.pk
- temp_dict['title']=S.title
- temp_dict['time']=str(S.creationTime)
- temp_dict['idPoll']=P[0].pk
- temp_dict['pollQuestion']=P[0].description
- temp_dict['pollImage']='dummy.jpg'
- temp_dict['recommend']=total_recommends
- temp_dict['option_list']=option_list
- temp_dict['votes']='100' #dummy.jpg value for now
- temp_dict['vote_count_list']=vote_count_list
- sending_list.append(temp_dict)
- data = json.dumps(sending_list)
- return HttpResponse(data)
- @csrf_exempt
- # @login_required(login_url='/login')
- def load_profile(request):
- if request.method == 'POST':
- data_byte=request.body.decode('utf-8')
- data=json.loads(data_byte)
- post_count = data['post_count']
- current = data['current']
- target = data['target']
- targetUser = User.objects.get(pk = target)
- print(targetUser)
- subscriber_count = len(Subscription.objects.filter(idSubscribee = target))
- subscription_count = len(Subscription.objects.filter(idSubscriber = target))
- # group_count = len(Group.objects.filter(idAdmin = target))
- group_count = len(GroupMember.objects.filter(idUser = target))
- flag = ''
- if current == target:
- flag = 'own_profile'
- elif len(Subscription.objects.filter(idSubscriber = current).filter(idSubscribee = target)) > 0 :
- flag = 'subscribed_profile'
- else:
- flag = 'unsubscribed_profile'
- head = {'name': (targetUser.first_name+' '+targetUser.last_name),'subscriber_count':subscriber_count,'subscription_count':subscription_count,'group_count':group_count,'flag':flag}
- latest_surveys = Survey.objects.filter(inGroup = False).filter(idUser = target).order_by('-creationTime')[post_count:post_count+10]
- sending_list = []
- sending_list.append(head)
- for S in latest_surveys:
- P = Poll.objects.filter(idSurvey = S)
- # print(S)
- # print("length of poll: ",len(P))
- # return HttpResponse('failure')
- O = OptionValues.objects.get(idPoll = P[0])
- U = User.objects.get(pk = S.idUser.pk)
- total_recommends = len(Recommend.objects.filter(idSurvey = S))
- option_list = [O.name0,O.name1,O.name2,O.name3]
- vote_count_list = [O.value0,O.value1,O.value2,O.value3]
- temp_dict = {}
- temp_dict['name']=U.first_name
- temp_dict['photo']='dummy.jpg'
- temp_dict['idSurvey']=S.pk
- temp_dict['title']=S.title
- temp_dict['time']=str(S.creationTime)
- temp_dict['idPoll']=P[0].pk
- temp_dict['pollQuestion']=P[0].description
- temp_dict['pollImage']='dummy.jpg'
- temp_dict['recommend']=total_recommends
- temp_dict['option_list']=option_list
- temp_dict['votes']='100' #dummy.jpg value for now
- temp_dict['vote_count_list']=vote_count_list
- sending_list.append(temp_dict)
- data = json.dumps(sending_list)
- return HttpResponse(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement