def clean_expired_requests():
now = datetime.datetime.now()
qs = Request.objects.filter(
expires_at__date=now, state__in=[
'documents', 'validation', 'evaluation', 'signature'])
for req in qs:
log.debug('Request %s expired' % req)
req.expired_at_state = req.state.name
req.save()
req.expire()
EmailFromTemplate('expired-request').send_to(req.customer.user)
我正在研究Django项目。我想插入一些东西,它会告诉我在运行服务器时调用了以下方法(python manage.py runserver_plus
)。我以为它可以在我的终端服务器上写一条消息' clean_expired_request已被调用!'。我怎么能这样做?
如果问题不清楚,请告诉我。
答案 0 :(得分:3)
更加Pythonic版本的代码会将逻辑与所有str
分开。一种解决方案是将所有对或str
和整数存储在dict
中,如下所示:
def fix_nb_rows_per_table(url_ws, season_slug):
result = url_ws + season_slug
mapping = {('daily_game_schedule', 'regular'): 14,
('full_game_schedule', 'regular'): 1235,
...
}
for keys, val in mapping.items():
if all(key in result for key in keys):
return val