diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 196ed9ed7..c2c162e9e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,12 +8,12 @@ repos: rev: 22.8.0 hooks: - id: black - language_version: python3.6 - - repo: https://github.com/pycqa/isort - rev: 5.6.4 - hooks: - - id: isort - args: ["--profile", "black", "--filter-files"] + language_version: python3.11.10 + # - repo: https://github.com/pycqa/isort + # rev: 5.6.4 + # hooks: + # - id: isort + # args: ["--profile", "black", "--filter-files"] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.1.0 hooks: diff --git a/gcloud/core/models.py b/gcloud/core/models.py index d40abdbbf..fe9510cac 100644 --- a/gcloud/core/models.py +++ b/gcloud/core/models.py @@ -19,6 +19,7 @@ from django.db import models, transaction from django.db.models import Q from django.utils import timezone +import pytz from django.utils.translation import gettext_lazy as _ from gcloud.constants import TEMPLATE_SOURCE @@ -208,7 +209,7 @@ def update_business_project_status(self, archived_cc_ids, active_cc_ids): def get_timezone_based_timestamp(self, project_id, timestamp_fmt="%Y%m%d%H%M%S"): project_tz = getattr(self.filter(id=project_id).first(), "time_zone") or settings.TIME_ZONE - timestamp = datetime.datetime.now(tz=timezone.pytz.timezone(project_tz)).strftime(timestamp_fmt) + timestamp = datetime.datetime.now(tz=pytz.timezone(project_tz)).strftime(timestamp_fmt) return timestamp diff --git a/gcloud/core/views.py b/gcloud/core/views.py index a25cc3ac4..5ded940f6 100644 --- a/gcloud/core/views.py +++ b/gcloud/core/views.py @@ -30,11 +30,16 @@ logger = logging.getLogger("root") +def get_response(request): + # 这是一个假函数,用于模拟正常的 get_response 逻辑 + return None + + def page_not_found(request, exception): if request.path.startswith(settings.STATIC_URL): return HttpResponseNotFound() - user = LoginRequiredMiddleware().authenticate(request) + user = LoginRequiredMiddleware(get_response).authenticate(request) if user: request.user = user @@ -45,7 +50,7 @@ def page_not_found(request, exception): # 未登录重定向到首页,跳到登录页面 if hasattr(LoginRequiredMiddleware(), "is_user_forbidden"): - user_forbidden, msg = LoginRequiredMiddleware().is_user_forbidden(request) + user_forbidden, msg = LoginRequiredMiddleware(get_response).is_user_forbidden(request) if user_forbidden: handler = ResponseHandler(ConfFixture, settings) return handler.build_403_response(msg) diff --git a/gcloud/taskflow3/domains/context.py b/gcloud/taskflow3/domains/context.py index 5169f195f..0951ec9f9 100644 --- a/gcloud/taskflow3/domains/context.py +++ b/gcloud/taskflow3/domains/context.py @@ -14,7 +14,8 @@ import logging from django.conf import settings -from django.utils import timezone, translation +from django.utils import translation +import pytz from django.utils.translation import gettext_lazy as _ from engine_pickle_obj.context import SystemObject @@ -52,7 +53,7 @@ def __init__(self, taskflow, username): self.biz_cc_name = self.bk_biz_name # 任务开始时间 project = Project.objects.get(id=self.project_id) - project_tz = timezone.pytz.timezone(project.time_zone) + project_tz = pytz.timezone(project.time_zone) self.task_start_time = datetime.datetime.now(tz=project_tz).strftime("%Y-%m-%d %H:%M:%S") # 任务URL self.task_url = ( diff --git a/pipeline_plugins/components/collections/controller.py b/pipeline_plugins/components/collections/controller.py index bb1a201b6..3bc83f6e6 100644 --- a/pipeline_plugins/components/collections/controller.py +++ b/pipeline_plugins/components/collections/controller.py @@ -17,7 +17,8 @@ import re from django.conf import settings -from django.utils import timezone, translation +from django.utils import translation +import pytz from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service, StaticIntervalGenerator @@ -119,7 +120,7 @@ def execute(self, data, parent_data): # 项目时区获取 project = Project.objects.get(id=parent_data.inputs.project_id) - project_tz = timezone.pytz.timezone(project.time_zone) + project_tz = pytz.timezone(project.time_zone) data.outputs.business_tz = project_tz now = datetime.datetime.now(tz=project_tz) diff --git a/pipeline_plugins/components/collections/subprocess_plugin/v1_0_0.py b/pipeline_plugins/components/collections/subprocess_plugin/v1_0_0.py index 3f7ef3d7f..8896ee144 100644 --- a/pipeline_plugins/components/collections/subprocess_plugin/v1_0_0.py +++ b/pipeline_plugins/components/collections/subprocess_plugin/v1_0_0.py @@ -19,7 +19,7 @@ from bamboo_engine.template import Template from django.conf import settings from django.db import transaction -from django.utils import timezone +import pytz from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow import Service @@ -128,7 +128,7 @@ def execute(self, data, parent_data): getattr(Project.objects.filter(id=parent_data.get_one_of_inputs("project_id")).first(), "time_zone") or settings.TIME_ZONE ) - time_stamp = datetime.datetime.now(tz=timezone.pytz.timezone(project_tz)).strftime("%Y%m%d%H%M%S") + time_stamp = datetime.datetime.now(tz=pytz.timezone(project_tz)).strftime("%Y%m%d%H%M%S") template_name = getattr(PipelineTemplate.objects.filter(template_id=subprocess.template_id).first(), "name") pipeline_instance_kwargs = { "name": f"{template_name}_{time_stamp}", diff --git a/pipeline_plugins/variables/collections/common.py b/pipeline_plugins/variables/collections/common.py index 5ae4f8531..5493f3e6e 100644 --- a/pipeline_plugins/variables/collections/common.py +++ b/pipeline_plugins/variables/collections/common.py @@ -17,7 +17,7 @@ from typing import List from django.conf import settings -from django.utils import timezone +import pytz from django.utils.translation import gettext_lazy as _ from pipeline.core.data.var import LazyVariable, RegisterVariableMeta, SpliceVariable from pipeline.core.flow.io import IntItemSchema, StringItemSchema @@ -213,7 +213,7 @@ def _self_explain(cls, **kwargs) -> List[FieldExplain]: def get_value(self): time_format = self.value.get("time_format", "%Y-%m-%d %H:%M:%S").strip() time_zone = self.value.get("time_zone", "Asia/Shanghai") - now = datetime.datetime.now(timezone.pytz.timezone(time_zone)) + now = datetime.datetime.now(pytz.timezone(time_zone)) current_time = now.strftime(time_format) return current_time @@ -233,7 +233,7 @@ def _self_explain(cls, **kwargs) -> List[FieldExplain]: def get_value(self): time_units = self.value.get("time_unit") or ["year", "month", "day", "hour", "minute", "second"] time_zone = self.value.get("time_zone", "Asia/Shanghai") - now = datetime.datetime.now(timezone.pytz.timezone(time_zone)) + now = datetime.datetime.now(pytz.timezone(time_zone)) current_time = now.strftime(self._generate_time_format(time_units)) return current_time