def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         c_index = int(
             request.GET.get('cIndex')) if request.GET.get('cIndex') else 0
         try:
             frame_id = request.GET.get('frameId')
             frame_id = int(frame_id)
         except:
             response_error()
         chat_frame = MessageFrame.objects.get(pk=frame_id)
         if user in chat_frame.users.all() and c_index != -1:
             m = Message.objects.filter(chat_frame=chat_frame).order_by(
                 '-create_time')[c_index:c_index + 10]
         elif user in chat_frame.users.all():
             m = Message.objects.filter(
                 chat_frame=chat_frame,
                 message_messagereadinfo_message__fetch=False)
             # here to reset the fetch in messageReadInfo
         mess = message_serialize(m)
         # line next and for loop to reset the message read and fetch
         mri = MessageReadInfo.objects.filter(user=user).filter(
             message_id__in=list(m.values_list('id', flat=True)))
         for i in mri:
             i.fetch = True
             i.save()
         data = {'status_code': 'ok', 'mess': mess}
         response = HttpResponse(
             'while(1);' + json.dumps(data),
             content_type='application/x-javascript;charset=utf-8')
         set_response_header(response)
         return response
 def get(self, request):
     if check_authentication(request, True):
         user = get_user(request)
         try:
             network_account = NetworkAccount.objects.get(user=user)
             data = {
                 'data': network_account_serialize(network_account),
                 'status_code': 'ok'
             }
             response = HttpResponse(
                 'while(1);' + json.dumps(data),
                 content_type='application/x-javascript; charset=utf-8;')
             set_response_header(response)
             response.set_cookie(key='nu',
                                 value=network_account.network_id.hex,
                                 max_age=60 * 60 * 24)
             return response
         except NetworkAccount.DoesNotExist:
             pass
     data = {'status_code': 'error'}
     response = HttpResponse(
         'while(1);' + json.dumps(data),
         content_type='application/x-javascript; charset=utf-8;')
     set_response_header(response)
     return response
Beispiel #3
0
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         try:
             currentIndex = int(request.GET.get('currentIndex'))
         except ValueError:
             currentIndex = 0
         noti_type = ['status-a', 'status-b']
         notis = Notification.objects.filter(
             user=user, noti_type__in=noti_type).order_by(
                 '-time')[currentIndex:currentIndex + 10]
         unread_noti = len(
             Notification.objects.filter(user=user,
                                         read=False,
                                         noti_type__in=noti_type))
         data = {
             'data': notification_serialize(notis),
             'unread': unread_noti,
             'status_code': 'ok'
         }
         response = JsonResponse(data)
         set_response_header(response)
         return response
     else:
         data = {'status_code': 'error'}
         response = JsonResponse(data)
         set_response_header(response)
         return response
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         timeout = time.time() + 45  # 3 seconds
         while True:
             time.sleep(2)
             if time.time() > timeout:
                 break
             m = MessageUserInfo.objects.filter(user=user, fetch=False)
             if len(m) > 0:
                 data = {
                     'data': pollmessage_serialize(m),
                     'status_code': 'ok',
                     'on': True
                 }
                 response = HttpResponse(
                     'while(1);' + json.dumps(data),
                     content_type='application/x-javascript; charset=utf-8')
                 set_response_header(response)
                 return response
         data = {'status_code': 'ok', 'on': False}
         response = HttpResponse(
             'while(1);' + json.dumps(data),
             content_type='application/x-javascript; charset=utf-8')
         set_response_header(response)
         return response
     data = {'status_code': 'error'}
     response = HttpResponse(
         'while(1);' + json.dumps(data),
         content_type='application/x-javascript; charset=utf-8')
     set_response_header(response)
     return response
 def post(self, request):
     if check_authentication(request):
         user = get_user(request)
         post_data = request.POST
         fullname = post_data.get('fullname')
         born_year = post_data.get('bornYear')
         image_id = post_data.get('imageId')
         country_code = post_data.get('countryCode')
         sex = post_data.get('sex')
         if user and fullname and born_year and image_id and sex and country_code:
             image = Image.objects.get(pk = image_id)
             try:
                 NetworkAccount.objects.create(user = user, fullname = fullname, birthYear = born_year, nationality = country_code, sex = sex, profile_picture = image)
             except IntegrityError:
                 data = {
                     'status_code': 'error'
                 }
                 response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
                 return response
             data = {
                 'status_code': 'ok'
             }
             response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
             return response
         data = {
             'status_code': 'error'
         }
         response = HttpResponse('while(1);' + json.dumps(data), content_type = 'application/x-javascript; charset=utf-8')
         set_response_header(response)
         return response
