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]})
|
permissions.append({'slug': slug, 'reason': reason, 'name': all_permission_names[slug]})
|
||||||
return permissions
|
return permissions
|
||||||
|
|
||||||
# FIXME make dependent on File or platform
|
# FIXME? make dependent on File or platform
|
||||||
@property
|
@property
|
||||||
def download_name(self) -> str:
|
def download_name(self) -> str:
|
||||||
Oleg-Komarov marked this conversation as resolved
Outdated
|
|||||||
"""Return a file name for downloads."""
|
"""Return a file name for downloads."""
|
||||||
replace_char = f'{self}'.replace('.', '-')
|
replace_char = f'{self}'.replace('.', '-')
|
||||||
Oleg-Komarov marked this conversation as resolved
Outdated
Anna Sirota
commented
to avoid making platform into file ext, maybe to avoid making platform into file ext, maybe `-`?
|
|||||||
return f'{utils.slugify(replace_char)}{self.files.first().suffix}'
|
return f'{utils.slugify(replace_char)}.zip'
|
||||||
|
|
||||||
# FIXME make dependent on File or platform
|
|
||||||
@property
|
|
||||||
def downloadable_signed_url(self) -> str:
|
|
||||||
# TODO: actual signed URLs?
|
|
||||||
return self.files.first().source.url
|
|
||||||
|
|
||||||
# FIXME make dependent on File or platform
|
# FIXME make dependent on File or platform
|
||||||
def download_url(self, append_repository_and_compatibility=True) -> str:
|
def download_url(self, append_repository_and_compatibility=True) -> str:
|
||||||
|
@ -91,6 +91,11 @@ urlpatterns = [
|
|||||||
public.extension_version_download,
|
public.extension_version_download,
|
||||||
name='version-download',
|
name='version-download',
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'<slug:slug>/<version>/<platform>/download/<filename>',
|
||||||
|
public.extension_version_platform_download,
|
||||||
|
name='version-platform-download',
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
'<slug:slug>/manage/versions/<int:pk>/upload/',
|
'<slug:slug>/manage/versions/<int:pk>/upload/',
|
||||||
manage.UploadVersionFileView.as_view(),
|
manage.UploadVersionFileView.as_view(),
|
||||||
|
@ -4,6 +4,7 @@ import logging
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.models import Count, Q
|
from django.db.models import Count, Q
|
||||||
|
from django.http import Http404
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import DetailView, ListView
|
from django.views.generic import DetailView, ListView
|
||||||
@ -52,6 +53,14 @@ class HomeView(ListedExtensionsView):
|
|||||||
|
|
||||||
|
|
||||||
def extension_version_download(request, type_slug, slug, version, filename):
|
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.
|
"""Download an extension version and count downloads.
|
||||||
|
|
||||||
The `filename` parameter is used to pass a file name ending with `.zip`.
|
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)
|
extension_version = get_object_or_404(Version, extension__slug=slug, version=version)
|
||||||
ExtensionDownload.create_from_request(request, object_id=extension_version.extension_id)
|
ExtensionDownload.create_from_request(request, object_id=extension_version.extension_id)
|
||||||
VersionDownload.create_from_request(request, object_id=extension_version.pk)
|
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):
|
class SearchView(ListedExtensionsView):
|
||||||
|
Loading…
Reference in New Issue
Block a user
The
filename
belowfilename = f'{self.extension.type_slug_singular}-{self.extension.slug}-v{self.version}.zip'
looks like a better name: doesn't rely on
self.__str__
.It also looks like these file names should be the same in both places.