diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2014-05-01 21:42:21 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2014-05-01 21:42:21 (GMT) |
commit | f2c4d866489a4aef845d7c422b98febf402472dc (patch) | |
tree | 30c4dcc6ced57ba7574249354090252cf82811e8 /program | |
parent | 329cd60b7f7dcf826e9cc4962453d2d90c27bd26 (diff) |
added save_as to NoteAdmin and limited time slot to the last four weeks. made renew action inside a method
Diffstat (limited to 'program')
-rw-r--r-- | program/admin.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/program/admin.py b/program/admin.py index 7b52fa4..0fa7461 100644 --- a/program/admin.py +++ b/program/admin.py @@ -5,7 +5,7 @@ from models import (BroadcastFormat, MusicFocus, ShowInformation, ShowTopic, Host, Note, ProgramSlot, Show, TimeSlot) from forms import MusicFocusForm -from datetime import date +from datetime import date, datetime, timedelta class BroadcastFormatAdmin(admin.ModelAdmin): @@ -34,15 +34,18 @@ class NoteAdmin(admin.ModelAdmin): list_display = ('title', 'show', 'start', 'status') list_filter = ('status',) ordering = ('timeslot',) + save_as = True def queryset(self, request): shows = request.user.shows.all() return super(NoteAdmin, self).queryset(request).filter(show__in=shows) def formfield_for_foreignkey(self, db_field, request=None, **kwargs): + four_weeks = datetime.now() - timedelta(weeks=4) if db_field.name == 'timeslot': shows = request.user.shows.all() - kwargs['queryset'] = TimeSlot.objects.filter(show__in=shows) + kwargs['queryset'] = TimeSlot.objects.filter(show__in=shows, + start__gt=four_weeks) return super(NoteAdmin, self).formfield_for_foreignkey(db_field, request, @@ -56,16 +59,8 @@ class TimeSlotInline(admin.TabularInline): model = TimeSlot -def renew(modeladmin, request, queryset): - next_year = date.today().year + 1 - queryset.update(until=date(next_year, 12, 31)) - - -renew.short_description = _("Renew selected time slots") - - class ProgramSlotAdmin(admin.ModelAdmin): - actions = (renew,) + actions = ('renew',) inlines = (TimeSlotInline,) list_display = ('show', 'byweekday', 'rrule', 'tstart', 'tend', 'until', 'timeslot_count') @@ -74,6 +69,17 @@ class ProgramSlotAdmin(admin.ModelAdmin): save_on_top = True search_fields = ('show__name',) + def renew(self, request, queryset): + next_year = date.today().year + 1 + until = date(next_year, 12, 31) + renewed = queryset.update(until=until) + if renewed == 1: + message = _("1 program slot was renewed until %s") % until + else: + message = _("%s program slots were renewed until %s") % until + self.message_user(request, message) + renew.short_description = _("Renew selected program slots") + class ProgramSlotInline(admin.TabularInline): model = ProgramSlot |