From f8e846415ac5b94c635ff9a8846d2977a61ad247 Mon Sep 17 00:00:00 2001
From: Sny <sny.aggarwal@gmail.com>
Date: Wed, 1 May 2024 16:46:40 +0530
Subject: [PATCH] OpenConceptLab/ocl_issues#1761 | fixing middleware and pylint

---
 core/common/renderers.py        |  2 +-
 core/middlewares/middlewares.py | 20 ++++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/core/common/renderers.py b/core/common/renderers.py
index 9163f973..0be081f9 100644
--- a/core/common/renderers.py
+++ b/core/common/renderers.py
@@ -23,4 +23,4 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
 
 
 class FhirRenderer(JSONRenderer):
-    media_type = 'application/fhir+json'
\ No newline at end of file
+    media_type = 'application/fhir+json'
diff --git a/core/middlewares/middlewares.py b/core/middlewares/middlewares.py
index ca9dcddf..300c5ee5 100644
--- a/core/middlewares/middlewares.py
+++ b/core/middlewares/middlewares.py
@@ -2,7 +2,7 @@
 import time
 
 import requests
-from django.http import HttpResponseNotFound, HttpRequest, HttpResponse
+from django.http import HttpResponseNotFound, HttpResponse
 from request_logging.middleware import LoggingMiddleware
 
 from core.common.constants import VERSION_HEADER, REQUEST_USER_HEADER, RESPONSE_TIME_HEADER, REQUEST_URL_HEADER, \
@@ -107,26 +107,26 @@ def __call__(self, request):
             elif is_fhir_resource:
                 return HttpResponseNotFound()
 
-        if settings.FHIR_VALIDATOR_URL and ('/CodeSystem/' in absolute_uri or '/ValueSet/' in absolute_uri or
-                                            '/ConceptMap' in absolute_uri):
-            accept_content_type = request.headers.get('Accept')
-            content_type = request.headers.get('Content-Type')
+        if settings.FHIR_VALIDATOR_URL and (
+                '/CodeSystem/' in absolute_uri or '/ValueSet/' in absolute_uri or '/ConceptMap' in absolute_uri):
+            accept_content_type = request.headers.get('Accept', '')
+            content_type = request.headers.get('Content-Type', '')
 
             if content_type.startswith('application/xml') or content_type.startswith('application/fhir+xml'):
                 request.META['CONTENT_TYPE'] = "application/json"
-                if request.method == 'POST' or request.method == 'PUT':
+                if request.method in ['POST', 'PUT']:
                     json_request = requests.post(settings.FHIR_VALIDATOR_URL +
                                                  '/convert?version=4.0&type=xml&toType=json', data=request.body)
                     request._body = json_request
 
-            if accept_content_type.startswith('application/xml') or \
-                    accept_content_type.startswith('application/fhir+xml'):
+            if accept_content_type.startswith(
+                    'application/xml') or accept_content_type.startswith('application/fhir+xml'):
                 request.META['HTTP_ACCEPT'] = "application/json"
 
             response = self.get_response(request)
 
-            if accept_content_type.startswith('application/xml') or \
-                    accept_content_type.startswith('application/fhir+xml'):
+            if accept_content_type.startswith(
+                    'application/xml') or accept_content_type.startswith('application/fhir+xml'):
                 xml_response = requests.post(settings.FHIR_VALIDATOR_URL + '/convert?version=4.0&type=json&toType=xml',
                                              data=response.content)
                 response = HttpResponse(xml_response, content_type=accept_content_type)