[PATCH 4/6] models: Remove 'SeriesMixin'

Stephen Finucane stephen at that.guru
Fri Sep 7 07:14:04 AEST 2018


The property this provides, 'latest_series', is now a no-op and can be
removed along with the mixin itself.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/models.py                           | 22 ++---------------
 .../templates/patchwork/download_buttons.html |  2 +-
 patchwork/templates/patchwork/submission.html |  6 ++---
 patchwork/tests/test_series.py                | 24 +++++++++----------
 4 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/patchwork/models.py b/patchwork/models.py
index a52fc4f6..48a2f650 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -385,25 +385,7 @@ class Submission(FilenameMixin, EmailMixin, models.Model):
         unique_together = [('msgid', 'project')]
 
 
-class SeriesMixin(object):
-
-    @property
-    def latest_series(self):
-        """Get the latest series this is a member of.
-
-        Return the last series that (ordered by date) that this
-        submission is a member of.
-
-        .. warning::
-          Be judicious in your use of this. For example, do not use it
-          in list templates as doing so will result in a new query for
-          each item in the list.
-        """
-        # TODO(stephenfin): Remove this as it's no longer necessary
-        return self.series
-
-
-class CoverLetter(SeriesMixin, Submission):
+class CoverLetter(Submission):
 
     def get_absolute_url(self):
         return reverse('cover-detail', kwargs={'cover_id': self.id})
@@ -413,7 +395,7 @@ class CoverLetter(SeriesMixin, Submission):
 
 
 @python_2_unicode_compatible
-class Patch(SeriesMixin, Submission):
+class Patch(Submission):
     # patch metadata
 
     diff = models.TextField(null=True, blank=True)
diff --git a/patchwork/templates/patchwork/download_buttons.html b/patchwork/templates/patchwork/download_buttons.html
index 6a6a1960..21933bd2 100644
--- a/patchwork/templates/patchwork/download_buttons.html
+++ b/patchwork/templates/patchwork/download_buttons.html
@@ -16,7 +16,7 @@
    >mbox</a>
   {% endif %}
   {% if submission.series %}
-  <a href="{% url 'series-mbox' series_id=submission.latest_series.id %}"
+  <a href="{% url 'series-mbox' series_id=submission.series.id %}"
    class="btn btn-default" role="button"
    title="Download patch mbox with dependencies">series</a>
   {% endif %}
diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html
index 2b4bc719..9a22665d 100644
--- a/patchwork/templates/patchwork/submission.html
+++ b/patchwork/templates/patchwork/submission.html
@@ -64,7 +64,7 @@ function toggle_div(link_id, headers_id)
    </div>
   </td>
  </tr>
-{% if submission.latest_series %}
+{% if submission.series %}
  <tr>
   <th>Series</th>
   <td>
@@ -81,7 +81,7 @@ function toggle_div(link_id, headers_id)
    >show</a>
    <div id="patchrelations" class="patchrelations" style="display:none;">
     <ul>
-    {% with submission.latest_series.cover_letter as cover %}
+    {% with submission.series.cover_letter as cover %}
      <li>
      {% if cover %}
       {% if cover == submission %}
@@ -94,7 +94,7 @@ function toggle_div(link_id, headers_id)
      {% endif %}
      </li>
     {% endwith %}
-    {% for sibling in submission.latest_series.patches.all %}
+    {% for sibling in submission.series.patches.all %}
      <li>
       {% if sibling == submission %}
        {{ sibling.name|default:"[no subject]"|truncatechars:100 }}
diff --git a/patchwork/tests/test_series.py b/patchwork/tests/test_series.py
index 62f49cb6..d012568b 100644
--- a/patchwork/tests/test_series.py
+++ b/patchwork/tests/test_series.py
@@ -87,7 +87,7 @@ class _BaseTestCase(TestCase):
 
             patches_ = patches[start_idx:end_idx]
             for patch in patches_:
-                self.assertEqual(patch.latest_series, series[idx])
+                self.assertEqual(patch.series, series[idx])
 
                 # TODO(stephenfin): Rework this function into two different
                 # functions - we're clearly not always testing patches here
@@ -539,7 +539,7 @@ class SeriesTotalTest(_BaseTestCase):
         self.assertSerialized(patches, [1])
         self.assertSerialized(covers, [1])
 
-        series = patches[0].latest_series
+        series = patches[0].series
         self.assertFalse(series.received_all)
 
     def test_complete(self):
@@ -559,7 +559,7 @@ class SeriesTotalTest(_BaseTestCase):
         self.assertSerialized(covers, [1])
         self.assertSerialized(patches, [2])
 
-        series = patches[0].latest_series
+        series = patches[0].series
         self.assertTrue(series.received_all)
 
     def test_extra_patches(self):
@@ -580,7 +580,7 @@ class SeriesTotalTest(_BaseTestCase):
         self.assertSerialized(covers, [1])
         self.assertSerialized(patches, [3])
 
-        series = patches[0].latest_series
+        series = patches[0].series
         self.assertTrue(series.received_all)
 
 
@@ -661,13 +661,13 @@ class SeriesNameTestCase(TestCase):
 
         cover = self._parse_mail(mbox[0])
         cover_name = 'A sample series'
-        self.assertEqual(cover.latest_series.name, cover_name)
+        self.assertEqual(cover.series.name, cover_name)
 
         self._parse_mail(mbox[1])
-        self.assertEqual(cover.latest_series.name, cover_name)
+        self.assertEqual(cover.series.name, cover_name)
 
         self._parse_mail(mbox[2])
-        self.assertEqual(cover.latest_series.name, cover_name)
+        self.assertEqual(cover.series.name, cover_name)
 
         mbox.close()
 
@@ -685,7 +685,7 @@ class SeriesNameTestCase(TestCase):
         mbox = self._get_mbox('base-no-cover-letter.mbox')
 
         patch = self._parse_mail(mbox[0])
-        series = patch.latest_series
+        series = patch.series
         self.assertEqual(series.name, patch.name)
 
         self._parse_mail(mbox[1])
@@ -709,13 +709,13 @@ class SeriesNameTestCase(TestCase):
         mbox = self._get_mbox('base-out-of-order.mbox')
 
         patch = self._parse_mail(mbox[0])
-        self.assertIsNone(patch.latest_series.name)
+        self.assertIsNone(patch.series.name)
 
         patch = self._parse_mail(mbox[1])
-        self.assertEqual(patch.latest_series.name, patch.name)
+        self.assertEqual(patch.series.name, patch.name)
 
         cover = self._parse_mail(mbox[2])
-        self.assertEqual(cover.latest_series.name, 'A sample series')
+        self.assertEqual(cover.series.name, 'A sample series')
 
         mbox.close()
 
@@ -734,7 +734,7 @@ class SeriesNameTestCase(TestCase):
         """
         mbox = self._get_mbox('base-out-of-order.mbox')
 
-        series = self._parse_mail(mbox[0]).latest_series
+        series = self._parse_mail(mbox[0]).series
         self.assertIsNone(series.name)
 
         series_name = 'My custom series name'
-- 
2.17.1



More information about the Patchwork mailing list