Skip to content

Commit

Permalink
back to 120 char line length
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-walluhn committed Mar 7, 2016
1 parent 69e7586 commit 458dffb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 67 deletions.
9 changes: 3 additions & 6 deletions radio/apps/schedules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
32 changes: 11 additions & 21 deletions radio/apps/schedules/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -217,7 +211,7 @@ def clean(self):
)
)

index = index + 1
index += 1

def save(self, *args, **kwargs):
# convert dates due MySQL
Expand All @@ -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) |
Expand Down Expand Up @@ -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

Expand All @@ -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')
Expand Down
57 changes: 17 additions & 40 deletions radio/apps/schedules/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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(
Expand Down

0 comments on commit 458dffb

Please sign in to comment.