From 6f1f7fa04df3f34c5843db3da22f246078f86cb1 Mon Sep 17 00:00:00 2001 From: Sean Farley Date: Tue, 11 Jul 2017 11:41:36 -0700 Subject: [PATCH] models: Add 'Series._format_name' helper This method already exists, but is nested and its functionality duplicated elsewhere. Making this a staticmethod allows us to reuse it. Signed-off-by: Sean Farley Signed-off-by: Stephen Finucane --- patchwork/models.py | 11 ++++++----- patchwork/tests/test_series.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/patchwork/models.py b/patchwork/models.py index dcb4c555..e1350c23 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -617,6 +617,10 @@ class Series(FilenameMixin, models.Model): total = models.IntegerField(help_text='Number of patches in series as ' 'indicated by the subject prefix(es)') + @staticmethod + def _format_name(obj): + return obj.name.split(']')[-1].strip() + @property def received_total(self): return self.patches.count() @@ -632,9 +636,6 @@ class Series(FilenameMixin, models.Model): patches and cover letters. """ - def _format_name(obj): - return obj.name.split(']')[-1] - if self.cover_letter: # TODO(stephenfin): We may wish to raise an exception here in the # future @@ -657,7 +658,7 @@ class Series(FilenameMixin, models.Model): # If none of the above are available, the name will be null. if not self.name: - self.name = _format_name(cover) + self.name = self._format_name(cover) else: try: name = SeriesPatch.objects.get(series=self, @@ -666,7 +667,7 @@ class Series(FilenameMixin, models.Model): name = None if self.name == name: - self.name = _format_name(cover) + self.name = self._format_name(cover) self.save() diff --git a/patchwork/tests/test_series.py b/patchwork/tests/test_series.py index e26dd3ee..6d656d6f 100644 --- a/patchwork/tests/test_series.py +++ b/patchwork/tests/test_series.py @@ -639,7 +639,7 @@ class SeriesNameTestCase(TestCase): @staticmethod def _format_name(cover): - return cover.name.split(']')[-1] + return models.Series._format_name(cover) def test_cover_letter(self): """Cover letter name set as series name. -- 2.47.3