Skip to content

Instantly share code, notes, and snippets.

@NilovAlexander
Created June 6, 2016 16:10
Show Gist options
  • Save NilovAlexander/25a42a5c8f9b01b8ae6d0f96724bdf19 to your computer and use it in GitHub Desktop.
Save NilovAlexander/25a42a5c8f9b01b8ae6d0f96724bdf19 to your computer and use it in GitHub Desktop.
# coding: utf-8
from datetime import datetime
import tornado.gen
from handlers.ets_mission import MissionHandler
from handlers.ets_waybill import WaybillHandler
from utils.check_date_overlap import (
check_date_overlap, CHECK_DATE_OVERLAP_ERROR_MESSAGE)
class MissionAssignationHandler(WaybillHandler, MissionHandler):
@tornado.gen.coroutine
def put(self):
# ...
existing_missions = [
{"date_start": "",
"date_end": "",
# ...
},
] # Список словарей заданий
# Проверяем корректность временных периодов
timeslots = [(datetime.strptime(i["date_start"],
"%Y-%m-%dT%H:%M:%S"),
datetime.strptime(i["date_end"],
"%Y-%m-%dT%H:%M:%S")
) for i in existing_missions if i]
sorted_timeslots = sorted(timeslots)
for num, slot in enumerate(sorted_timeslots):
# Проверяем на порядок дат в слоте
if not check_date_overlap(*slot):
"""
Даже при попадании в это условие цмкл продолжал отрабатывать
до конца.
"""
self.response["warnings"] = CHECK_DATE_OVERLAP_ERROR_MESSAGE
self.write(self.response)
self.finish()
return
# Проверяем на пересечение временны периодов
if num != 0 and sorted_timeslots[num - 1][1] > slot[0]:
self.response["warnings"] = [
"Данные введены некорректно. "
"Произошло пересечение временных интервалов заданий."]
self.write(self.response)
self.finish()
return
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment