Skip to content

Commit d600dc7

Browse files
committed
fix: 修复timezone修改成pytz,页面刷新404LoginRequiredMiddleware传入函数问题 TencentBlueKing#7625
1 parent 4a16b08 commit d600dc7

File tree

5 files changed

+58
-21
lines changed

5 files changed

+58
-21
lines changed

gcloud/core/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import typing
1515
from os import environ
1616

17+
import pytz
1718
from django.conf import settings
1819
from django.contrib.auth.models import Group
1920
from django.db import models, transaction
@@ -208,7 +209,7 @@ def update_business_project_status(self, archived_cc_ids, active_cc_ids):
208209

209210
def get_timezone_based_timestamp(self, project_id, timestamp_fmt="%Y%m%d%H%M%S"):
210211
project_tz = getattr(self.filter(id=project_id).first(), "time_zone") or settings.TIME_ZONE
211-
timestamp = datetime.datetime.now(tz=timezone.pytz.timezone(project_tz)).strftime(timestamp_fmt)
212+
timestamp = datetime.datetime.now(tz=pytz.timezone(project_tz)).strftime(timestamp_fmt)
212213
return timestamp
213214

214215

gcloud/core/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@
3030
logger = logging.getLogger("root")
3131

3232

33+
def get_response(request):
34+
# 这是一个假函数,用于模拟正常的 get_response 逻辑
35+
return None
36+
37+
3338
def page_not_found(request, exception):
3439
if request.path.startswith(settings.STATIC_URL):
3540
return HttpResponseNotFound()
3641

37-
user = LoginRequiredMiddleware().authenticate(request)
42+
user = LoginRequiredMiddleware(get_response).authenticate(request)
3843

3944
if user:
4045
request.user = user
@@ -45,7 +50,7 @@ def page_not_found(request, exception):
4550

4651
# 未登录重定向到首页,跳到登录页面
4752
if hasattr(LoginRequiredMiddleware(), "is_user_forbidden"):
48-
user_forbidden, msg = LoginRequiredMiddleware().is_user_forbidden(request)
53+
user_forbidden, msg = LoginRequiredMiddleware(get_response).is_user_forbidden(request)
4954
if user_forbidden:
5055
handler = ResponseHandler(ConfFixture, settings)
5156
return handler.build_403_response(msg)

gcloud/taskflow3/domains/context.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
import datetime
1414
import logging
1515

16+
import pytz
1617
from django.conf import settings
17-
from django.utils import timezone, translation
18+
from django.utils import translation
1819
from django.utils.translation import ugettext_lazy as _
1920

2021
from engine_pickle_obj.context import SystemObject
@@ -52,7 +53,7 @@ def __init__(self, taskflow, username):
5253
self.biz_cc_name = self.bk_biz_name
5354
# 任务开始时间
5455
project = Project.objects.get(id=self.project_id)
55-
project_tz = timezone.pytz.timezone(project.time_zone)
56+
project_tz = pytz.timezone(project.time_zone)
5657
self.task_start_time = datetime.datetime.now(tz=project_tz).strftime("%Y-%m-%d %H:%M:%S")
5758
# 任务URL
5859
self.task_url = (
@@ -128,7 +129,12 @@ def flat_details(cls):
128129
"index": -3,
129130
"desc": "",
130131
},
131-
cls.to_flat_key("task_id"): {"key": cls.to_flat_key("task_id"), "index": -2, "name": _("任务ID"), "desc": ""},
132+
cls.to_flat_key("task_id"): {
133+
"key": cls.to_flat_key("task_id"),
134+
"index": -2,
135+
"name": _("任务ID"),
136+
"desc": "",
137+
},
132138
cls.to_flat_key("task_name"): {
133139
"key": cls.to_flat_key("task_name"),
134140
"name": _("任务名称"),

pipeline_plugins/components/collections/controller.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
import os
1717
import re
1818

19+
import pytz
1920
from django.conf import settings
20-
from django.utils import timezone, translation
21+
from django.utils import translation
2122
from django.utils.translation import ugettext_lazy as _
2223
from pipeline.component_framework.component import Component
2324
from pipeline.core.flow.activity import Service, StaticIntervalGenerator
@@ -79,7 +80,9 @@ class PauseComponent(Component):
7980
code = "pause_node"
8081
bound_service = PauseService
8182
form = settings.STATIC_URL + "components/atoms/bk/pause.js"
82-
desc = _("该节点可以通过node_callback API接口进行回调并传入数据,callback_data参数为dict类型,回调数据会作为该节点的输出数据")
83+
desc = _(
84+
"该节点可以通过node_callback API接口进行回调并传入数据,callback_data参数为dict类型,回调数据会作为该节点的输出数据"
85+
)
8386

8487

8588
class SleepTimerService(Service):
@@ -103,7 +106,9 @@ def inputs_format(self):
103106
name=_("是否强制晚于当前时间"),
104107
key="force_check",
105108
type="bool",
106-
schema=StringItemSchema(description=_("用户输入日期格式时是否强制要求时间晚于当前时间,只对日期格式定时输入有效")),
109+
schema=StringItemSchema(
110+
description=_("用户输入日期格式时是否强制要求时间晚于当前时间,只对日期格式定时输入有效")
111+
),
107112
),
108113
]
109114