Beispiel #6
0
    def post(self, request):
        if check_authentication(request):
            # the person who upload image
            user = get_user(request)
            
            # the real file
            upload_file = request.FILES['image']

            # the type of image
            image_type = request.POST.get('imageType')
            if image_type and image_type != '':
                pass
            else:
                image_type = 'post_status'

            pillow_image = handle_image_pillow(upload_file)
            final_image = InMemoryUploadedFile(pillow_image, None, 'base.jpg', 'image/jpeg', pillow_image.tell, None)
            final_pillow_image = Image.open(final_image)

            img_model = ImageModel.objects.create(user = user, image_type = image_type, image_width = final_pillow_image.width, image_height = final_pillow_image.height, image_id = uuid.uuid4().hex)
            img_model.image = final_image
            img_model.save()
            data = {
                    'status_type': 'ok',
                    'photo_id': img_model.id,
                    'photo_url': img_model.image.url
                }
            response = JsonResponse(data)
            set_response_header(response)
            return response
        else:
            response = JsonResponse({'status_type':'error'})
            set_response_header(response)
            return response
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         past_5_days = timezone.now() - timedelta(days=5)
         #friend = Friend.objects.filter(user = user, friend__onlinetime__time__gte = past_5_days)
         friend = Friend.objects.filter(user=user)
         data = {'friends': friend_serialize(friend), 'status_code': 'ok'}
         response = JsonResponse(data)
         set_response_header(response)
         return response
    def post(self, request):
        if check_authentication(request, True):
            user = get_user(request)
            data = request.POST
            post = PostModel.objects.create(user = user, text = data.get('textarea'))
            # sale items 
            post.sale_item = data.get('saleItem')
            post.save()
            # for friend
            fr_id = data.getlist('friendIds')
            if fr_id:
                pf = PostFriendTag.objects.create(post = post)
                for i in fr_id:
                    t = User.objects.get(user_id = i)
                    pf.friend.add(t)
                    noti = Notification.objects.create(user = t, noti_type = 'post-a')
                    PostANotification.objects.create(noti = noti, post = post)
            # for images
            images_id = data.getlist('images_id')
            for i in images_id:
                img = ImageModel.objects.get(pk = int(i))
                img.image_type = 'post-newfeed'
                img.user = user
                img.has_saved = True
                img.save()
                post.has_link_image = True
                post.image.add(img)
                post.save()
            status = Status.objects.create(verb = 'post', privacy = 'friend', post = post, user = user)
            if request.POST.get('verb') == 'sale':
                status.verb = 'sale'
                status.save()

            #for reactions
            use_default_reaction = True
            use_custom_reaction = False
            reaction = data.get('reaction')
            if reaction.strip() and len(reaction.strip()) < 30:
                use_default_reaction = False
                use_custom_reaction = True
                status.use_default_reaction = use_default_reaction
                status.use_custom_reaction = use_custom_reaction
                status.save()
                sr = StatusReaction.objects.create(status = status, reactionName = reaction, reactionType = 'a')
            else:
                sr = StatusReaction.objects.create(status = status, reactionName = 'like', reactionType = '1', icon = 'heart', vote = 0)
            response = JsonResponse({'data': status_serialize(status, user), 'status_code':'ok'})
            set_response_header(response)
            return response
        else:
            response = JsonResponse({'status_code':'error'})
            set_response_header(response)
            return response
 def post(self, request):
     if check_authentication(request):
         user = get_user(request)
         try:
             pk = int(request.POST.get('plustagPk'))
         except:
             response = JsonResponse({'status_code': 'error'})
             set_response_header(response)
             return response
         plustag = Plustag.objects.get(pk=pk)
         if plustag.user_send_plus == user:
             data = {
                 'data': plustag_vote_serialize(plustag),
                 'status_code': 'ok'
             }
             response = JsonResponse(data)
             set_response_header(response)
             return response
         else:
             try:
                 pv = PlustagVoteModel.objects.create(plustag=plustag,
                                                      user_vote=user,
                                                      been_vote=True)
                 plustag.votes += 1
                 plustag.save()
                 data = {
                     'data': plustag_vote_serialize(plustag),
                     'status_code': 'ok'
                 }
                 response = JsonResponse(data)
                 set_response_header(response)
                 return response
             except IntegrityError:
                 pv = PlustagVoteModel.objects.get(plustag=plustag,
                                                   user_vote=user)
                 if pv.been_vote == True:
                     pv.been_vote = False
                     pv.save()
                     plustag.votes -= 1
                     plustag.save()
                 else:
                     pv.been_vote = True
                     pv.save()
                     plustag.votes += 1
                     plustag.save()
                 data = {
                     'data': plustag_vote_serialize(plustag),
                     'status_code': 'ok'
                 }
                 response = JsonResponse(data)
                 set_response_header(response)
                 return response
 def get(self, request):
     if check_authentication(request):
         user_request = get_user(request)
         try:
             total = int(request.GET.get('total'))
         except:
             response_error()
         target = request.GET.get('target')
         user_receive_id = request.GET.getlist('listId[]')
         #now it is just 1 item in user_receive_id
         user_receive_id = user_receive_id[0]
         try:
             user_receive = User.objects.get(user_id=user_receive_id)
         except User.DoesNotExist:
             response_error()
         if total == 2 and target == 'user':
             m = MessageFrame.objects.filter(message_type='user').filter(
                 users=user_request).filter(users=user_receive)
             if len(m) == 1 and len(m[0].users.all()) == 2:
                 data = {
                     'frame_id':
                     m[0].id,
                     'status_code':
                     'ok',
                     'users': [
                         serialize_user_basic(user_request),
                         serialize_user_basic(user_receive)
                     ]
                 }
             elif len(m) == 0:
                 m = MessageFrame.objects.create(message_type='user')
                 m.users.add(user_request)
                 m.users.add(user_receive)
                 m.save()
                 data = {
                     'frame_id':
                     m.id,
                     'status_code':
                     'ok',
                     'users': [
                         serialize_user_basic(user_request),
                         serialize_user_basic(user_receive)
                     ]
                 }
             else:
                 data = {'status_code': 'error'}
         else:
             data = {'status_code': 'error'}
         response = HttpResponse('while(1);' + json.dumps(data),
                                 content_type='text/javascript')
         set_response_header(response)
         return response
    def post(self, request):
        if check_authentication(request, True):
            user = get_user(request)
            data = request.POST
            try:
                status = Status.objects.get(
                    pk__exact=int(request.POST.get('feed_pk')))
            except Status.DoesNotExist:
                return JsonResponse({'status_type': 'error'})
            sc = StatusComment.objects.create(user=user,
                                              status=status,
                                              comment=request.POST.get('text'))
            self.define_plustag(status, user, request.POST.get('text'))
            if status.user and user != status.user:
                noti = Notification.objects.create(user=status.user,
                                                   noti_type='status-b')
                StatusBNotification.objects.create(noti=noti,
                                                   status=status,
                                                   statuscomment=sc)
            # friendship

            #if status.user:
            #    try:
            #        friend = status.user
            #        x = Friend.objects.get(user = user, friend = friend)
            #        try:
            #            t = FriendRelationship.objects.get(user = user, friend = x)
            #        except FriendRelationship.DoesNotExist:
            #             t = FriendRelationship.objects.create(user = user, friend = x)
            #        finally:
            #            try:
            #                a = FriendHeart.objects.get(user = user, friend = friend, friendrelationship = t, source = 'status',reason = 'comment',status = status)
            #            except FriendHeart.DoesNotExist:
            #                a = FriendHeart.objects.create(user = user, friend = friend, friendrelationship = t, source = 'status',reason = 'comment',status = status)
            #                a.heart = random.randint(1,2)
            #                t.friend_heart += a.heart
            #                a.save()
            #                t.save()
            #    except Friend.DoesNotExist:
            #        pass
            comment = status_comment_serialize(status, 1)
            response = JsonResponse({
                'comments':
                comment,
                'plustags':
                status_plustag_serialize(status),
                'status_type':
                'ok'
            })
            set_response_header(response)
            return response
 def get(self, request):
     if check_authentication(request, True):
         user = get_user(request)
         data = {'status_code': 'ok', 'user': serialize_user_basic(user)}
         response = HttpResponse(
             'while(1);' + json.dumps(data),
             content_type='application/x-javascript; charset=utf-8')
         set_response_header(response)
         return response
     data = {'status_code': 'error'}
     response = HttpResponse(
         'while(1);' + json.dumps(data),
         content_type='application/x-javascript; charset=utf-8')
     set_response_header(response)
     return response
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         name = request.GET.get('name')
         friendIds = request.GET.getlist('friendIds')
         if name:
             friends = Friend.objects.filter(
                 user=user, friend__fullname__icontains=name).exclude(
                     friend__user_id__in=friendIds)
         else:
             friends = []
         data = friend_serialize(friends)
         response = JsonResponse({'status_code': 'ok', 'friends': data})
         set_response_header(response)
         return response
