summaryrefslogtreecommitdiff
path: root/program/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'program/views.py')
-rw-r--r--program/views.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/program/views.py b/program/views.py
index d824df8..0e86518 100644
--- a/program/views.py
+++ b/program/views.py
@@ -91,10 +91,9 @@ def current_show(request):
def week_schedule(request, year=None, week=None):
if year is None and week is None:
- year, week = datetime.strftime(datetime.today(), '%Y__%W').split('__')
-
- monday = datetime.strptime('%s__%s__1__06__00' % (year, week), '%Y__%W__%w__%H__%M')
+ year, week = datetime.strftime(datetime.now(), '%G__%V').split('__')
+ monday = tofirstdayinisoweek(int(year), int(week))
tuesday = monday+timedelta(days=1)
wednesday = monday+timedelta(days=2)
thursday = monday+timedelta(days=3)
@@ -114,12 +113,12 @@ def week_schedule(request, year=None, week=None):
extra_context['saturday_timeslots'] = TimeSlot.objects.get_day_timeslots(saturday)
extra_context['sunday_timeslots'] = TimeSlot.objects.get_day_timeslots(sunday)
- extra_context['last_w'] = datetime.strftime(monday-timedelta(days=7), '%Y/%W')
- extra_context['cur_w'] = '%s/%s' % (year, week)
- extra_context['next_w1'] = datetime.strftime(monday+timedelta(days=7), '%Y/%W')
- extra_context['next_w2'] = datetime.strftime(monday+timedelta(days=14), '%Y/%W')
- extra_context['next_w3'] = datetime.strftime(monday+timedelta(days=21), '%Y/%W')
- extra_context['next_w4'] = datetime.strftime(monday+timedelta(days=28), '%Y/%W')
+ extra_context['last_w'] = datetime.strftime(monday-timedelta(days=7), '%G/%V')
+ extra_context['cur_w'] = datetime.strftime(monday, '%G/%V')
+ extra_context['next_w1'] = datetime.strftime(monday+timedelta(days=7), '%G/%V')
+ extra_context['next_w2'] = datetime.strftime(monday+timedelta(days=14), '%G/%V')
+ extra_context['next_w3'] = datetime.strftime(monday+timedelta(days=21), '%G/%V')
+ extra_context['next_w4'] = datetime.strftime(monday+timedelta(days=28), '%G/%V')
return simple.direct_to_template(request, template='program/week_schedule.html', extra_context=extra_context)
@@ -148,3 +147,10 @@ def json_day_schedule(request, year=None, month=None, day=None):
schedule.append((ts.start.strftime('%H:%M:%S'), -1))
return HttpResponse(json.dumps(schedule), content_type="application/json")
+
+def tofirstdayinisoweek(year, week):
+ # http://stackoverflow.com/questions/5882405/get-date-from-iso-week-number-in-python
+ ret = datetime.strptime('%04d-%02d-1' % (year, week), '%Y-%W-%w')
+ if date(year, 1, 4).isoweekday() > 4:
+ ret -= timedelta(days=7)
+ return ret \ No newline at end of file