@@ -119,7 +124,7 @@ def execute(self, data, parent_data):
119124
# 项目时区获取
120125
project = Project.objects.get(id=parent_data.inputs.project_id)
121126

122-
project_tz = timezone.pytz.timezone(project.time_zone)
127+
project_tz = pytz.timezone(project.time_zone)
123128
data.outputs.business_tz = project_tz
124129

125130
now = datetime.datetime.now(tz=project_tz)
@@ -134,7 +139,10 @@ def execute(self, data, parent_data):
134139
# 如果写成+号 可以输入无限长,或考虑前端修改
135140
eta = now + datetime.timedelta(seconds=int(timing))
136141
else:
137-
message = _("[定时]节点执行失败: 定时时间仅支持「秒(s)」 或 「%%Y-%%m-%%d %%H:%%M:%%S)」格式,请检查节点配置") % timing
142+
message = (
143+
_("[定时]节点执行失败: 定时时间仅支持「秒(s)」 或 「%%Y-%%m-%%d %%H:%%M:%%S)」格式,请检查节点配置")
144+
% timing
145+
)
138146
LOGGER.error(message)
139147
data.set_outputs("ex_data", message)
140148
return False

pipeline_plugins/variables/collections/common.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import logging
1717
from typing import List
1818

19+
import pytz
1920
from django.conf import settings
20-
from django.utils import timezone
2121
from django.utils.translation import ugettext_lazy as _
2222
from pipeline.core.data.var import LazyVariable, RegisterVariableMeta, SpliceVariable
2323
from pipeline.core.flow.io import IntItemSchema, StringItemSchema
@@ -75,7 +75,9 @@ class Datetime(CommonPlainVariable, SelfExplainVariable):
7575

7676
@classmethod
7777
def _self_explain(cls, **kwargs) -> List[FieldExplain]:
78-
return [FieldExplain(key="${KEY}", type=Type.STRING, description="用户选择的时间,输出格式: 2000-04-19 14:45:16")]
78+
return [
79+
FieldExplain(key="${KEY}", type=Type.STRING, description="用户选择的时间,输出格式: 2000-04-19 14:45:16")
80+
]
7981

8082

8183
class Int(CommonPlainVariable, SelfExplainVariable):
@@ -116,11 +118,17 @@ class Select(LazyVariable, SelfExplainVariable):
116118
meta_tag = "select.select_meta"
117119
form = "%svariables/%s.js" % (settings.STATIC_URL, code)
118120
schema = StringItemSchema(description=_("下拉框变量"))
119-
desc = _("单选模式下输出选中的 value,多选模式下输出选中 value 以 ',' 拼接的字符串\n该变量默认不支持输入任意值,仅在子流程节点配置填参时支持输入任意值")
121+
desc = _(
122+
"单选模式下输出选中的 value,多选模式下输出选中 value 以 ',' 拼接的字符串\n该变量默认不支持输入任意值,仅在子流程节点配置填参时支持输入任意值"
123+
)
120124

