Repository: watchdogpolska/feder

Issue:
Wprowadzić wykaz projektów listów
![zaznaczenie_0951](https://user-images.githubusercontent.com/3618479/29756710-40121212-8ba6-11e7-9c09-607e78e27067.png)

Jak na zdjęciu widoczny tylko dla osób uprawnionych do zatwierdzenia projektów.


Discussion:

Resolving patch:
diff --git a/feder/letters/models.py b/feder/letters/models.py
--- a/feder/letters/models.py
+++ b/feder/letters/models.py
@@ -43,6 +43,9 @@ def with_author(self):
     def for_milestone(self):
         return self.prefetch_related('attachment_set').with_author()
 
+    def is_draft(self):
+            return self.is_outgoing().filter(eml='')
+
     def is_outgoing(self):
         return self.filter(author_user__isnull=False)
 
diff --git a/feder/monitorings/urls.py b/feder/monitorings/urls.py
--- a/feder/monitorings/urls.py
+++ b/feder/monitorings/urls.py
@@ -24,6 +24,10 @@
         name="letters"),
     url(_(r'^(?P<slug>[\w-]+)/letter/page-(?P<page>[\d]+)$'), views.LetterListMonitoringView.as_view(),
         name="letters"),
+    url(_(r'^(?P<slug>[\w-]+)/drafts'), views.DraftListMonitoringView.as_view(),
+        name="drafts"),
+    url(_(r'^(?P<slug>[\w-]+)/drafts/page-(?P<page>[\d]+)$'), views.DraftListMonitoringView.as_view(),
+        name="drafts"),
     url(_(r'^(?P<slug>[\w-]+)/~update$'), views.MonitoringUpdateView.as_view(),
         name="update"),
     url(_(r'^(?P<slug>[\w-]+)/~delete$'), views.MonitoringDeleteView.as_view(),
diff --git a/feder/monitorings/views.py b/feder/monitorings/views.py
--- a/feder/monitorings/views.py
+++ b/feder/monitorings/views.py
@@ -74,6 +74,23 @@ def get_object_list(self, obj):
                 all())
 
 
+class DraftListMonitoringView(SelectRelatedMixin, PrefetchRelatedMixin, ExtraListMixin, DetailView):
+    model = Monitoring
+    template_name_suffix = '_draft_list'
+    select_related = ['user', ]
+    prefetch_related = ['questionary_set', ]
+    paginate_by = 25
+
+    def get_object_list(self, obj):
+        return (Letter.objects.filter(case__monitoring=obj).
+                is_draft().
+                select_related('case').
+                with_author().
+                attachment_count().
+                order_by('-created').
+                all())
+
+
 class MonitoringCreateView(LoginRequiredMixin, PermissionRequiredMixin,
                            UserFormKwargsMixin, CreateView):
     model = Monitoring


Test patch:
diff --git a/feder/monitorings/tests.py b/feder/monitorings/tests.py
--- a/feder/monitorings/tests.py
+++ b/feder/monitorings/tests.py
@@ -6,6 +6,7 @@
 from feder.cases.models import Case
 from feder.institutions.factories import InstitutionFactory
 from feder.letters.factories import IncomingLetterFactory
+from feder.letters.factories import OutgoingLetterFactory
 from feder.main.mixins import PermissionStatusMixin
 from feder.users.factories import UserFactory
 from .factories import MonitoringFactory
@@ -114,6 +115,27 @@ def test_display_letter(self):
         self.assertContains(response, letter.note)
 
 
+class DraftListMonitoringViewTestCase(ObjectMixin, PermissionStatusMixin, TestCase):
+    status_anonymous = 200
+    status_no_permission = 200
+    permission = []
+
+    def get_url(self):
+        return reverse('monitorings:drafts', kwargs={'slug': self.monitoring})
+
+    def test_list_display(self):
+        response = self.client.get(self.get_url())
+        self.assertEqual(response.status_code, 200)
+        self.assertContains(response, self.monitoring)
+
+    def test_display_draft(self):
+        draft_letter = OutgoingLetterFactory(case__monitoring=self.monitoring)
+        incoming_letter = IncomingLetterFactory(case__monitoring=self.monitoring)
+        response = self.client.get(self.get_url())
+        self.assertContains(response, draft_letter.body)
+        self.assertContains(response, draft_letter.note)
+        self.assertNotContains(response, incoming_letter.body)
+
 class MonitoringUpdateViewTestCase(ObjectMixin, PermissionStatusMixin, TestCase):
     permission = ['monitorings.change_monitoring', ]