Refactor get_downloads to make one query for default_version
@@ -630,18 +630,14 @@ class Project(models.Model):
def get_downloads(self):
downloads = {}
- downloads['htmlzip'] = self.get_production_media_url(
- 'htmlzip',
- self.get_default_version(),
- )
- downloads['epub'] = self.get_production_media_url(
- 'epub',
- self.get_default_version(),
- )
- downloads['pdf'] = self.get_production_media_url(
- 'pdf',
- self.get_default_version(),
+ default_version = self.get_default_version()
+
+ for type_ in ('htmlzip', 'epub', 'pdf'):
+ downloads[type_] = self.get_production_media_url(
+ type_,
+ default_version,
)
+
return downloads
@property
