Multi-platform: support multiple files per version #201
@ -755,18 +755,12 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
permissions.append({'slug': slug, 'reason': reason, 'name': all_permission_names[slug]})
|
||||
return permissions
|
||||
|
||||
# FIXME make dependent on File or platform
|
||||
# FIXME? make dependent on File or platform
|
||||
@property
|
||||
def download_name(self) -> str:
|
||||
"""Return a file name for downloads."""
|
||||
replace_char = f'{self}'.replace('.', '-')
|
||||
return f'{utils.slugify(replace_char)}{self.files.first().suffix}'
|
||||
|
||||
# FIXME make dependent on File or platform
|
||||
@property
|
||||
def downloadable_signed_url(self) -> str:
|
||||
# TODO: actual signed URLs?
|
||||
return self.files.first().source.url
|
||||
return f'{utils.slugify(replace_char)}.zip'
|
||||
|
||||
# FIXME make dependent on File or platform
|
||||
def download_url(self, append_repository_and_compatibility=True) -> str:
|
||||
|
@ -91,6 +91,11 @@ urlpatterns = [
|
||||
public.extension_version_download,
|
||||
name='version-download',
|
||||
),
|
||||
path(
|
||||
'<slug:slug>/<version>/<platform>/download/<filename>',
|
||||
public.extension_version_platform_download,
|
||||
name='version-platform-download',
|
||||
),
|
||||
path(
|
||||
'<slug:slug>/manage/versions/<int:pk>/upload/',
|
||||
manage.UploadVersionFileView.as_view(),
|
||||
|
@ -4,6 +4,7 @@ import logging
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import connection
|
||||
from django.db.models import Count, Q
|
||||
from django.http import Http404
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import DetailView, ListView
|
||||
@ -52,6 +53,14 @@ class HomeView(ListedExtensionsView):
|
||||
|
||||
|
||||
def extension_version_download(request, type_slug, slug, version, filename):
|
||||
"""A backward-compatible shortcut for the method below.
|
||||
|
||||
No platform is specified, assuming only a single file for a given version.
|
||||
"""
|
||||
return extension_version_platform_download(request, type_slug, slug, version, None, filename)
|
||||
|
||||
|
||||
def extension_version_platform_download(request, type_slug, slug, version, platform, filename):
|
||||
"""Download an extension version and count downloads.
|
||||
|
||||
The `filename` parameter is used to pass a file name ending with `.zip`.
|
||||
@ -61,7 +70,12 @@ def extension_version_download(request, type_slug, slug, version, filename):
|
||||
extension_version = get_object_or_404(Version, extension__slug=slug, version=version)
|
||||
ExtensionDownload.create_from_request(request, object_id=extension_version.extension_id)
|
||||
VersionDownload.create_from_request(request, object_id=extension_version.pk)
|
||||
return redirect(extension_version.downloadable_signed_url + f'?filename={filename}')
|
||||
for file in extension_version.files.all():
|
||||
platforms = file.platforms() or []
|
||||
if platform is None or platform in platforms:
|
||||
url = file.source.url
|
||||
return redirect(f'{url}?filename={filename}')
|
||||
raise Http404()
|
||||
|
||||
|
||||
class SearchView(ListedExtensionsView):
|
||||
|
Loading…
Reference in New Issue
Block a user