def at_front_view(self):
if not self.request.root.properties[PROP_KEYS.QUEUE_ENABLED]:
return HTTPFound(location=self.request.route_path("welcome"))
# Find open slots
total_slots = self.request.root.properties[PROP_KEYS.CONCURRENT_NUM]
open_slots = total_slots - len(self.request.root.active)
# Continue
position = Queue(self.request).position(self.request.session["queue_id"])
if position < open_slots:
queue_id = self.request.session["queue_id"]
items = [x for x in self.request.root.queue if x.queue_id == queue_id]
if len(items) <= 0:
self.request.session.flash("You are not yet at the front of the queue, please wait.", "info")
return HTTPFound(location=self.request.route_path("queue"))
else:
# Check if there are too many people in "active" state
if open_slots <= 0:
return HTTPFound(location=self.request.route_path("queue"))
# Shift the person from being in queue to being active
item = items[0]
self.request.root.queue.remove(item)
self.request.root.active[item.__name__] = item
item.__parent__ = self.request.root.active
item.queue_exit_time = item.purchase_entry_time = datetime.now()
# Make active
self.request.session.pop("queue_id", None)
self.request.session["active_id"] = item.__name__
header = remember(self.request, str(item.__name__))
return HTTPFound(location=self.request.route_path('welcome'), headers=header)
else:
self.request.session.flash("You are not yet at the front of the queue, please wait.", "info")
return HTTPFound(location=self.request.route_path("queue"))
评论列表
文章目录