# Path: Blog/comments/api/views.py
# class CommentListAPIView(ListAPIView):
#     serializer_class = CommentListSerializer
#     filter_backends = [OrderingFilter]
#     pagination_class = PostLimitOffsetPagination
#     permission_classes = [AllowAny]
# 
#     def get_queryset(self, *args, **kwargs):
#         query_list = Comment.objects.filter(id__gte=0)
#         query = self.request.GET.get("q")
#         if query:
#             query_list = query_list.filter(
#                 Q(title__icontains=query) |
#                 Q(user__first_name__icontains=query) |
#                 Q(user__last_name__icontains=query) |
#                 Q(content__icontains=query)
#             ).distinct()
#         return query_list
# 
# class CommentDetailAPIView(RetrieveAPIView):
#     queryset = Comment.objects.all()
#     serializer_class = CommentDetailSerializer
#     lookup_field = "id"
#     permission_classes = [IsOwnerOrReadOnly]
# 
# class CommentCreateAPIView(CreateAPIView):
#     queryset = Comment.objects.all()
#     # permission_classes = [IsAuthenticated, IsAdminUser]
# 
#     def get_serializer_class(self):
#         model_type = self.request.GET.get("type")
#         slug = self.request.GET.get("slug")
#         parent_id = self.request.GET.get("parent_id", None)
#         return create_comment_serializer(
#             model_type=model_type,
#             slug=slug,
#             parent_id=parent_id,
#             user=self.request.user
#         )
# 
# class CommentEditAPIView(UpdateModelMixin, DestroyModelMixin, RetrieveAPIView):
#     queryset = Comment.objects.filter(id__gte=0)  # override the all function that filters out comments that are not parent
#     serializer_class = CommentDetailSerializer
#     lookup_field = "id"
#     permission_classes = [IsOwnerOrReadOnly]
# 
#     def put(self, request, *args, **kwargs):
#         self.update(request, *args, **kwargs)
# 
#     def delete(self, request, *args, **kwargs):
#         self.destroy(request,*args, **kwargs)


from django.conf.urls import url
from .views import CommentListAPIView, CommentDetailAPIView, CommentCreateAPIView, CommentEditAPIView

urlpatterns = [
    url(r"^$", CommentListAPIView.as_view(), name="list"),
    url(r"^(?P<id>\d+)/$", CommentDetailAPIView.as_view(), name="thread"),
    url(r"create", CommentCreateAPIView.as_view(), name="create"),
    url(r"^(?P<id>\d+)/edit$", CommentEditAPIView.as_view(), name="edit"),

# Path: Blog/comments/api/views.py
# class CommentListAPIView(ListAPIView):
#     serializer_class = CommentListSerializer
#     filter_backends = [OrderingFilter]
#     pagination_class = PostLimitOffsetPagination
#     permission_classes = [AllowAny]
# 
#     def get_queryset(self, *args, **kwargs):
#         query_list = Comment.objects.filter(id__gte=0)
#         query = self.request.GET.get("q")
#         if query:
#             query_list = query_list.filter(
#                 Q(title__icontains=query) |
#                 Q(user__first_name__icontains=query) |
#                 Q(user__last_name__icontains=query) |
#                 Q(content__icontains=query)
#             ).distinct()
#         return query_list
# 
# class CommentDetailAPIView(RetrieveAPIView):
#     queryset = Comment.objects.all()
#     serializer_class = CommentDetailSerializer
#     lookup_field = "id"
#     permission_classes = [IsOwnerOrReadOnly]
# 
# class CommentCreateAPIView(CreateAPIView):
#     queryset = Comment.objects.all()
#     # permission_classes = [IsAuthenticated, IsAdminUser]
# 
#     def get_serializer_class(self):
#         model_type = self.request.GET.get("type")
#         slug = self.request.GET.get("slug")
#         parent_id = self.request.GET.get("parent_id", None)
#         return create_comment_serializer(
#             model_type=model_type,
#             slug=slug,
#             parent_id=parent_id,
#             user=self.request.user
#         )
# 
# class CommentEditAPIView(UpdateModelMixin, DestroyModelMixin, RetrieveAPIView):
#     queryset = Comment.objects.filter(id__gte=0)  # override the all function that filters out comments that are not parent
#     serializer_class = CommentDetailSerializer
#     lookup_field = "id"
#     permission_classes = [IsOwnerOrReadOnly]
# 
#     def put(self, request, *args, **kwargs):
#         self.update(request, *args, **kwargs)
# 
#     def delete(self, request, *args, **kwargs):
#         self.destroy(request,*args, **kwargs)


# Path: Blog/comments/api/urls.py
from django.conf.urls import url
from .views import CommentListAPIView, CommentDetailAPIView, CommentCreateAPIView, CommentEditAPIView


urlpatterns = [
    url(r"^$", CommentListAPIView.as_view(), name="list"),
    url(r"^(?P<id>\d+)/$", CommentDetailAPIView.as_view(), name="thread"),
    url(r"create", CommentCreateAPIView.as_view(), name="create"),
    url(r"^(?P<id>\d+)/edit$", CommentEditAPIView.as_view(), name="edit"),

]