121125
@classmethod
122126
def _self_explain(cls, **kwargs) -> List[FieldExplain]:
123-
return [FieldExplain(key="${KEY}", type=Type.STRING, description="选中的 value,多选模式下输出选中 value 以 ',' 拼接的字符串")]
127+
return [
128+
FieldExplain(
129+
key="${KEY}", type=Type.STRING, description="选中的 value,多选模式下输出选中 value 以 ',' 拼接的字符串"
130+
)
131+
]
124132

125133
def get_value(self):
126134
# multiple select
@@ -151,11 +159,17 @@ class TextValueSelect(LazyVariable, SelfExplainVariable):
151159
@classmethod
152160
def _self_explain(cls, **kwargs) -> List[FieldExplain]:
153161
return [
154-
FieldExplain(key="${KEY}", type=Type.DICT, description="用户选择的选项的text与value以及未选中的text与value"),
162+
FieldExplain(
163+
key="${KEY}", type=Type.DICT, description="用户选择的选项的text与value以及未选中的text与value"
164+
),
155165
FieldExplain(key='${KEY["value"]}', type=Type.STRING, description="用户选中选项的value,多个以,分隔"),
156166
FieldExplain(key='${KEY["text"]}', type=Type.STRING, description="用户选中选项的text,多个以,分隔"),
157-
FieldExplain(key='${KEY["value_not_selected"]}', type=Type.STRING, description="用户未选中选项的value,多个以,分隔"),
158-
FieldExplain(key='${KEY["text_not_selected"]}', type=Type.STRING, description="用户未选中选项的text,多个以,分隔"),
167+
FieldExplain(
168+
key='${KEY["value_not_selected"]}', type=Type.STRING, description="用户未选中选项的value,多个以,分隔"
169+
),
170+
FieldExplain(
171+
key='${KEY["text_not_selected"]}', type=Type.STRING, description="用户未选中选项的text,多个以,分隔"
172+
),
159173
]
160174

161175
def get_value(self):
@@ -213,7 +227,7 @@ def _self_explain(cls, **kwargs) -> List[FieldExplain]:
213227
def get_value(self):
214228
time_format = self.value.get("time_format", "%Y-%m-%d %H:%M:%S").strip()
215229
time_zone = self.value.get("time_zone", "Asia/Shanghai")
216-
now = datetime.datetime.now(timezone.pytz.timezone(time_zone))
230+
now = datetime.datetime.now(pytz.timezone(time_zone))
217231
current_time = now.strftime(time_format)
218232
return current_time
219233

@@ -233,7 +247,7 @@ def _self_explain(cls, **kwargs) -> List[FieldExplain]:
233247
def get_value(self):
234248
time_units = self.value.get("time_unit") or ["year", "month", "day", "hour", "minute", "second"]
235249
time_zone = self.value.get("time_zone", "Asia/Shanghai")
236-
now = datetime.datetime.now(timezone.pytz.timezone(time_zone))
250+
now = datetime.datetime.now(pytz.timezone(time_zone))
237251
current_time = now.strftime(self._generate_time_format(time_units))
238252
return current_time
239253

@@ -321,7 +335,10 @@ class StaffGroupSelector(LazyVariable, SelfExplainVariable):
321335
type = "dynamic"
322336
tag = "staff_group_multi_selector.staff_group_selector"
323337
form = "%svariables/staff_group_multi_selector.js" % settings.STATIC_URL
324-
desc = _("可选cc业务固定的四个人员分组(运维人员、产品人员、开发人员、测试人员)和标准运维【项目管理】中配置的人员分组\n" "输出格式为选中人员用户名以 ',' 拼接的字符串")
338+
desc = _(
339+
"可选cc业务固定的四个人员分组(运维人员、产品人员、开发人员、测试人员)和标准运维【项目管理】中配置的人员分组\n"
340+
"输出格式为选中人员用户名以 ',' 拼接的字符串"
341+
)
325342

326343
@classmethod
327344
def _self_explain(cls, **kwargs) -> List[FieldExplain]:

0 commit comments

Comments
 (0)