Beispiel #1
0
 def ins(self, request, name):
     user = get_object_or_400(User, name=name)
     ins = User.objects.get_ins(user)
     page = self.paginate_queryset(format_ins(ins))
     if page is not None:
         return self.get_paginated_response(page)
     return json_response(page)
Beispiel #2
0
 def following(self, request, name):
     user = get_object_or_400(User, name=name)
     following = User.objects.get_following(user)
     page = self.paginate_queryset(following)
     if page is not None:
         return self.get_paginated_response(page)
     return json_response(page)
Beispiel #3
0
 def followedins(self, request, name):
     user = get_object_or_400(User, name=name)
     queue_manager = QueueManager()
     queue_name = 'uid_{}'.format(user.uuid)
     ins_list = queue_manager.get_user_followed_ins(queue_name)
     page = self.paginate_queryset(ins_list)
     if page is not None:
         return self.get_paginated_response(page)
     return json_response(page)
Beispiel #4
0
 def comments(self, request, pk):
     # globals()['_comments_{}'.format(request.method.lower())](self, request, pk)
     ins = get_object_or_400(Ins, uuid=pk)
     if request.method == 'GET':
         comments = Ins.ins_objects.get_comments(ins)
         page = self.paginate_queryset(
             CommentSerializer(comments, many=True).data)
         if page is not None:
             return self.get_paginated_response(page)
         return json_response(page)
     else:
         data = request.data
         comment_keys = ['type', 'body']
         check_keys(data, comment_keys)
         if 'type' in data:
             validate_value(data['type'], const.COMMENT_TYPES)
         data.update({'user': request.user, 'ins': ins})
         comment = Comment.objects.create(**data)
         data = CommentSerializer(comment).data
         send_hook_request(comment,
                           method='POST',
                           context=request,
                           data=data)
         return json_response(data)
Beispiel #5
0
def _get_user_profile(obj):
    # 获取评论者的用户信息或者用户发表ins时候的用户信息
    user = get_object_or_400(User, uuid=obj['user']) if isinstance(
        obj, dict) else obj.user
    return {'avatar': user.avatar, 'username': user.name, 'uuid': user.uuid}
Beispiel #6
0
 def unfollow(self, request, name):
     target_user = get_object_or_400(User, name=name)
     request.user.followed.remove(target_user)
     return empty_response()
Beispiel #7
0
 def detail(self, request, pk):
     ins = get_object_or_400(Ins, uuid=pk)
     ins_detail = format_ins_detail(ins)
     return json_response(ins_detail)