diff --git a/requirements.txt b/requirements.txt index 60d44ddc..bc854d1e 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/safesite/services.py b/safesite/services.py new file mode 100644 index 00000000..c58f7c28 --- /dev/null +++ b/safesite/services.py @@ -0,0 +1,42 @@ +import locale +from croniter import croniter +from cron_descriptor import get_description +from safesite.models import MySchedule, GridTaskSet, PeriodicTask +period_dict = { + "days": "天", + "hours": "小时", + "minutes": "分钟", + "seconds": "秒", + "microseconds": "毫秒" + } +def get_chinese_description(type:str = 'interval', data: dict = {}): + """转换为汉语描述 + """ + if type == 'interval': + return f"每隔{data['every']}{period_dict[data['period']]}" + elif type == 'crontab': + exp = f"{data['minute']} {data['hour']} {data['day_of_month']} {data['month_of_year']} {data['day_of_week']}" + try: + croniter(exp) + except ValueError: + return '' + locale.setlocale(locale.LC_ALL, 'zh_CN.UTF-8') + return get_description(exp) + return '' + +def correct_myschedule(): + qs = MySchedule.objects.all() + for ind, item in enumerate(qs): + typeset = item.typeset + if typeset == 'interval': + interval = item.interval + item.name = get_chinese_description(typeset, {'every': interval.every, 'period': interval.period}) + item.save() + elif typeset == 'crontab': + crontab = item.crontab + item.name = get_chinese_description(typeset, + {"minute": crontab.minute, "hour": crontab.hour, "day_of_month": crontab.day_of_month, + "month_of_year": crontab.month_of_year, "day_of_week": crontab.day_of_week}) + if item.name == '': + crontab.delete() + item.delete() \ No newline at end of file diff --git a/safesite/templates/schedulesetadd.html b/safesite/templates/schedulesetadd.html index da0d11c3..0dbb894b 100644 --- a/safesite/templates/schedulesetadd.html +++ b/safesite/templates/schedulesetadd.html @@ -7,11 +7,11 @@
-
+ {% comment %}
-
+
{% endcomment %}