SHARE
TWEET

sort by time

a guest Jan 11th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @csrf_exempt
  2. # @login_required(login_url='/login')
  3.  
  4. def trending(request):
  5.     if request.method == 'POST':
  6.         data_byte=request.body.decode('utf-8')
  7.         data=json.loads(data_byte)
  8.  
  9.         post_count = data['post_count']
  10.  
  11.  
  12.         latest_surveys = Survey.objects.filter(inGroup = False).order_by('-creationTime')[post_count:post_count+10]
  13.        
  14.         print("I am here ",latest_surveys)
  15.  
  16.         sending_list = []
  17.  
  18.         for S in latest_surveys:
  19.             P = Poll.objects.filter(idSurvey = S)
  20.             O = OptionValues.objects.get(idPoll = P[0])
  21.             U = User.objects.get(pk = S.idUser.pk)
  22.             total_recommends = len(Recommend.objects.filter(idSurvey = S))
  23.             option_list = [O.name0,O.name1,O.name2,O.name3]
  24.             vote_count_list = [O.value0,O.value1,O.value2,O.value3]
  25.  
  26.             temp_dict = {}
  27.  
  28.             temp_dict['name']=U.first_name
  29.             temp_dict['photo']='dummy.jpg'
  30.             temp_dict['idSurvey']=S.pk
  31.             temp_dict['title']=S.title
  32.             temp_dict['time']=str(S.creationTime)
  33.             temp_dict['idPoll']=P[0].pk
  34.             temp_dict['pollQuestion']=P[0].description
  35.             temp_dict['pollImage']='dummy.jpg'
  36.             temp_dict['recommend']=total_recommends
  37.             temp_dict['option_list']=option_list
  38.             temp_dict['votes']='100'                        #dummy.jpg value for now
  39.             temp_dict['vote_count_list']=vote_count_list
  40.  
  41.             sending_list.append(temp_dict)
  42.  
  43.  
  44.         data = json.dumps(sending_list)
  45.         return HttpResponse(data)
  46.  
  47. @csrf_exempt
  48. # @login_required(login_url='/login')
  49.  
  50. def home(request):
  51.     if request.method == 'POST':
  52.         data_byte=request.body.decode('utf-8')
  53.         data=json.loads(data_byte)
  54.  
  55.         post_count = data['post_count']
  56.         idUser = User.objects.get(pk = data['idUser'])
  57.  
  58.  
  59.         # latest_surveys = []
  60.  
  61.         # subscriptions = Subscription.objects.filter(idSubscriber = idUser)
  62.  
  63.         # for ss in subscriptions:
  64.         #   latest_surveys.extend(Survey.objects.filter(idUser = ss.idSubscribee))
  65.  
  66.  
  67.         # latest_surveys_new=latest_surveys[post_count:post_count+10];
  68.         latest_surveys = Survey.objects.filter(idUser__userSubscribee__idSubscriber = idUser.pk).order_by('-creationTime')[post_count:post_count+10]    # using related name for subscription
  69.  
  70.         sending_list = []
  71.        
  72.        
  73.         for S in latest_surveys:
  74.             P = Poll.objects.filter(idSurvey = S)[:1]
  75.             O = OptionValues.objects.get(idPoll = P[0])
  76.             U = User.objects.get(pk = S.idUser.pk)
  77.             total_recommends = len(Recommend.objects.filter(idSurvey = S))
  78.             option_list = [O.name0,O.name1,O.name2,O.name3]
  79.             vote_count_list = [O.value0,O.value1,O.value2,O.value3]
  80.  
  81.             temp_dict = {}
  82.  
  83.             temp_dict['name']=U.first_name
  84.             temp_dict['photo']='dummy.jpg'
  85.             temp_dict['idSurvey']=S.pk
  86.             temp_dict['title']=S.title
  87.             temp_dict['time']=str(S.creationTime)
  88.             temp_dict['idPoll']=P[0].pk
  89.             temp_dict['pollQuestion']=P[0].description
  90.             temp_dict['pollImage']='dummy.jpg'
  91.             temp_dict['recommend']=total_recommends
  92.             temp_dict['option_list']=option_list
  93.             temp_dict['votes']='100'                        #dummy.jpg value for now
  94.             temp_dict['vote_count_list']=vote_count_list
  95.  
  96.             sending_list.append(temp_dict)
  97.        
  98.  
  99.  
  100.         data = json.dumps(sending_list)
  101.         return HttpResponse(data)
  102.  
  103.  
  104.  
  105.  
  106. @csrf_exempt
  107. # @login_required(login_url='/login')
  108.  
  109.  
  110. def load_profile(request):
  111.     if request.method == 'POST':
  112.         data_byte=request.body.decode('utf-8')
  113.         data=json.loads(data_byte)
  114.  
  115.         post_count = data['post_count']
  116.         current = data['current']
  117.         target = data['target']
  118.        
  119.         targetUser = User.objects.get(pk = target)
  120.         print(targetUser)
  121.  
  122.         subscriber_count = len(Subscription.objects.filter(idSubscribee = target))
  123.         subscription_count = len(Subscription.objects.filter(idSubscriber = target))
  124.         # group_count = len(Group.objects.filter(idAdmin = target))
  125.         group_count = len(GroupMember.objects.filter(idUser = target))
  126.  
  127.         flag = ''
  128.  
  129.         if current == target:
  130.             flag = 'own_profile'
  131.         elif len(Subscription.objects.filter(idSubscriber = current).filter(idSubscribee = target)) > 0 :
  132.             flag = 'subscribed_profile'
  133.         else:
  134.             flag = 'unsubscribed_profile'
  135.  
  136.         head = {'name': (targetUser.first_name+' '+targetUser.last_name),'subscriber_count':subscriber_count,'subscription_count':subscription_count,'group_count':group_count,'flag':flag}
  137.  
  138.         latest_surveys = Survey.objects.filter(inGroup = False).filter(idUser = target).order_by('-creationTime')[post_count:post_count+10]
  139.        
  140.  
  141.         sending_list = []
  142.         sending_list.append(head)
  143.         for S in latest_surveys:
  144.             P = Poll.objects.filter(idSurvey = S)
  145.             # print(S)
  146.             # print("length of poll: ",len(P))
  147.             # return HttpResponse('failure')
  148.             O = OptionValues.objects.get(idPoll = P[0])
  149.             U = User.objects.get(pk = S.idUser.pk)
  150.             total_recommends = len(Recommend.objects.filter(idSurvey = S))
  151.             option_list = [O.name0,O.name1,O.name2,O.name3]
  152.             vote_count_list = [O.value0,O.value1,O.value2,O.value3]
  153.  
  154.             temp_dict = {}
  155.  
  156.             temp_dict['name']=U.first_name
  157.             temp_dict['photo']='dummy.jpg'
  158.             temp_dict['idSurvey']=S.pk
  159.             temp_dict['title']=S.title
  160.  
  161.             temp_dict['time']=str(S.creationTime)
  162.             temp_dict['idPoll']=P[0].pk
  163.             temp_dict['pollQuestion']=P[0].description
  164.             temp_dict['pollImage']='dummy.jpg'
  165.             temp_dict['recommend']=total_recommends
  166.             temp_dict['option_list']=option_list
  167.             temp_dict['votes']='100'                        #dummy.jpg value for now
  168.             temp_dict['vote_count_list']=vote_count_list
  169.  
  170.             sending_list.append(temp_dict)
  171.        
  172.  
  173.  
  174.         data = json.dumps(sending_list)
  175.         return HttpResponse(data)
RAW Paste Data
Top