Repository: CTPUG/wafer

Issue:
Schedule Editor doesn't update revision information for ScheduleItems
This is mainly so I don't lose track of this.

Updating the schedule using the editor doesn't update the revision history for schedule items correctly, and attempting to add it, using the documented logic for reversion and rest APIs, doesn't work as expected for reasons I haven't been able to figure out yet.


Discussion:

Resolving patch:
diff --git a/wafer/schedule/admin.py b/wafer/schedule/admin.py
--- a/wafer/schedule/admin.py
+++ b/wafer/schedule/admin.py
@@ -8,9 +8,11 @@
 from django.utils.encoding import force_text
 from django.utils.translation import ugettext as _
 from django import forms
+from reversion.admin import VersionAdmin
 
 from easy_select2 import Select2Multiple
 
+from wafer.compare.admin import CompareVersionAdmin
 from wafer.schedule.models import Day, Venue, Slot, ScheduleItem
 from wafer.talks.models import Talk, ACCEPTED, CANCELLED
 from wafer.pages.models import Page
@@ -366,7 +368,7 @@ def __init__(self, *args, **kwargs):
         self.fields['page'].queryset = Page.objects.all()
 
 
-class ScheduleItemAdmin(admin.ModelAdmin):
+class ScheduleItemAdmin(CompareVersionAdmin):
     form = ScheduleItemAdminForm
 
     change_list_template = 'admin/scheduleitem_list.html'
@@ -428,7 +430,7 @@ class SlotAdminAddForm(SlotAdminForm):
                                                 "this one"))
 
 
-class SlotAdmin(admin.ModelAdmin):
+class SlotAdmin(CompareVersionAdmin):
     form = SlotAdminForm
 
     list_display = ('__str__', 'get_day', 'get_formatted_start_time',
@@ -486,7 +488,16 @@ def save_model(self, request, obj, form, change):
                 prev = new_slot
 
 
-admin.site.register(Day)
+# Register and setup reversion support for Days and Venues
+class DayAdmin(VersionAdmin):
+    pass
+
+
+class VenueAdmin(VersionAdmin):
+    pass
+
+
+admin.site.register(Day, DayAdmin)
 admin.site.register(Slot, SlotAdmin)
-admin.site.register(Venue)
+admin.site.register(Venue, VenueAdmin)
 admin.site.register(ScheduleItem, ScheduleItemAdmin)
diff --git a/wafer/schedule/serializers.py b/wafer/schedule/serializers.py
--- a/wafer/schedule/serializers.py
+++ b/wafer/schedule/serializers.py
@@ -1,4 +1,5 @@
 from rest_framework import serializers
+from reversion import revisions
 
 from wafer.talks.models import Talk
 from wafer.pages.models import Page
@@ -19,7 +20,9 @@ class Meta:
         model = ScheduleItem
         fields = ('id', 'talk', 'page', 'venue', 'slots')
 
+    @revisions.create_revision()
     def create(self, validated_data):
+        request = self.context['request']
         venue_id = validated_data['venue']
         slots = validated_data['slots']
         talk = validated_data.get('talk')
@@ -29,7 +32,8 @@ def create(self, validated_data):
             existing_schedule_item = ScheduleItem.objects.get(
                 venue_id=venue_id, slots__in=slots)
         except ScheduleItem.DoesNotExist:
-            pass
+            revisions.set_user(request.user)
+            revisions.set_comment("Created using Schedule Editor")
         else:
             existing_schedule_item.talk = talk
             existing_schedule_item.page = page
@@ -41,5 +45,7 @@ def create(self, validated_data):
             existing_schedule_item.css_class = ''
             existing_schedule_item.expand = False
             existing_schedule_item.save()
+            revisions.set_user(request.user)
+            revisions.set_comment("Updated using Schedule Editor")
             return existing_schedule_item
         return super(ScheduleItemSerializer, self).create(validated_data)


Test patch: