perf: 优化 ops 任务,支持 i18n

- 内置任务名称支持了 i18n,数据库存英文,返回是翻译一下
- 任务执行中,添加 language 上下文
This commit is contained in:
ibuler
2022-01-13 14:18:32 +08:00
committed by Jiangjie.Bai
parent 43c4c78378
commit 145c7952c9
14 changed files with 127 additions and 88 deletions

View File

@@ -9,7 +9,7 @@ from celery import current_task
from django.db import models
from django.conf import settings
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _, gettext
from common.utils import get_logger, lazyproperty
from common.fields.model import (
@@ -58,6 +58,17 @@ class Task(PeriodTaskModelMixin, OrgModelMixin):
else:
return False
@lazyproperty
def display_name(self):
sps = ['. ', ': ']
spb = {str(sp in self.name): sp for sp in sps}
sp = spb.get('True')
if not sp:
return self.name
tpl, data = self.name.split(sp, 1)
return gettext(tpl + sp) + data
@property
def timedelta(self):
if self.latest_execution: