From 458dffbcc5ecaf644f3a7249baa9c5c37e02ac6d Mon Sep 17 00:00:00 2001 From: Stefan Date: Mon, 7 Mar 2016 09:19:57 +0100 Subject: [PATCH] back to 120 char line length --- radio/apps/schedules/admin.py | 9 ++---- radio/apps/schedules/models.py | 32 +++++++------------ radio/apps/schedules/tests.py | 57 ++++++++++------------------------ 3 files changed, 31 insertions(+), 67 deletions(-) diff --git a/radio/apps/schedules/admin.py b/radio/apps/schedules/admin.py index 1b317e4..372195f 100755 --- a/radio/apps/schedules/admin.py +++ b/radio/apps/schedules/admin.py @@ -59,10 +59,8 @@ def copy_ScheduleBoard(self, request, queryset): obj_copy.save() # Live Schedules lives must be created first schedules = [] - schedules.extend(Schedule.objects.filter( - schedule_board=obj, type='L')) - schedules.extend(Schedule.objects.filter( - schedule_board=obj).exclude(type='L')) + schedules.extend(Schedule.objects.filter(schedule_board=obj, type='L')) + schedules.extend(Schedule.objects.filter(schedule_board=obj).exclude(type='L')) for schedule in schedules: schedule_copy = copy.copy(schedule) schedule_copy.id = None @@ -110,8 +108,7 @@ def get_urls(self): return custom_urls + urls def response_change(self, request, obj): - msg = _('{obj} was changed successfully.'.format( - obj=force_unicode(obj))) + msg = _('{obj} was changed successfully.'.format(obj=force_unicode(obj))) if '_continue' in request.POST: return HttpResponseRedirect(request.path) else: diff --git a/radio/apps/schedules/models.py b/radio/apps/schedules/models.py index b65ee1e..36cda85 100755 --- a/radio/apps/schedules/models.py +++ b/radio/apps/schedules/models.py @@ -85,18 +85,15 @@ def clean(self): pass elif self.end_date: - raise ValidationError( - _('start date cannot be null if end date exists')) + raise ValidationError(_('start date cannot be null if end date exists')) def save(self, *args, **kwargs): # rearrange episodes if self.pk is not None: orig = ScheduleBoard.objects.get(pk=self.pk) - if (orig.start_date != self.start_date or - orig.end_date != self.end_date): # Field has changed + if (orig.start_date != self.start_date or orig.end_date != self.end_date): # Field has changed super(ScheduleBoard, self).save(*args, **kwargs) - Episode.rearrange_episodes( - programme=None, after=datetime.datetime.now()) + Episode.rearrange_episodes(programme=None, after=datetime.datetime.now()) else: super(ScheduleBoard, self).save(*args, **kwargs) else: @@ -139,13 +136,11 @@ def runtime(self): def __get_rrule(self): start_date = self.programme.start_date - if (self.schedule_board.start_date and - start_date < self.schedule_board.start_date): + if (self.schedule_board.start_date and start_date < self.schedule_board.start_date): start_date = self.schedule_board.start_date if self.programme.end_date: end_date = self.programme.end_date - if (self.schedule_board.end_date and - end_date > self.schedule_board.end_date): + if (self.schedule_board.end_date and end_date > self.schedule_board.end_date): end_date = self.schedule_board.end_date # Due to rrule we need to add 1 day end_date = end_date + datetime.timedelta(days=1) @@ -190,8 +185,7 @@ def date_after(self, dt): def clean(self): now = datetime.datetime.now() if self.schedule_board.start_date: - dt = datetime.datetime.combine( - self.schedule_board.start_date, datetime.time(0, 0)) + dt = datetime.datetime.combine(self.schedule_board.start_date, datetime.time(0, 0)) if now > dt: dt = now # get the next emission date @@ -217,7 +211,7 @@ def clean(self): ) ) - index = index + 1 + index += 1 def save(self, *args, **kwargs): # convert dates due MySQL @@ -234,8 +228,7 @@ def between(cls, after, before, exclude=None, live=False, schedule_board=None): if live: list_schedules = list_schedules.filter(type='L') if schedule_board: - list_schedules = list_schedules.filter( - schedule_board=schedule_board) + list_schedules = list_schedules.filter(schedule_board=schedule_board) else: list_schedules = ( list_schedules.filter(schedule_board__start_date__lte=before, schedule_board__end_date__isnull=True) | @@ -273,9 +266,7 @@ def schedule(cls, dt, exclude=None): if date and (earlier_date is None or date > earlier_date): earlier_date = date earlier_schedule = schedule - if (earlier_schedule is None or - dt > earlier_date + earlier_schedule.runtime()): - # XXX Todo: check + if (earlier_schedule is None or dt > earlier_date + earlier_schedule.runtime()): # Todo: check return None, None return earlier_schedule, earlier_date @@ -297,13 +288,12 @@ def get_next_date(cls, programme, after): if date and (closer_date is None or date < closer_date): closer_date = date closer_schedule = schedule - if closer_schedule is None: # XXX Todo: check + if closer_schedule is None: # Todo: check return None, None return closer_schedule, closer_date def __unicode__(self): - return ' - '.join([self.get_day_display(), - self.start_hour.strftime('%H:%M')]) + return ' - '.join([self.get_day_display(), self.start_hour.strftime('%H:%M')]) class Meta: verbose_name = _('schedule') diff --git a/radio/apps/schedules/tests.py b/radio/apps/schedules/tests.py index 968848d..84fdca3 100755 --- a/radio/apps/schedules/tests.py +++ b/radio/apps/schedules/tests.py @@ -82,26 +82,16 @@ def setUp(self): def test_runtime(self): programme = Programme.objects.get(name="Programme 00:00 - 09:00") - self.assertEqual( - relativedelta(hours=+9), to_relativedelta(programme.runtime)) + self.assertEqual(relativedelta(hours=+9), to_relativedelta(programme.runtime)) def test_day_schedule(self): - schedules, dates = Schedule.between( - datetime.datetime(2014, 1, 6), datetime.datetime(2014, 1, 7)) + schedules, dates = Schedule.between(datetime.datetime(2014, 1, 6), datetime.datetime(2014, 1, 7)) self.assertEqual(4, len(schedules)) - schedule_1 = Schedule.objects.get( - programme=Programme.objects.get(name="Programme 00:00 - 09:00"), - day=MO) - schedule_2 = Schedule.objects.get( - programme=Programme.objects.get(name="Programme 09:00 - 10:00"), - day=MO) - schedule_3 = Schedule.objects.get( - programme=Programme.objects.get(name="Programme 10:00 - 12:00"), - day=MO) - schedule_4 = Schedule.objects.get( - programme=Programme.objects.get(name="Programme 00:00 - 09:00"), - day=TU) + schedule_1 = Schedule.objects.get(programme=Programme.objects.get(name="Programme 00:00 - 09:00"), day=MO) + schedule_2 = Schedule.objects.get(programme=Programme.objects.get(name="Programme 09:00 - 10:00"), day=MO) + schedule_3 = Schedule.objects.get(programme=Programme.objects.get(name="Programme 10:00 - 12:00"), day=MO) + schedule_4 = Schedule.objects.get(programme=Programme.objects.get(name="Programme 00:00 - 09:00"), day=TU) self.assertTrue(schedule_1 in schedules) self.assertTrue(schedule_2 in schedules) self.assertTrue(schedule_3 in schedules) @@ -110,19 +100,14 @@ def test_day_schedule(self): def test_now_playing_1(self): now_mock = datetime.datetime(2014, 1, 6, 0, 0, 0, 0) schedule, date = Schedule.schedule(now_mock) - schedule_1 = Schedule.objects.get( - programme=Programme.objects.get(name="Programme 00:00 - 09:00"), - day=MO) + schedule_1 = Schedule.objects.get(programme=Programme.objects.get(name="Programme 00:00 - 09:00"), day=MO) self.assertEqual(schedule_1, schedule) - self.assertEqual( - datetime.datetime.combine(now_mock, schedule_1.start_hour), date) + self.assertEqual(datetime.datetime.combine(now_mock, schedule_1.start_hour), date) def test_now_playing_2(self): now_mock = datetime.datetime(2014, 1, 7, 0, 0, 0, 0) schedule, date = Schedule.schedule(now_mock) - schedule_1 = Schedule.objects.get( - programme=Programme.objects.get(name="Programme 00:00 - 09:00"), - day=TU) + schedule_1 = Schedule.objects.get(programme=Programme.objects.get(name="Programme 00:00 - 09:00"), day=TU) self.assertEqual(schedule_1, schedule) self.assertEqual(datetime.datetime.combine(now_mock, schedule_1.start_hour), date) @@ -146,22 +131,14 @@ def test_runtime(self): february_board = ScheduleBoard.objects.get(name="1_14_february") after_board = ScheduleBoard.objects.get(name="after_14_february") - self.assertEqual(None, ScheduleBoard.get_current( - datetime.datetime(2013, 12, 1, 0, 0, 0, 0))) - self.assertEqual(january_board, ScheduleBoard.get_current( - datetime.datetime(2014, 1, 1, 0, 0, 0, 0))) - self.assertEqual(january_board, ScheduleBoard.get_current( - datetime.datetime(2014, 1, 31, 0, 0, 0, 0))) - self.assertEqual(january_board, ScheduleBoard.get_current( - datetime.datetime(2014, 1, 31, 12, 0, 0, 0))) - self.assertEqual(february_board, ScheduleBoard.get_current( - datetime.datetime(2014, 2, 1, 0, 0, 0, 0))) - self.assertEqual(february_board, ScheduleBoard.get_current( - datetime.datetime(2014, 2, 14, 0, 0, 0, 0))) - self.assertEqual(after_board, ScheduleBoard.get_current( - datetime.datetime(2014, 2, 15, 0, 0, 0, 0))) - self.assertEqual(after_board, ScheduleBoard.get_current( - datetime.datetime(2014, 6, 1, 0, 0, 0, 0))) + self.assertEqual(None, ScheduleBoard.get_current(datetime.datetime(2013, 12, 1, 0, 0, 0, 0))) + self.assertEqual(january_board, ScheduleBoard.get_current(datetime.datetime(2014, 1, 1, 0, 0, 0, 0))) + self.assertEqual(january_board, ScheduleBoard.get_current(datetime.datetime(2014, 1, 31, 0, 0, 0, 0))) + self.assertEqual(january_board, ScheduleBoard.get_current(datetime.datetime(2014, 1, 31, 12, 0, 0, 0))) + self.assertEqual(february_board, ScheduleBoard.get_current(datetime.datetime(2014, 2, 1, 0, 0, 0, 0))) + self.assertEqual(february_board, ScheduleBoard.get_current(datetime.datetime(2014, 2, 14, 0, 0, 0, 0))) + self.assertEqual(after_board, ScheduleBoard.get_current(datetime.datetime(2014, 2, 15, 0, 0, 0, 0))) + self.assertEqual(after_board, ScheduleBoard.get_current(datetime.datetime(2014, 6, 1, 0, 0, 0, 0))) def test_validation_exception_1(self): schedule_board = ScheduleBoard.objects.create(