Beispiel #1
0
 def new(self, request, pk=None):
     data = request.data
     author = get_overflow_user(data['author'])
     tags = Tag.objects.filter(title__in=data['tags'])
     question = Question.objects.create(
         title=data['title'],
         body=data['body'],
         author=author
     )
     question.tags.set(tags)
     return Response(request.data)
Beispiel #2
0
 def overflow_user_profile(self, request, pk=None):
     name = request.data['author']
     overflow_user = get_overflow_user(name)
     return Response({
         "name": overflow_user.name,
         "bio": overflow_user.bio,
         "reputation": overflow_user.reputation,
         "interests": overflow_user.interests.all().values(),
         "favorites": [i["id"] for i in
                       overflow_user.favorites.all().values()],
         "favorite_obj": overflow_user.favorites.all().values(),
         })
Beispiel #3
0
 def favorite(self, request, pk=None):
     data = request.data
     overflow_user = get_overflow_user(data['author'])
     question = Question.objects.get(
         id=data['id']
         )
     favorites = overflow_user.favorites.all()
     if question not in favorites:
         overflow_user.favorites.add(question)
         return Response({"favorite": True})
     else:
         overflow_user.favorites.remove(question)
         return Response({"favorite": False})
Beispiel #4
0
 def new(self, request, pk=None):
     data = request.data
     question = Question.objects.filter(
         body=data['question']['body']).first()
     new_comment_author = get_overflow_user(data['author'])
     new_comment = Comment.objects.create(
         body=data['comment'],
         author=new_comment_author
     )
     question.comment.add(new_comment)
     new_notification = Notification.objects.create(
         answer_user=new_comment_author,
         answer=new_comment,
         question=question
     )
     question.author.notifications.add(new_notification)
     return Response({
         'id': new_comment.id,
         'body': new_comment.body,
         'author': new_comment_author.name,
         'date': new_comment.date,
         'upvote': new_comment.upvote.all().values(),
         'downvote': new_comment.downvote.all().values(),
     })
Beispiel #5
0
 def bio(self, request):
     data = request.data
     author = get_overflow_user(data['author']['name'])
     author.bio = data['bio']
     author.save()
     return Response(author.bio)