Skip to content

Commit

Permalink
fix: 修复timezone修改成pytz,页面刷新404LoginRequiredMiddleware传入函数问题 TencentBl…
Browse files Browse the repository at this point in the history
  • Loading branch information
huangpixu committed Dec 9, 2024
1 parent ce2f2ae commit b985abc
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion gcloud/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
9 changes: 7 additions & 2 deletions gcloud/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions gcloud/taskflow3/domains/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = (
Expand Down
5 changes: 3 additions & 2 deletions pipeline_plugins/components/collections/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}",
Expand Down
6 changes: 3 additions & 3 deletions pipeline_plugins/variables/collections/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit b985abc

Please sign in to comment.