From 6ba9e32c9b4397e24ac77fbcaf28802b6e7ff5f7 Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Fri, 20 Sep 2013 17:05:01 +0200 Subject: fix week number bug. diff --git a/program/views.py b/program/views.py index d824df8..f9ffcab 100644 --- a/program/views.py +++ b/program/views.py @@ -114,12 +114,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['last_w'] = datetime.strftime(monday-timedelta(days=7), '%Y/%V') 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['next_w1'] = datetime.strftime(monday+timedelta(days=7), '%Y/%V') + extra_context['next_w2'] = datetime.strftime(monday+timedelta(days=14), '%Y/%V') + extra_context['next_w3'] = datetime.strftime(monday+timedelta(days=21), '%Y/%V') + extra_context['next_w4'] = datetime.strftime(monday+timedelta(days=28), '%Y/%V') return simple.direct_to_template(request, template='program/week_schedule.html', extra_context=extra_context) -- cgit v0.10.2 From 1e7a2fd39f7cfa90e79fd9fbe00220de7f54520a Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Fri, 20 Sep 2013 17:34:48 +0200 Subject: fix week number bug. this time for real. diff --git a/program/views.py b/program/views.py index f9ffcab..4b5737b 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(), '%Y__%V').split('__') + monday = tofirstdayinisoweek(int(year), int(week)) tuesday = monday+timedelta(days=1) wednesday = monday+timedelta(days=2) thursday = monday+timedelta(days=3) @@ -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 -- cgit v0.10.2 From 1f76b988023df1520a3eb35dbecca72d0d693394 Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Fri, 20 Sep 2013 17:41:49 +0200 Subject: fix week number bug. this time for real. really diff --git a/program/views.py b/program/views.py index 4b5737b..0e86518 100644 --- a/program/views.py +++ b/program/views.py @@ -91,7 +91,7 @@ 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.now(), '%Y__%V').split('__') + year, week = datetime.strftime(datetime.now(), '%G__%V').split('__') monday = tofirstdayinisoweek(int(year), int(week)) tuesday = monday+timedelta(days=1) @@ -113,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/%V') - extra_context['cur_w'] = '%s/%s' % (year, week) - extra_context['next_w1'] = datetime.strftime(monday+timedelta(days=7), '%Y/%V') - extra_context['next_w2'] = datetime.strftime(monday+timedelta(days=14), '%Y/%V') - extra_context['next_w3'] = datetime.strftime(monday+timedelta(days=21), '%Y/%V') - extra_context['next_w4'] = datetime.strftime(monday+timedelta(days=28), '%Y/%V') + 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) -- cgit v0.10.2 From ce745d33cad169e6a06b41009620cb53b54ee18f Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Fri, 20 Sep 2013 18:16:18 +0200 Subject: removed owner of Note. diff --git a/program/admin.py b/program/admin.py index bdd3acc..87cceba 100644 --- a/program/admin.py +++ b/program/admin.py @@ -25,7 +25,6 @@ class ShowTopicAdmin(admin.ModelAdmin): class NoteAdmin(admin.ModelAdmin): date_hierarchy = 'start' - exclude = ('owner',) list_display = ('title', 'show', 'start', 'status') list_filter = ('status',) ordering = ('timeslot',) @@ -42,7 +41,6 @@ class NoteAdmin(admin.ModelAdmin): return super(NoteAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs) def save_model(self, request, obj, form, change): - obj.owner = request.user obj.save() class TimeSlotInline(admin.TabularInline): diff --git a/program/models.py b/program/models.py index 484c191..5ee4446 100644 --- a/program/models.py +++ b/program/models.py @@ -452,7 +452,6 @@ class Note(models.Model): (2, _("Repetition")), ) timeslot = models.OneToOneField(TimeSlot, verbose_name=_("Time slot")) - owner = models.ForeignKey(User, related_name='notes', verbose_name=_("Owner")) title = models.CharField(_("Title"), max_length=128) content = tinymce_models.HTMLField(_("Content")) status = models.IntegerField(_("Status"), choices=STATUS_CHOICES, default=1) -- cgit v0.10.2