Refactor get_downloads
-# -*- coding: utf-8 -*-
-
"""Models for the builds app."""
import datetime
@@ -258,29 +256,22 @@ class Version(models.Model):
def get_downloads(self, pretty=False):
project = self.project
data = {}
- if pretty:
+
+ def prettify(k):
+ return k if pretty else k.lower()
+
if project.has_pdf(self.slug):
- data['PDF'] = project.get_production_media_url('pdf', self.slug)
- if project.has_htmlzip(self.slug):
- data['HTML'] = project.get_production_media_url(
- 'htmlzip',
+ data[prettify('PDF')] = project.get_production_media_url(
+ 'pdf',
self.slug,
)
- if project.has_epub(self.slug):
- data['Epub'] = project.get_production_media_url(
- 'epub',
- self.slug,
- )
- else:
- if project.has_pdf(self.slug):
- data['pdf'] = project.get_production_media_url('pdf', self.slug)
if project.has_htmlzip(self.slug):
- data['htmlzip'] = project.get_production_media_url(
+ data[prettify('HTML')] = project.get_production_media_url(
'htmlzip',
self.slug,
)
if project.has_epub(self.slug):
- data['epub'] = project.get_production_media_url(
+ data[prettify('Epub')] = project.get_production_media_url(
'epub',
self.slug,
)
