Skip to content
Snippets Groups Projects
Commit 5214f14c authored by David Trattnig's avatar David Trattnig
Browse files

Improve invalid timeslot handling. engine-clock#2

parent 7d7bf134
No related branches found
No related tags found
No related merge requests found
...@@ -120,19 +120,34 @@ class PlayLog(db.Model): ...@@ -120,19 +120,34 @@ class PlayLog(db.Model):
def select_for_timeslot(timeslot_id): def select_for_timeslot(timeslot_id):
""" """
Selects all playlogs which appear to be in the current timeslot. Selects all playlogs which appear to be in the current timeslot.
Limited to 10 records in the last 24hours. If playlogs without a valid timeslot are queried (-1), then only
the last 50 total playlogs are respected.
""" """
db.session.commit() db.session.commit()
now = datetime.datetime.now() now = datetime.datetime.now()
before24h = datetime.datetime.now() - datetime.timedelta(hours=24) before12h = datetime.datetime.now() - datetime.timedelta(hours=12)
playlogs = None
tracks = db.session.query(PlayLog).\
order_by(PlayLog.track_start.desc()).\ # Invalid Timeslot ID
filter(PlayLog.track_start >= str(before24h)).\ if timeslot_id == -1:
filter(PlayLog.timeslot_id == timeslot_id).\ playlogs = []
limit(10) result = db.session.query(PlayLog).\
order_by(PlayLog.track_start.desc()).\
filter(PlayLog.track_start >= str(before12h)).\
limit(50)
for playlog in result.all():
if playlog.timeslot_id != -1:
break
playlogs.append(playlog)
# Valid Timeslot ID
else:
result = db.session.query(PlayLog).\
order_by(PlayLog.track_start.desc()).\
filter(PlayLog.timeslot_id == timeslot_id).\
playlogs = result.all()
return tracks.all() return playlogs
@staticmethod @staticmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment