fixed comments

This commit is contained in:
Anatoly 2019-09-20 15:38:20 +03:00
parent 5f3947601a
commit 193ecfba7a
3 changed files with 1 additions and 35 deletions

View File

@ -47,15 +47,6 @@ class CollectionEstablishmentListView(CollectionListView):
""" """
queryset = super(CollectionEstablishmentListView, self).get_queryset() queryset = super(CollectionEstablishmentListView, self).get_queryset()
# Perform the lookup filtering. # Perform the lookup filtering.
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
assert lookup_url_kwarg in self.kwargs, (
'Expected view %s to be called with a URL keyword argument '
'named "%s". Fix your URL conf, or set the `.lookup_field` '
'attribute on the view correctly.' %
(self.__class__.__name__, lookup_url_kwarg)
)
collection = get_object_or_404(queryset, pk=self.kwargs['pk']) collection = get_object_or_404(queryset, pk=self.kwargs['pk'])
# May raise a permission denied # May raise a permission denied

View File

@ -263,7 +263,7 @@ class EstablishmentCommentCreateSerializer(comment_serializers.CommentSerializer
establishment_id = self.context.get('request').parser_context.get('kwargs').get('pk') establishment_id = self.context.get('request').parser_context.get('kwargs').get('pk')
establishment_qs = models.Establishment.objects.filter(id=establishment_id) establishment_qs = models.Establishment.objects.filter(id=establishment_id)
if not establishment_qs.exists(): if not establishment_qs.exists():
return serializers.ValidationError() raise serializers.ValidationError({'detail': _('Establishment not found.')})
attrs['establishment'] = establishment_qs.first() attrs['establishment'] = establishment_qs.first()
return attrs return attrs

View File

@ -79,14 +79,6 @@ class EstablishmentCommentRUDView(generics.RetrieveUpdateDestroyAPIView):
Returns the object the view is displaying. Returns the object the view is displaying.
""" """
queryset = self.filter_queryset(self.get_queryset()) queryset = self.filter_queryset(self.get_queryset())
lookup_url_kwargs = ('pk', 'comment_id')
assert lookup_url_kwargs in self.kwargs.keys(), (
'Expected view %s to be called with a URL keyword argument '
'named "%s". Fix your URL conf, or set the `.lookup_field` '
'attribute on the view correctly.' %
(self.__class__.__name__, lookup_url_kwargs)
)
establishment_obj = get_object_or_404(queryset, establishment_obj = get_object_or_404(queryset,
pk=self.kwargs['pk']) pk=self.kwargs['pk'])
@ -107,14 +99,6 @@ class EstablishmentFavoritesCreateDestroyView(generics.CreateAPIView, generics.D
""" """
Returns the object the view is displaying. Returns the object the view is displaying.
""" """
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
assert lookup_url_kwarg in self.kwargs, (
'Expected view %s to be called with a URL keyword argument '
'named "%s". Fix your URL conf, or set the `.lookup_field` '
'attribute on the view correctly.' %
(self.__class__.__name__, lookup_url_kwarg)
)
obj = get_object_or_404( obj = get_object_or_404(
self.request.user.favorites.by_content_type(app_label='establishment', self.request.user.favorites.by_content_type(app_label='establishment',
model='establishment') model='establishment')
@ -164,15 +148,6 @@ class EstablishmentScheduleRUDView(generics.RetrieveUpdateDestroyAPIView):
""" """
Returns the object the view is displaying. Returns the object the view is displaying.
""" """
lookup_url_kwargs = ('pk', 'schedule_id')
assert lookup_url_kwargs in self.kwargs.keys(), (
'Expected view %s to be called with a URL keyword argument '
'named "%s". Fix your URL conf, or set the `.lookup_field` '
'attribute on the view correctly.' %
(self.__class__.__name__, lookup_url_kwargs)
)
establishment_pk = self.kwargs['pk'] establishment_pk = self.kwargs['pk']
schedule_id = self.kwargs['schedule_id'] schedule_id = self.kwargs['schedule_id']