Repository: carpentries/amy

Issue:
Show user what will be displayed on website after adding/changing Events
The top of the 'Event' display page should show users exactly what will be displayed on the main website given the current state of the Event: flag, date, link, event name, etc. This will help remind people about missing or erroneous fields, particularly as our rules continue to evolve.



Discussion:

Resolving patch:
diff --git a/api/serializers.py b/api/serializers.py
--- a/api/serializers.py
+++ b/api/serializers.py
@@ -38,35 +38,13 @@ class Meta:
 
 
 class EventSerializer(serializers.ModelSerializer):
-    humandate = serializers.SerializerMethodField()
+    humandate = serializers.CharField(source='human_readable_date')
     country = serializers.CharField()
     start = serializers.DateField(format=None)
     end = serializers.DateField(format=None)
     url = serializers.URLField(source='website_url')
     eventbrite_id = serializers.CharField(source='reg_key')
 
-    def get_humandate(self, obj):
-        """Render start and end dates as human-readable short date."""
-        return EventSerializer.human_readable_date(obj.start, obj.end)
-
-    @staticmethod
-    def human_readable_date(date1, date2):
-        """Render start and end dates as human-readable short date."""
-        if date1 and not date2:
-            return '{:%b %d, %Y}-???'.format(date1)
-        elif date2 and not date1:
-            return '???-{:%b %d, %Y}'.format(date2)
-        elif not date2 and not date1:
-            return '???-???'
-
-        if date1.year == date2.year:
-            if date1.month == date2.month:
-                return '{:%b %d}-{:%d, %Y}'.format(date1, date2)
-            else:
-                return '{:%b %d}-{:%b %d, %Y}'.format(date1, date2)
-        else:
-            return '{:%b %d, %Y}-{:%b %d, %Y}'.format(date1, date2)
-
     class Meta:
         model = Event
         fields = (
diff --git a/workshops/models.py b/workshops/models.py
--- a/workshops/models.py
+++ b/workshops/models.py
@@ -723,6 +723,27 @@ def get_invoice_form_url(self):
         url += urlencode(query)
         return url
 
+    @property
+    def human_readable_date(self):
+        """Render start and end dates as human-readable short date."""
+        date1 = self.start
+        date2 = self.end
+
+        if date1 and not date2:
+            return '{:%b %d, %Y}-???'.format(date1)
+        elif date2 and not date1:
+            return '???-{:%b %d, %Y}'.format(date2)
+        elif not date2 and not date1:
+            return '???-???'
+
+        if date1.year == date2.year:
+            if date1.month == date2.month:
+                return '{:%b %d}-{:%d, %Y}'.format(date1, date2)
+            else:
+                return '{:%b %d}-{:%b %d, %Y}'.format(date1, date2)
+        else:
+            return '{:%b %d, %Y}-{:%b %d, %Y}'.format(date1, date2)
+
     def get_ident(self):
         if self.slug:
             return str(self.slug)


Test patch:
diff --git a/api/test/test_events.py b/api/test/test_events.py
--- a/api/test/test_events.py
+++ b/api/test/test_events.py
@@ -119,9 +119,7 @@ def setUp(self):
                 'slug': 'event2',
                 'start': self.event2.start,
                 'end': self.event2.end,
-                'humandate': self.serializer_class.human_readable_date(
-                    self.event2.start, self.event2.end
-                ),
+                'humandate': self.event2.human_readable_date,
                 'latitude': 3.,
                 'longitude': -2.,
                 'venue': 'University',