Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
WinnyTroy committed Jan 15, 2020
1 parent 177d84d commit eb06523
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions onadata/apps/api/tests/viewsets/test_attachment_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ def test_list_view_surfaces_current_attachment(self):

# test when the attachment is soft deleted
self.attachment.soft_delete(user=self.user)
self.attachment.save()

request = self.factory.get('/', **self.extra)
response = self.list_view(request)
Expand All @@ -246,7 +245,7 @@ def test_soft_delete_action_returns_correct_user(self):

# test when the attachment is soft deleted
self.attachment.soft_delete(user=self.user)
self.attachment.save()

# Test that deleted_by field captures the right user
self.assertTrue(self.attachment.deleted_by, self.user)

Expand Down
7 changes: 3 additions & 4 deletions onadata/apps/api/viewsets/attachment_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class AttachmentViewSet(AuthenticateHeaderMixin, CacheControlMixin, ETagsMixin,
content_negotiation_class = MediaFileContentNegotiation
filter_backends = (filters.AttachmentFilter, filters.AttachmentTypeFilter)
lookup_field = 'pk'
queryset = Attachment.objects.filter(instance__deleted_at__isnull=True)
queryset = Attachment.objects.filter(
instance__deleted_at__isnull=True, deleted_at__isnull=True)
permission_classes = (AttachmentObjectPermissions,)
serializer_class = AttachmentSerializer
pagination_class = StandardPageNumberPagination
Expand Down Expand Up @@ -100,9 +101,7 @@ def list(self, request, *args, **kwargs):
if not xform.shared_data:
raise Http404(_("Not Found"))

request_data = self.filter_queryset(self.get_queryset())
self.object_list = self.object_list = [
a for a in request_data if a.deleted_at is None]
self.object_list = self.filter_queryset(self.get_queryset())
page = self.paginate_queryset(self.object_list)
if page is not None:
serializer = self.get_serializer(page, many=True)
Expand Down

0 comments on commit eb06523

Please sign in to comment.