Configures ruff as the one stop linter and resolves warnings it raised

This commit is contained in:
Trenton H
2023-03-28 09:39:30 -07:00
parent 5869467db3
commit ce41ac9158
110 changed files with 507 additions and 491 deletions

View File

@@ -265,10 +265,7 @@ class DocumentViewSet(
def get_serializer(self, *args, **kwargs):
super().get_serializer(*args, **kwargs)
fields_param = self.request.query_params.get("fields", None)
if fields_param:
fields = fields_param.split(",")
else:
fields = None
fields = fields_param.split(",") if fields_param else None
truncate_content = self.request.query_params.get("truncate_content", "False")
serializer_class = self.get_serializer_class()
kwargs.setdefault("context", self.get_serializer_context())
@@ -358,7 +355,7 @@ class DocumentViewSet(
try:
doc = Document.objects.get(pk=pk)
except Document.DoesNotExist:
raise Http404()
raise Http404
meta = {
"original_checksum": doc.checksum,
@@ -422,7 +419,7 @@ class DocumentViewSet(
response = self.file_response(pk, request, "inline")
return response
except (FileNotFoundError, Document.DoesNotExist):
raise Http404()
raise Http404
@action(methods=["get"], detail=True)
@method_decorator(cache_control(public=False, max_age=315360000))
@@ -438,14 +435,14 @@ class DocumentViewSet(
return HttpResponse(handle, content_type="image/webp")
except (FileNotFoundError, Document.DoesNotExist):
raise Http404()
raise Http404
@action(methods=["get"], detail=True)
def download(self, request, pk=None):
try:
return self.file_response(pk, request, "attachment")
except (FileNotFoundError, Document.DoesNotExist):
raise Http404()
raise Http404
def getNotes(self, doc):
return [
@@ -468,7 +465,7 @@ class DocumentViewSet(
try:
doc = Document.objects.get(pk=pk)
except Document.DoesNotExist:
raise Http404()
raise Http404
currentUser = request.user
@@ -569,7 +566,7 @@ class UnifiedSearchViewSet(DocumentViewSet):
elif "more_like_id" in self.request.query_params:
query_class = index.DelayedMoreLikeThisQuery
else:
raise ValueError()
raise ValueError
return query_class(
self.searcher,
@@ -606,12 +603,12 @@ class LogViewSet(ViewSet):
def retrieve(self, request, pk=None, *args, **kwargs):
if pk not in self.log_files:
raise Http404()
raise Http404
filename = self.get_log_filename(pk)
if not os.path.isfile(filename):
raise Http404()
raise Http404
with open(filename) as f:
lines = [line.rstrip() for line in f.readlines()]