Repository: carpentries/amy

Issue:
"Upcoming" workshops list
I like having this list displayed on the AMY dashboard.  Can you change it so workshops remain on the list until the workshop is over -  so it should display all workshops where end_date >= today.



Discussion:

Resolving patch:
diff --git a/workshops/views.py b/workshops/views.py
--- a/workshops/views.py
+++ b/workshops/views.py
@@ -154,14 +154,16 @@ def as_view(cls, **kwargs):
 @login_required
 def dashboard(request):
     '''Home page.'''
-    upcoming_events = Event.objects.upcoming_events()
+    upcoming_ongoing_events = (
+        Event.objects.upcoming_events() | Event.objects.ongoing_events()
+    )
     unpublished_events = Event.objects.unpublished_events()
     uninvoiced_events = Event.objects.uninvoiced_events()
     recently_changed = Revision.objects.all().select_related('user') \
                                        .prefetch_related('version_set') \
                                        .order_by('-date_created')[:50]
     context = {'title': None,
-               'upcoming_events': upcoming_events,
+               'upcoming_ongoing_events': upcoming_ongoing_events,
                'uninvoiced_events': uninvoiced_events,
                'unpublished_events': unpublished_events,
                'recently_changed': recently_changed}


Test patch:
diff --git a/workshops/test/base.py b/workshops/test/base.py
--- a/workshops/test/base.py
+++ b/workshops/test/base.py
@@ -221,7 +221,7 @@ def _setUpEvents(self):
         event_end = today + datetime.timedelta(days=1)
         Event.objects.create(start=event_start,
                              end=event_end,
-                             slug='ends_tomorrow',
+                             slug='ends_tomorrow_ongoing',
                              host=test_host,
                              admin_fee=0)
 
@@ -231,7 +231,7 @@ def _setUpEvents(self):
         event_end = today
         Event.objects.create(start=event_start,
                              end=event_end,
-                             slug='ends_today',
+                             slug='ends_today_ongoing',
                              host=test_host,
                              admin_fee=0)
 
@@ -241,7 +241,7 @@ def _setUpEvents(self):
         event_end = today + datetime.timedelta(days=1)
         Event.objects.create(start=event_start,
                              end=event_end,
-                             slug='starts_today',
+                             slug='starts_today_ongoing',
                              host=test_host,
                              admin_fee=100)
 
diff --git a/workshops/test/test_event.py b/workshops/test/test_event.py
--- a/workshops/test/test_event.py
+++ b/workshops/test/test_event.py
@@ -62,9 +62,9 @@ def test_get_ongoing_events(self):
 
         ongoing_events = Event.objects.ongoing_events()
         event_slugs = [e.slug for e in ongoing_events]
-        correct_slugs = ['starts_today',
-                         'ends_tomorrow',
-                         'ends_today', ]
+        correct_slugs = ['starts_today_ongoing',
+                         'ends_tomorrow_ongoing',
+                         'ends_today_ongoing', ]
 
         if sys.version_info >= (3,):
             self.assertCountEqual(event_slugs, correct_slugs)
@@ -108,7 +108,7 @@ def test_edit_event(self):
 
     def test_delete_event(self):
         """Make sure deleted event and its tasks are no longer accessible."""
-        event = Event.objects.get(slug="starts_today")
+        event = Event.objects.get(slug="starts_today_ongoing")
         role1 = Role.objects.create(name='NonInstructor')
         t1 = Task.objects.create(event=event, person=self.spiderman,
                                  role=role1)
@@ -123,7 +123,7 @@ def test_delete_event(self):
         assert rv.status_code == 302
 
         with self.assertRaises(Event.DoesNotExist):
-            Event.objects.get(slug="starts_today")
+            Event.objects.get(slug="starts_today_ongoing")
 
         for t in [t1, t2, t3]:
             with self.assertRaises(Task.DoesNotExist):
@@ -133,7 +133,7 @@ def test_delete_event_with_tasks_and_awards(self):
         """Ensure we cannot delete an event with related tasks and awards.
 
         Deletion is prevented via Award.event's on_delete=PROTECT."""
-        event = Event.objects.get(slug="starts_today")
+        event = Event.objects.get(slug="starts_today_ongoing")
         role = Role.objects.create(name='NonInstructor')
         badge = Badge.objects.create(name='noninstructor',
                                      title='Non-instructor',
diff --git a/workshops/test/test_landing_page.py b/workshops/test/test_landing_page.py
--- a/workshops/test/test_landing_page.py
+++ b/workshops/test/test_landing_page.py
@@ -21,10 +21,8 @@ def test_has_upcoming_events(self):
         response = self.client.get(reverse('dashboard'))
 
         # This will fail if the context variable doesn't exist
-        upcoming_events = response.context['upcoming_events']
-
-        # Count published upcoming events.
-        assert len(upcoming_events) == self.num_upcoming
+        events = response.context['upcoming_ongoing_events']
 
         # They should all be labeled 'upcoming'.
-        assert all([('upcoming' in e.slug) for e in upcoming_events])
+        assert all([('upcoming' in e.slug or 'ongoing' in e.slug)
+                    for e in events])