From d6d80a4a77a2b53b2c7b73924a0a37231cef27b1 Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Mon, 23 Dec 2013 13:24:40 +0000 Subject: [PATCH] Make a couple of the utility methods in meeting.models use .first(), fix potential bug in slot_to_the_right, test on location_id instead of location in build_timeslices to speed up the edit timeslots view - Legacy-Id: 7050 --- ietf/meeting/models.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/ietf/meeting/models.py b/ietf/meeting/models.py index 11f14a393..d34207d60 100644 --- a/ietf/meeting/models.py +++ b/ietf/meeting/models.py @@ -105,10 +105,7 @@ class Meeting(models.Model): return self.date + datetime.timedelta(days=settings.SUBMISSION_CORRECTION_DAYS) def get_schedule_by_name(self, name): - qs = self.schedule_set.filter(name=name) - if qs: - return qs[0] - return None + return self.schedule_set.filter(name=name).first() @property def sessions_that_can_meet(self): @@ -150,7 +147,7 @@ class Meeting(models.Model): slots = {} for ts in self.timeslot_set.all(): - if ts.location is None: + if ts.location_id is None: continue ymd = ts.time.date() if ymd not in time_slices: @@ -379,18 +376,15 @@ class TimeSlot(models.Model): """ Find a timeslot that comes next, in the same room. It must be on the same day, - and it must have a gap of 11 minutes or less. (10 is the spec) + and it must have a gap of less than 11 minutes. (10 is the spec) """ @property def slot_to_the_right(self): - things = self.meeting.timeslot_set.filter(location = self.location, # same room! - type = self.type, # must be same type (usually session) - time__gt = self.time + self.duration, # must be after this session. - time__lt = self.time + self.duration + datetime.timedelta(0,11*60)) - if things: - return things[0] - else: - return None + return self.meeting.timeslot_set.filter( + location = self.location, # same room! + type = self.type, # must be same type (usually session) + time__gt = self.time + self.duration, # must be after this session + time__lt = self.time + self.duration + datetime.timedelta(seconds=11*60)).first() # end of TimeSlot @@ -571,9 +565,9 @@ class ScheduledSession(models.Model): @property def slot_to_the_right(self): - ss1 = self.schedule.scheduledsession_set.filter(timeslot = self.timeslot.slot_to_the_right) - if ss1: - return ss1[0] + s = self.timeslot.slot_to_the_right + if s: + return self.schedule.scheduledsession_set.filter(timeslot=s).first() else: return None