Beispiel #14
0
 def post(self, request):
     if check_authentication(request):
         user = get_user(request)
         try:
             a = OnlineTime.objects.create(user=user)
         except IntegrityError:
             a = OnlineTime.objects.get(user=user)
             a.time = timezone.now()
             a.save()
             data = {
                 'status_code': 'ok',
             }
             response = HttpResponse('while(1);' + json.dumps(data),
                                     content_type='text/javascript')
             set_response_header(response)
             return response
     else:
         response = JsonResponse({'status_code': 'error'})
         set_response_header(response)
         return response
Beispiel #15
0
    def post(self, request):
        tab_id = request.GET.get('tab_id')

        tab_name = request.POST.get('tab_name')

        # action type is delete user or add user
        action_type = request.POST.get('action_type')

        if check_authentication(request):
            user = get_user(request)
            if action_type == 'create_tab':
                try:
                    a = FollowTimeline.objects.get(name=tab_name, user=user)
                    data = {'status_code': 'error'}
                except FollowTimeline.DoesNotExist:
                    a = FollowTimeline.objects.create(name=tab_name, user=user)
                    data = {'status_code': 'ok'}
                response = JsonResponse(data)
                set_response_header(response)
                return response
 def post(self, request):
     if check_authentication(request):
         user = get_user(request)
         try:
             pk = int(request.POST.get('plustagPk'))
         except:
             response = JsonResponse({'status_code': 'error'})
             set_response_header(response)
             return response
         plustag = Plustag.objects.get(pk=pk)
         status = plustag.status
         if status.user == user:
             plustag.delete()
             response = JsonResponse({'status_code': 'ok'})
             set_response_header(response)
             return response
         else:
             response = JsonResponse({'status_code': 'error'})
             set_response_header(response)
             return response
 def post(self, request):
     if check_authentication(request):
         user_request = get_user(request)
         text = request.POST.get('text')
         frame_id = request.POST.get('frameId')
         try:
             frame_id = int(frame_id)
         except:
             response_error()
         chat_frame = MessageFrame.objects.get(pk=frame_id)
         if text:
             m = Message.objects.create(user_send=user_request,
                                        chat_frame=chat_frame,
                                        text=text)
             # create or get a messageFrameInfo to detect user read or not read
             users_of_chat_frame = chat_frame.users.all()
             for user in users_of_chat_frame:
                 try:
                     a = MessageUserInfo.objects.get(frame=chat_frame,
                                                     user=user)
                 except MessageUserInfo.DoesNotExist:
                     a = MessageUserInfo.objects.create(frame=chat_frame,
                                                        user=user)
                 if user != user_request:
                     a.read = False
                     a.fetch = False
                     a.save()
                     # here to create messagereadInfo for each message
                     mri = MessageReadInfo.objects.create(user=user,
                                                          message=m,
                                                          read=False,
                                                          fetch=False)
         data = {'status_code': 'ok', 'mess': message_serialize(m)}
         response = HttpResponse(
             'while(1);' + json.dumps(data),
             content_type='application/x-javascript;charset=utf-8')
         set_response_header(response)
         return response
 def get(self, request):
     if check_authentication(request):
         user = get_user(request)
         # all or family or friends
         tab_section = request.GET.get('tab_section')
         try:
             currentIndex = int(request.GET.get('currentIndex'))
         except ValueError:
             currentIndex = 0
         fr = Friend.objects.filter(user=user).values_list('friend_id',
                                                           flat=True)
         if tab_section == '':
             status = Status.objects.filter(
                 Q(user=user) | Q(user_id__in=list(fr)),
                 who_post='user',
                 verb='post').order_by(
                     '-time_create')[currentIndex:currentIndex + 10]
         elif tab_section == 'friend':
             status = Status.objects.filter(
                 Q(user=user) | Q(user_id__in=list(fr)),
                 who_post='user',
                 verb='post').order_by(
                     '-time_create')[currentIndex:currentIndex + 10]
         elif tab_section == 'sale':
             status = Status.objects.filter(
                 Q(user=user) | Q(user_id__in=list(fr)),
                 who_post='user',
                 verb='sale').order_by(
                     '-time_create')[currentIndex:currentIndex + 10]
         else:
             status = Status.objects.none()
         reset(status)
         data_serialize = status_serialize(status, user)
         data = {'data': data_serialize, 'status_code': 'ok'}
         response = JsonResponse(data)
         set_response_header(response)
         return response
 def get(self, request, *a, **kw):
     isSelf = False
     isStranger = False
     isFriend = False
     user = None
     if check_authentication(request):
         user = get_user(request)
         friends = Friend.objects.filter(user=user)
     profile_url = request.GET.get('profileUrl')
     try:
         user_visited = User.objects.get(
             account__profilename__exact=profile_url)
     except User.DoesNotExist:
         response = JsonResponse({'status_code': 'error'})
         set_response_header(response)
         return response
     if user:
         if user == user_visited:
             isSelf = True
         elif user_visited.id in friends.values_list('friend_id',
                                                     flat=True):
             isFriend = True
         else:
             isStranger = True
     data = {
         'user': serialize_user_basic(user_visited),
         'relationShip': {
             'isSelf': isSelf,
             'isFriend': isFriend,
             'isStranger': isStranger
         },
         'status_code': 'ok'
     }
     response = JsonResponse(data)
     set_response_header(response)
     return response
