Repository: carpentries/amy

Issue:
View archived requests
We can now create a new event in AMY based on a workshop request.  Once we do that though, the workshop request is no longer visible.  If I missed entering in some detail in creating the event, the workshop request is no longer visible. 

I know it's in my email but it would be nice to see it right from AMY.



Discussion:

Resolving patch:
diff --git a/workshops/urls.py b/workshops/urls.py
--- a/workshops/urls.py
+++ b/workshops/urls.py
@@ -67,6 +67,7 @@
     url(r'^revision/(?P<revision_id>[\d]+)/?$', views.object_changes, name='object_changes'),
 
     url(r'^requests/$', views.AllEventRequests.as_view(), name='all_eventrequests'),
+    url(r'^requests/closed/$', views.AllClosedEventRequests.as_view(), name='all_closed_eventrequests'),
     url(r'^request/(?P<request_id>\d+)/?$', views.EventRequestDetails.as_view(), name='eventrequest_details'),
     url(r'^request/(?P<request_id>\d+)/discard/?$', views.eventrequest_discard, name='eventrequest_discard'),
     url(r'^request/(?P<request_id>\d+)/accept/?$', views.eventrequest_accept, name='eventrequest_accept'),
@@ -74,6 +75,7 @@
     url(r'^dc/request/$', views.DCEventRequest.as_view(), name='dc_workshop_request'),
 
     url(r'^profile_updates/$', views.AllProfileUpdateRequests.as_view(), name='all_profileupdaterequests'),
+    url(r'^profile_updates/closed/$', views.AllClosedProfileUpdateRequests.as_view(), name='all_closed_profileupdaterequests'),
     url(r'^profile_update/(?P<request_id>\d+)/?$', views.profileupdaterequest_details, name='profileupdaterequest_details'),
     url(r'^profile_update/(?P<request_id>\d+)/discard/?$', views.profileupdaterequest_discard, name='profileupdaterequest_discard'),
     url(r'^profile_update/(?P<request_id>\d+)/accept/(?P<person_id>[\w\.-]+)/?$', views.profileupdaterequest_accept, name='profileupdaterequest_accept'),
diff --git a/workshops/views.py b/workshops/views.py
--- a/workshops/views.py
+++ b/workshops/views.py
@@ -1522,18 +1522,27 @@ class DCEventRequest(SWCEventRequest):
 
 
 class AllEventRequests(LoginRequiredMixin, ListView):
-    queryset = EventRequest.objects.filter(active=True).order_by('-created_at')
+    active_requests = True
     context_object_name = 'requests'
     template_name = 'workshops/all_eventrequests.html'
 
+    def get_queryset(self):
+        return EventRequest.objects.filter(active=self.active_requests) \
+                                   .order_by('-created_at')
+
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
         context['title'] = 'Workshop requests'
+        context['active_requests'] = self.active_requests
         return context
 
 
+class AllClosedEventRequests(AllEventRequests):
+    active_requests = False
+
+
 class EventRequestDetails(LoginRequiredMixin, DetailView):
-    queryset = EventRequest.objects.filter(active=True)
+    queryset = EventRequest.objects.all()
     context_object_name = 'object'
     template_name = 'workshops/eventrequest.html'
     pk_url_kwarg = 'request_id'
@@ -1620,20 +1629,29 @@ def profileupdaterequest_create(request):
 
 
 class AllProfileUpdateRequests(LoginRequiredMixin, ListView):
-    queryset = ProfileUpdateRequest.objects.filter(active=True) \
-                .order_by('-created_at')
+    active_requests = True
     context_object_name = 'requests'
     template_name = 'workshops/all_profileupdaterequests.html'
 
+    def get_queryset(self):
+        return ProfileUpdateRequest.objects \
+                                   .filter(active=self.active_requests) \
+                                   .order_by('-created_at')
+
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
         context['title'] = 'Instructor profile update requests'
+        context['active_requests'] = self.active_requests
         return context
 
 
+class AllClosedProfileUpdateRequests(AllProfileUpdateRequests):
+    active_requests = False
+
+
 @login_required
 def profileupdaterequest_details(request, request_id):
