Beispiel #1
0
    def get(self,request):


        user = request.user
        user_full_name = str(user.first_name)+" " +str(user.last_name)
        full_name = str(user.first_name)+" " +str(user.last_name)
        thumbnail = user.profile_photo.url

        post_list = FeedPost.objects.filter(user=user).order_by('-created_at')
        page = self.paginate_queryset(post_list)
        to_send = []
        print("page is",page)

        for post_obj in page:

            is_liked = is_post_liked(user,post_obj,'Feed')        
            image = post_obj.image

            if image.name!=u'':
                print("length of name is ",len(image.name))
                image = image.url
            else:
                image = None    



            if post_obj.is_edited is True:
                timestamp = post_obj.created_at
            else:
                timestamp = post_obj.modified_at
            print("image is",image)            
            to_add = {
                "thumbnail":thumbnail,
                "full_name":full_name,
                "user_id":user.id,
                # "activity_message":activity_message,
                "post_id":post_obj.id,
                "is_edited":post_obj.is_edited,
                "is_comment_disabled":post_obj.is_comment_disabled,
                "no_of_likes":post_obj.no_of_likes,
                "no_of_comments":post_obj.no_of_comments,
                "content":post_obj.content,
                "image":image,
                "is_liked":is_liked,
                "timestamp":timestamp,
                "post_type":'Feed',
                
                
            }

            to_send.append(to_add)


        print("to_send is",to_send)
        to_send = self.get_paginated_response(to_send)
        print("to_send is",to_send)

        return Response({"success":True,"data":to_send.data,"msg":"ok"},status=200)
Beispiel #2
0
    def post(self, request):
        requesting_user = request.user

        serializer = PostDetailSerializer(data=request.data)

        if serializer.is_valid():

            post_obj  = serializer.post_obj
            user = post_obj.user
            thumbnail = user.profile_photo.url
            is_liked = is_post_liked(requesting_user,post_obj,'Feed')            
            image = post_obj.image
            full_name = str(user.first_name)+" " +str(user.last_name)
            if image.name!=u'':
                print("length of name is ",len(image.name))
                image = image.url
            else:
                image = None    

            if post_obj.is_edited is True:
                timestamp = post_obj.modified_at
            else:
                timestamp = post_obj.created_at

            print("image is",image)            
            to_send = {
                "thumbnail":thumbnail,
                "full_name":full_name,
                "user_id":user.id,
                # "activity_message":activity_message,
                "post_id":post_obj.id,
                "is_edited":post_obj.is_edited,
                "is_comment_disabled":post_obj.is_comment_disabled,
                "no_of_likes":post_obj.no_of_likes,
                "no_of_comments":post_obj.no_of_comments,
                "content":post_obj.content,
                "image":image,
                "is_liked":is_liked,
                "timestamp":timestamp,
                "post_type":'Feed',
                
                
            }



            print("to_send is",to_send)

            return Response({"success":True,"data":to_send,"msg":"ok"},status=200)
        if serializer.errors:
            errors = serializer.errors
            print("error is ",errors)
            if errors.get('non_field_errors',None) is not None:
                error = {"message":errors['non_field_errors'][0]}
            
            return Response({"success":False,"error":error},status=400)
Beispiel #3
0
    def post(self,request):

        serializer = PostDetailSerializer(data=request.data)

        if serializer.is_valid():
            user = request.user    
            data = serializer.data 
            post_obj = serializer.post_obj

            post_type = data['post_type']
            is_liked = is_post_liked(user,post_obj,post_type)

            
            if post_type == "Feed":
                feed_post = post_obj
                group_post = None
                

            if post_type == "Group":
                group_post = post_obj
                feed_post = None
                


            if is_liked is False:
                return Response({"success":False,"error":{"message":"post already unliked"}},status=400)

            like_obj = Like.objects.get(user=user,feed_post=feed_post,group_post=group_post,
                )
            to_send = {"like_obj_id":like_obj.id}

            like_obj.delete()

            post_obj.no_of_likes -= 1
            post_obj.save()            

            return Response({"success":True,"data":to_send,"msg":"ok"},status=200)

        if serializer.errors:          
            errors = serializer.errors
            print("error is ",errors)
            if errors.get('non_field_errors',None) is not None:
                error = {"message":errors['non_field_errors'][0]}            
            return Response({"success":False,"error":error},status=400)
Beispiel #4
0
    def post(self,request):

        serializer = PostDetailSerializer(data=request.data)

        if serializer.is_valid():
            user = request.user    
            data = serializer.data 
            post_type = data['post_type']
            post_obj = serializer.post_obj

            is_liked = is_post_liked(user,post_obj,post_type)

            if is_liked is True:
                return Response({"success":False,"error":{"message":"post already liked"}},status=400)

            feed_post,group_post,activity_obj = create_activity_and_notification_object(
                        user,post_obj,post_type,'like_post')

            like_obj = Like.objects.create(user=user,feed_post=feed_post,group_post=group_post,
                )
            post_obj.no_of_likes += 1
            post_obj.save()


            
            activity_obj.like = like_obj
            activity_obj.save()

            to_send = {"like_obj_id":like_obj.id}
            # posts = FeedPost.objects.filter(user=user,vis)
            return Response({"success":True,"data":to_send,"msg":"ok"},status=200)

        if serializer.errors:          
            errors = serializer.errors
            print("error is ",errors)
            if errors.get('non_field_errors',None) is not None:
                error = {"message":errors['non_field_errors'][0]}            
            return Response({"success":False,"error":error},status=400)