diff --git a/safesite/services.py b/safesite/services.py index 5d2d183c..0f0a2b92 100644 --- a/safesite/services.py +++ b/safesite/services.py @@ -2,6 +2,7 @@ import locale from croniter import croniter from cron_descriptor import get_description from safesite.models import MySchedule, GridTaskSet, PeriodicTask +from django.core.exceptions import ObjectDoesNotExist period_dict = { "days": "天", "hours": "小时", @@ -33,10 +34,14 @@ def correct_myschedule(): 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() + try: + 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() + except ObjectDoesNotExist: + GridTaskSet.objects.filter(myschedule=item).delete() item.delete() \ No newline at end of file