-    update_request = get_object_or_404(ProfileUpdateRequest, active=True,
+    update_request = get_object_or_404(ProfileUpdateRequest,
                                        pk=request_id)
 
     person_selected = False


Test patch:
diff --git a/workshops/test/test_event_requests.py b/workshops/test/test_event_requests.py
--- a/workshops/test/test_event_requests.py
+++ b/workshops/test/test_event_requests.py
@@ -136,3 +136,59 @@ def test_request_discarded(self):
         assert rv.status_code == 302
         er.refresh_from_db()
         assert not er.active
+
+
+class TestEventRequestsViews(TestBase):
+    def setUp(self):
+        self._setUpUsersAndLogin()
+
+        self.er1 = EventRequest.objects.create(
+            active=True, name="Harry Potter", email="harry@potter.com",
+            affiliation="Hogwarts", location="Scotland", country="GB",
+            preferred_date="soon",
+        )
+        self.er2 = EventRequest.objects.create(
+            active=False, name="Harry Potter", email="harry@potter.com",
+            affiliation="Hogwarts", location="Scotland", country="GB",
+            preferred_date="soon",
+        )
+
+    def test_active_requests_list(self):
+        rv = self.client.get(reverse('all_eventrequests'))
+        assert self.er1 in rv.context['object_list']
+        assert self.er2 not in rv.context['object_list']
+
+    def test_inactive_requests_list(self):
+        rv = self.client.get(reverse('all_closed_eventrequests'))
+        assert self.er1 not in rv.context['object_list']
+        assert self.er2 in rv.context['object_list']
+
+    def test_active_request_view(self):
+        rv = self.client.get(reverse('eventrequest_details',
+                                     args=[self.er1.pk]))
+        assert rv.status_code == 200
+
+    def test_inactive_request_view(self):
+        rv = self.client.get(reverse('eventrequest_details',
+                                     args=[self.er2.pk]))
+        assert rv.status_code == 200
+
+    def test_active_request_accept(self):
+        rv = self.client.get(reverse('eventrequest_accept',
+                                     args=[self.er1.pk]))
+        assert rv.status_code == 200
+
+    def test_inactive_request_accept(self):
+        rv = self.client.get(reverse('eventrequest_accept',
+                                     args=[self.er2.pk]))
+        assert rv.status_code != 200
+
+    def test_active_request_discard(self):
+        rv = self.client.get(reverse('eventrequest_discard',
+                                     args=[self.er1.pk]), follow=True)
+        assert rv.status_code == 200
+
+    def test_inactive_request_discard(self):
+        rv = self.client.get(reverse('eventrequest_discard',
+                                     args=[self.er2.pk]), follow=True)
+        assert rv.status_code != 200
diff --git a/workshops/test/test_profile_update_request.py b/workshops/test/test_profile_update_request.py
--- a/workshops/test/test_profile_update_request.py
+++ b/workshops/test/test_profile_update_request.py
@@ -111,3 +111,65 @@ def test_request_accepted(self):
         assert set(person.domains.all()) == \
             set(KnowledgeDomain.objects.all()[0:2])
         assert set(person.lessons.all()) == set(Lesson.objects.all()[0:2])
+
+
+class TestProfileUpdateRequestsViews(TestBase):
+    def setUp(self):
+        self._setUpAirports()
+        self._setUpLessons()
+        self._setUpBadges()
+        self._setUpInstructors()
+        self._setUpUsersAndLogin()
+
+        self.pur1 = ProfileUpdateRequest.objects.create(
+            active=True, personal="Harry", family="Potter",
+            email="harry@potter.com", airport_iata='AAA',
+            affiliation='Hogwarts',
+        )
+        self.pur2 = ProfileUpdateRequest.objects.create(
+            active=False, personal="Harry", family="Potter",
+            email="harry@potter.com", airport_iata='AAA',
+            affiliation='Hogwarts',
+        )
+
+    def test_active_requests_list(self):
+        rv = self.client.get(reverse('all_profileupdaterequests'))
+        assert self.pur1 in rv.context['object_list']
+        assert self.pur2 not in rv.context['object_list']
+
+    def test_inactive_requests_list(self):
+        rv = self.client.get(reverse('all_closed_profileupdaterequests'))
+        assert self.pur1 not in rv.context['object_list']
+        assert self.pur2 in rv.context['object_list']
+
+    def test_active_request_view(self):
+        rv = self.client.get(reverse('profileupdaterequest_details',
+                                     args=[self.pur1.pk]))
+        assert rv.status_code == 200
+
+    def test_inactive_request_view(self):
+        rv = self.client.get(reverse('profileupdaterequest_details',
+                                     args=[self.pur2.pk]))
+        assert rv.status_code == 200
+
+    def test_active_request_accept(self):
+        rv = self.client.get(reverse('profileupdaterequest_accept',
+                                     args=[self.pur1.pk, self.harry.pk]),
+                             follow=True)
+        assert rv.status_code == 200
+
+    def test_inactive_request_accept(self):
+        rv = self.client.get(reverse('profileupdaterequest_accept',
+                                     args=[self.pur2.pk, self.harry.pk]),
+                             follow=True)
+        assert rv.status_code != 200
+
+    def test_active_request_discard(self):
+        rv = self.client.get(reverse('profileupdaterequest_discard',
+                                     args=[self.pur1.pk]), follow=True)
+        assert rv.status_code == 200
+
+    def test_inactive_request_discard(self):
+        rv = self.client.get(reverse('profileupdaterequest_discard',
+                                     args=[self.pur2.pk]), follow=True)
+        assert rv.status_code != 200