From: Stephen Finucane Date: Wed, 5 Sep 2018 14:53:32 +0000 (+0100) Subject: models: Remove 'latest_series' X-Git-Tag: v2.2.0-rc1~290 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84def8549f6fc624a523e4c45480305848f29cc9;p=thirdparty%2Fpatchwork.git models: Remove 'latest_series' This is only used in a single view (where it probably shouldn't be used) and some tests. It's an anti-pattern that makes it too easy to shoot yourself in the foot. Remove it. Signed-off-by: Stephen Finucane --- diff --git a/patchwork/models.py b/patchwork/models.py index d2d8f343..8731bb2f 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -393,26 +393,7 @@ class Submission(FilenameMixin, EmailMixin, models.Model): ] -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. - """ - # NOTE(stephenfin): We don't use 'latest()' here, as this can raise an - # exception if no series exist - return self.series.order_by('-date').first() - - -class CoverLetter(SeriesMixin, Submission): +class CoverLetter(Submission): def get_absolute_url(self): return reverse('cover-detail', kwargs={'cover_id': self.id}) @@ -422,7 +403,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 4809db54..32acf26b 100644 --- a/patchwork/templates/patchwork/download_buttons.html +++ b/patchwork/templates/patchwork/download_buttons.html @@ -15,17 +15,19 @@ class="btn btn-default" role="button" title="Download cover mbox" >mbox {% endif %} - {% if submission.series.all|length == 1 %} - series - {% elif submission.series.all|length > 1 %} + {% endwith %} + {% elif all_series|length > 1 %}