diff --git a/bkmonitor/config/dev.py b/bkmonitor/config/dev.py index 3efe1d4b30..2b35859774 100644 --- a/bkmonitor/config/dev.py +++ b/bkmonitor/config/dev.py @@ -70,5 +70,5 @@ INSTALLED_APPS += ("corsheaders",) # 该跨域中间件需要放在前面 MIDDLEWARE = ("corsheaders.middleware.CorsMiddleware",) + MIDDLEWARE - CORS_ORIGIN_ALLOW_ALL = True + CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_CREDENTIALS = True diff --git a/bkmonitor/config/prod.py b/bkmonitor/config/prod.py index ec30a8d8b0..d17bf60959 100644 --- a/bkmonitor/config/prod.py +++ b/bkmonitor/config/prod.py @@ -19,5 +19,5 @@ INSTALLED_APPS += ("corsheaders",) # 该跨域中间件需要放在前面 MIDDLEWARE = ("corsheaders.middleware.CorsMiddleware",) + MIDDLEWARE - CORS_ORIGIN_ALLOW_ALL = True + CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_CREDENTIALS = True diff --git a/bkmonitor/config/stag.py b/bkmonitor/config/stag.py index a74adadaa8..a1ad880dd9 100644 --- a/bkmonitor/config/stag.py +++ b/bkmonitor/config/stag.py @@ -21,5 +21,5 @@ INSTALLED_APPS += ("corsheaders",) # 该跨域中间件需要放在前面 MIDDLEWARE = ("corsheaders.middleware.CorsMiddleware",) + MIDDLEWARE - CORS_ORIGIN_ALLOW_ALL = True + CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_CREDENTIALS = True diff --git a/bkmonitor/core/drf_resource/base.py b/bkmonitor/core/drf_resource/base.py index 23057e5628..6d5016a9d3 100644 --- a/bkmonitor/core/drf_resource/base.py +++ b/bkmonitor/core/drf_resource/base.py @@ -308,11 +308,3 @@ def generate_doc(cls): "request_params": render_schema(request_params), "response_params": render_schema(response_params, using_source=True), } - - @classmethod - def etag(cls, request, *args, **kwargs): - return - - @classmethod - def last_modified(cls, request, *args, **kwargs): - return diff --git a/bkmonitor/core/drf_resource/routers.py b/bkmonitor/core/drf_resource/routers.py index 5cd6c44969..97ce1d603a 100644 --- a/bkmonitor/core/drf_resource/routers.py +++ b/bkmonitor/core/drf_resource/routers.py @@ -9,8 +9,7 @@ specific language governing permissions and limitations under the License. """ - -import six +from django.core.exceptions import ImproperlyConfigured from rest_framework.routers import DefaultRouter from rest_framework.viewsets import GenericViewSet @@ -33,16 +32,17 @@ def register(self, prefix, viewset, basename=None): 注册单个ResourceViewset """ self._init_resource_viewset(viewset) - # 如果已经注册过了viewset,则不进行注册 - if (prefix, viewset, basename or self.get_default_basename(viewset)) in self.registry: - return - super(ResourceRouter, self).register(prefix, viewset, basename) + + try: + super(ResourceRouter, self).register(prefix, viewset, basename) + except ImproperlyConfigured: + pass def register_module(self, viewset_module): """ 注册整个ResourceViewset模块,并根据类的命名规则自动生成对应的url """ - for attr, viewset in six.iteritems(viewset_module.__dict__): + for attr, viewset in viewset_module.__dict__.items(): # 全小写的属性不是类,忽略 if attr.startswith("_") or attr[0].islower(): continue diff --git a/bkmonitor/core/drf_resource/viewsets.py b/bkmonitor/core/drf_resource/viewsets.py index ceb2365d79..9aac251dfa 100644 --- a/bkmonitor/core/drf_resource/viewsets.py +++ b/bkmonitor/core/drf_resource/viewsets.py @@ -19,7 +19,6 @@ from rest_framework.decorators import action from rest_framework.response import Response from rest_framework.serializers import Serializer -from rest_framework_condition import condition from core.drf_resource.base import Resource @@ -181,10 +180,6 @@ def generate_endpoint(cls): url_path=resource_route.endpoint, url_name=resource_route.endpoint.replace("_", "-"), )(function) - function = condition( - etag_func=resource_route.resource_class.etag, - last_modified_func=resource_route.resource_class.last_modified, - )(function) function = decorator_function(function) setattr(cls, function.__name__, function) diff --git a/bkmonitor/requirements.txt b/bkmonitor/requirements.txt index 33d39b13f8..c397566a6f 100644 --- a/bkmonitor/requirements.txt +++ b/bkmonitor/requirements.txt @@ -8,7 +8,7 @@ Django==3.2.25 whitenoise==5.0 django-mysql==4.3.0 django-db-connection-pool==1.2.5 -django-cors-headers==3.2.1 +django-cors-headers==4.1.0 django-versionlog==1.6.0 # prometheus & django @@ -25,7 +25,6 @@ django-jinja==2.7.1 # django rest framework djangorestframework==3.12.4 -django-rest-framework-condition==0.1.1 django-filter==2.4.0 drf-yasg==1.21.5