Skip to content

Commit

Permalink
fix: ugettext_lazy导入修改为gettext_lazy TencentBlueKing#7625
Browse files Browse the repository at this point in the history
  • Loading branch information
huangpixu committed Dec 9, 2024
1 parent 14877fd commit 37dcde0
Show file tree
Hide file tree
Showing 214 changed files with 1,646 additions and 1,149 deletions.
85 changes: 73 additions & 12 deletions api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _
import logging

import requests
import curlify
import requests
from django.utils.translation import gettext_lazy as _

logger = logging.getLogger("component")

Expand All @@ -28,29 +28,67 @@ def _gen_header():


def _http_request(
method, url, headers=None, data=None, verify=False, cert=None, timeout=None, cookies=None,
method,
url,
headers=None,
data=None,
verify=False,
cert=None,
timeout=None,
cookies=None,
):
resp = requests.Response()
request_id = None

try:
if method == "GET":
resp = requests.get(
url=url, headers=headers, params=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies,
url=url,
headers=headers,
params=data,
verify=verify,
cert=cert,
timeout=timeout,
cookies=cookies,
)
elif method == "HEAD":
resp = requests.head(url=url, headers=headers, verify=verify, cert=cert, timeout=timeout, cookies=cookies,)
resp = requests.head(
url=url,
headers=headers,
verify=verify,
cert=cert,
timeout=timeout,
cookies=cookies,
)
elif method == "POST":
resp = requests.post(
url=url, headers=headers, json=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies,
url=url,
headers=headers,
json=data,
verify=verify,
cert=cert,
timeout=timeout,
cookies=cookies,
)
elif method == "DELETE":
resp = requests.delete(
url=url, headers=headers, json=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies,
url=url,
headers=headers,
json=data,
verify=verify,
cert=cert,
timeout=timeout,
cookies=cookies,
)
elif method == "PUT":
resp = requests.put(
url=url, headers=headers, json=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies,
url=url,
headers=headers,
json=data,
verify=verify,
cert=cert,
timeout=timeout,
cookies=cookies,
)
else:
message = _(f"非法请求: 请求不是合法的HTTP Method: {method} | api http")
Expand Down Expand Up @@ -105,31 +143,54 @@ def _http_request(
resp.request = requests.Request(method, url, headers=headers, data=data, cookies=cookies).prepare()

logger.debug(
"the request_id: `%s`. curl: `%s`", request_id, curlify.to_curl(resp.request, verify=False),
"the request_id: `%s`. curl: `%s`",
request_id,
curlify.to_curl(resp.request, verify=False),
)


def get(url, data, headers=None, verify=False, cert=None, timeout=None, cookies=None):
if not headers:
headers = _gen_header()
return _http_request(
method="GET", url=url, headers=headers, data=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies,
method="GET",
url=url,
headers=headers,
data=data,
verify=verify,
cert=cert,
timeout=timeout,
cookies=cookies,
)


def post(url, data, headers=None, verify=False, cert=None, timeout=None, cookies=None):
if not headers:
headers = _gen_header()
return _http_request(
method="POST", url=url, headers=headers, data=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies,
method="POST",
url=url,
headers=headers,
data=data,
verify=verify,
cert=cert,
timeout=timeout,
cookies=cookies,
)


def put(url, data, headers=None, verify=False, cert=None, timeout=None, cookies=None):
if not headers:
headers = _gen_header()
return _http_request(
method="PUT", url=url, headers=headers, data=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies,
method="PUT",
url=url,
headers=headers,
data=data,
verify=verify,
cert=cert,
timeout=timeout,
cookies=cookies,
)


Expand Down
2 changes: 1 addition & 1 deletion api/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""
import logging

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from gcloud.conf import settings
from gcloud.exceptions import ApiRequestError
Expand Down
2 changes: 1 addition & 1 deletion config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from blueapps.opentelemetry.utils import inject_logging_trace_info
from django.db.backends.mysql.features import DatabaseFeatures
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from pipeline.celery.queues import ScalableQueues

import env
Expand Down
2 changes: 1 addition & 1 deletion docs/develop/dev_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ python manage.py create_new_plugin cc create_set v1.0 open pipeline_plugins site

import logging

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from pipeline.core.flow.activity import Service
from pipeline.component_framework.component import Component
Expand Down
2 changes: 1 addition & 1 deletion en_docs/develop/dev_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Write plugin background logic in `plugin.py`. It mainly includes standard plugin

import logging

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from pipeline.core.flow.activity import Service
from pipeline.component_framework.component import Component
Expand Down
8 changes: 5 additions & 3 deletions files/bartenders/upload_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
import re
import logging
import re
import traceback

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from .base import UploadRequestBartender

Expand Down Expand Up @@ -52,7 +52,9 @@ def process_request(self, request, *args, **kwargs):
try:
file_tag = self.manager.save(name=file_name, content=None, source_ip=source_ip, file_path=file_path)
except Exception as e:
message = _(f"文件上传失败: 文件归档失败请重试, 如持续失败可联系管理员处理, {traceback.format_exc()} | process_request")
message = _(
f"文件上传失败: 文件归档失败请重试, 如持续失败可联系管理员处理, {traceback.format_exc()} | process_request"
)
logger.error(message)
return {"result": False, "message": message + f":{e}", "code": 500}

Expand Down
6 changes: 3 additions & 3 deletions files/bartenders/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
import re
import logging
import hashlib
import logging
import re

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

logger = logging.getLogger("root")

Expand Down
15 changes: 9 additions & 6 deletions files/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from django.utils.translation import ugettext_lazy as _
import logging

from django.utils.translation import gettext_lazy as _

from . import env
from .bartenders.bk_repo import BKRepoBartender
from .bartenders.job_repo import JobRepoBartender
from .bartenders.nfs import HostNFSBartender
from .bartenders.upload_module import UploadModuleBartender
from .managers.bk_repo import BKRepoManager
from .managers.job_repo import JobRepoManager
from .managers.nfs import HostNFSManager
from .managers.upload_module import UploadModuleManager
from .bartenders.nfs import HostNFSBartender
from .bartenders.upload_module import UploadModuleBartender
from .bartenders.bk_repo import BKRepoBartender
import logging

logger = logging.getLogger("root")

Expand All @@ -31,7 +32,9 @@ class ManagerFactory(object):
def get_manager(cls, manager_type):
creator = getattr(cls, "_create_{}_manager".format(manager_type), None)
if not creator or not callable(creator):
message = _(f"文件上传失败: 无法找到对应的FileManager: {manager_type}, 请重试, 如持续失败可联系管理员处理 | get_manager")
message = _(
f"文件上传失败: 无法找到对应的FileManager: {manager_type}, 请重试, 如持续失败可联系管理员处理 | get_manager"
)
logger.error(message)
raise LookupError(message)

Expand Down
2 changes: 1 addition & 1 deletion gcloud/analysis_statistics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from gcloud.constants import TASK_CATEGORY, TASK_CREATE_METHOD, TaskCreateMethod

Expand Down
2 changes: 1 addition & 1 deletion gcloud/common_template/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import logging

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from gcloud import err_code
from gcloud.template_base.models import BaseTemplate, BaseTemplateManager
Expand Down
2 changes: 1 addition & 1 deletion gcloud/conf/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

import env
from packages.blueking.component.shortcuts import get_client_by_request, get_client_by_user
Expand Down
2 changes: 1 addition & 1 deletion gcloud/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from enum import Enum

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

PROJECT = "project"
BUSINESS = "business"
Expand Down
2 changes: 1 addition & 1 deletion gcloud/contrib/admin/migration_api/app_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from blueapps.account.decorators import login_exempt
from django.http.response import JsonResponse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from pipeline.models import TemplateScheme
Expand Down
8 changes: 4 additions & 4 deletions gcloud/contrib/admin/migration_api/resource_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
"""

import json
import logging
import traceback
from datetime import datetime

from blueapps.account.decorators import login_exempt
from django.http.response import JsonResponse
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST

from blueapps.account.decorators import login_exempt
from gcloud import err_code
from gcloud.contrib.admin.migration_api.decorators import require_migrate_token
from gcloud.core.models import Project, ResourceConfig
from gcloud import err_code
from django.utils.translation import ugettext_lazy as _
import logging

logger = logging.getLogger("root")

Expand Down
9 changes: 5 additions & 4 deletions gcloud/contrib/admin/migration_api/staff_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
specific language governing permissions and limitations under the License.
"""

import logging
import json
import logging

from blueapps.account.decorators import login_exempt
from django.http.response import JsonResponse
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.utils.translation import ugettext_lazy as _

from blueapps.account.decorators import login_exempt
from gcloud.core.models import Project, StaffGroupSet
from gcloud import err_code
from gcloud.core.models import Project, StaffGroupSet

from .decorators import require_migrate_token

logger = logging.getLogger("root")
Expand Down
10 changes: 5 additions & 5 deletions gcloud/contrib/admin/migration_api/template_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
"""

import json
import logging
import traceback

from blueapps.account.decorators import login_exempt
from django.http.response import JsonResponse
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST

from blueapps.account.decorators import login_exempt
from gcloud.contrib.admin.migration_api.decorators import require_migrate_token
from gcloud.constants import TASK_CATEGORY
from gcloud import err_code
from gcloud.constants import TASK_CATEGORY
from gcloud.contrib.admin.migration_api.decorators import require_migrate_token
from gcloud.label.models import Label, TemplateLabelRelation
from gcloud.tasktmpl3.models import TaskTemplate
from django.utils.translation import ugettext_lazy as _
import logging

logger = logging.getLogger("root")

Expand Down
6 changes: 4 additions & 2 deletions gcloud/contrib/appmaker/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import jsonschema
import magic
from django.http import JsonResponse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.views.decorators.http import require_GET

from gcloud.conf import settings
Expand Down Expand Up @@ -61,7 +61,9 @@ def save(request, project_id):
file_size = logo_obj.size
# LOGO大小不能大于 100K
if file_size > 100 * 1024:
message = _("轻应用保存失败: 非法的图片大小, 请使用不超过100KB 的 JPG / PNG 图片作为应用LOGO | appmaker save")
message = _(
"轻应用保存失败: 非法的图片大小, 请使用不超过100KB 的 JPG / PNG 图片作为应用LOGO | appmaker save"
)
logger.error(message)
return JsonResponse({"result": False, "message": message})
logo_content = logo_obj.read()
Expand Down
Loading

0 comments on commit 37dcde0

Please sign in to comment.