Beispiel #20
0
    def get(self, request):
        # tab id of each tab. If this is empty, it means that tab has not created. This is required
        tab_id = request.GET.get('tab_id')

        # tab name of each tab. This is optional because searching not based on name but based on id. When tab_id is empty, this must be not empty. Such as 'family' because it has created on client but not on the server so it has name but not has id yet
        tab_name = request.GET.get('tab_name')

        # type of GET request: 'fetch_user' is fetching all User in this tab and 'filter_user' is filtering User when user type name in input
        action_type = request.GET.get('action_type')

        # input_name is text user type in input to filter user has not been in this tab
        input_name = request.GET.get('input_name')

        # friend Ids is the ID has been typed in input field. Those will be filtered out for the results.
        friendIds = request.GET.getlist('friend_ids')

        # check authentication and get user
        if check_authentication(request):
            user = get_user(request)
            if action_type == 'fetch_user':
                if tab_id:
                    try:
                        TabFollower = FollowTimeline.objects.get(
                            follow_id=tab_id, user=user)
                        users = TabFollower.members.all()
                        data_se = []
                        for i in users:
                            data_se.append(serialize_user_basic(i))
                        data = {'status_code': 'ok', 'data': data_se}
                    except FollowTimeline.DoesNotExist:
                        data = {'status_code': 'error'}
                elif tab_name:
                    try:
                        TabFollower = FollowTimeline.objects.get(name=tab_name,
                                                                 user=user)
                        users = TabFollower.members.all()
                        data_se = []
                        for i in users:
                            data_se.append(serialize_user_basic(i))
                        data = {'status_code': 'ok', 'data': data_se}
                    except FollowTimeline.DoesNotExist:
                        data = {'status_code': 'error'}
                else:
                    data = {'status_code': 'ok'}
                response = JsonResponse(data)
                set_response_header(response)
                return response
            elif action_type == 'filter_user':
                if tab_id:
                    try:
                        TabFollower = FollowTimeline.objects.get(
                            follow_id=tab_id, user=user)
                        users_id_in_tab_followers = TabFollower.members.all(
                        ).values_list('id', flat=True)
                        friends = Friend.objects.filter(
                            friend__fullname__icontains=input_name,
                            user=user).exclude(
                                friend__user_id__in=users_id_in_tab_followers
                            ).exclude(friend__user_id__in=friendIds)
                        data_se = []
                        for i in friends:
                            data_se.append(serialize_user_basic(i.friend))
                        data = {'status_code': 'ok', 'data': data_se}
                    except FollowTimeline.DoesNotExist:
                        data = {'status_code': 'error'}
                elif tab_name:
                    try:
                        TabFollower = FollowTimeline.objects.get(name=tab_name,
                                                                 user=user)
                        users_id_in_tab_followers = TabFollower.members.all(
                        ).values_list('id', flat=True)
                        friends = Friend.objects.filter(
                            friend__fullname__icontains=input_name,
                            user=user).exclude(
                                friend__user_id__in=users_id_in_tab_followers
                            ).exclude(friend__user_id__in=friendIds)
                        data_se = []
                        for i in friends:
                            data_se.append(serialize_user_basic(i.friend))
                        data = {'status_code': 'ok', 'data': data_se}
                    except FollowTimeline.DoesNotExist:
                        data = {'status_code': 'error'}
                else:
                    data = {'status_code': 'ok'}
                response = JsonResponse(data)
                set_response_header(response)
                return response
            else:
                data = {'status_code': 'error'}
                response = JsonResponse(data)
                set_response_header(response)
                return response
    def post(self, request):
        if check_authentication(request):
            user = get_user(request)
            try:
                reactionPk = int(request.POST.get('reaction'))
                reaction_type = request.POST.get('type')
            except ValueError:
                return JsonResponse({'status_type': 'ok'})
            status_reaction = StatusReaction.objects.get(
                pk=reactionPk, reactionType=reaction_type)
            status = status_reaction.status
            try:
                #vote = StatusVote.objects.create(user = user, status = status)
                #status.vote += 1
                #status.save()
                #vote.been_vote = True
                #vote.save()
                #if status.user and user != status.user:
                #    noti = Notification.objects.create(user = status.user, noti_type = 'status-a')
                #    StatusANotification.objects.create(noti = noti, status = status, who_vote = user)

                reaction_vote = StatusReactionVote.objects.create(
                    statusreaction=status_reaction, user=user)
                # specific reaction of status
                status_reaction.vote += 1
                status_reaction.save()
                reaction_vote.been_vote = True
                reaction_vote.save()
                # the whole votes for all reactions
                status.vote += 1
                status.save()
                if status.user and user != status.user:
                    noti = Notification.objects.create(user=status.user,
                                                       noti_type='status-a')
                    StatusANotification.objects.create(noti=noti,
                                                       status=status,
                                                       user=user)
            except IntegrityError:
                #vote = StatusVote.objects.get(user = user, status = status)
                #if vote.been_vote == True:
                #    status.vote -= 1
                #    status.save()
                #    vote.been_vote = False
                #    vote.save()
                #else:
                #    status.vote += 1
                #    status.save()
                #    vote.been_vote = True
                #    vote.save()
                reaction_vote = StatusReactionVote.objects.get(
                    statusreaction=status_reaction, user=user)
                if reaction_vote.been_vote == True:
                    reaction_vote.been_vote = False
                    reaction_vote.save()
                    status_reaction.vote -= 1
                    status_reaction.save()
                    status.vote -= 1
                    status.save()
                else:
                    reaction_vote.been_vote = True
                    reaction_vote.save()
                    status_reaction.vote += 1
                    status_reaction.save()
                    status.vote += 1
                    status.save()
            heart = 0
            if status.user:
                try:
                    friend = status.user
                    x = Friend.objects.get(user=user, friend=friend)
                    try:
                        t = FriendRelationship.objects.get(user=user, friend=x)
                    except FriendRelationship.DoesNotExist:
                        t = FriendRelationship.objects.create(user=user,
                                                              friend=x)
                    finally:
                        try:
                            a = FriendHeart.objects.get(user=user,
                                                        friend=friend,
                                                        friendrelationship=t,
                                                        source='status',
                                                        reason='like',
                                                        status=status)
                        except FriendHeart.DoesNotExist:
                            a = FriendHeart.objects.create(
                                user=user,
                                friend=friend,
                                friendrelationship=t,
                                source='status',
                                reason='like',
                                status=status)
                        finally:
                            if reaction_vote.been_vote == True:
                                a.heart = 1
                                t.friend_heart += a.heart
                            else:
                                t.friend_heart -= a.heart
                                a.heart = 0
                            a.save()
                            t.save()
                            zz = FriendHeart.objects.filter(
                                user=user,
                                friend=friend,
                                friendrelationship=t,
                                status=status)
                            for i in zz:
                                heart += i.heart
                except Friend.DoesNotExist:
                    pass
            response = JsonResponse({
                'been_vote': reaction_vote.been_vote,
                'user': {
                    'user': serialize_user_basic(user)
                },
                'status_type': 'ok'
            })
            set_response_header(response)
            return response