change release section put video and more
This commit is contained in:
@@ -23,10 +23,14 @@ def downloads_section_link(product):
|
||||
|
||||
def featured_version(qs):
|
||||
ordered = qs.order_by("order", "pk")
|
||||
cand = ordered.filter(is_featured_stable=True).first()
|
||||
cand = ordered.filter(is_featured=True).first()
|
||||
return cand if cand else ordered.first()
|
||||
|
||||
|
||||
def version_has_public_assets(version):
|
||||
return version.has_any_install_asset() or bool((version.package_resource_url or "").strip())
|
||||
|
||||
|
||||
def install_specs_from_versions(version_list):
|
||||
present = set()
|
||||
for ver in version_list:
|
||||
@@ -36,13 +40,29 @@ def install_specs_from_versions(version_list):
|
||||
return tuple(s for s in INSTALLABLE_PLATFORM_SPECS if s[0] in present)
|
||||
|
||||
|
||||
def build_installable_channel_block(version):
|
||||
if not version_has_public_assets(version):
|
||||
return None
|
||||
block = {
|
||||
"version": version,
|
||||
"install_cells": [],
|
||||
"is_previous": version.is_previous_channel,
|
||||
}
|
||||
if version.has_any_install_asset():
|
||||
specs = install_specs_from_versions([version])
|
||||
block["install_cells"] = version.install_urls_for_specs(specs)
|
||||
return block
|
||||
|
||||
|
||||
def build_release_context(distribution, active_versions, product):
|
||||
context = {
|
||||
"distribution_installable": distribution == DISTRIBUTION_INSTALLABLE,
|
||||
"distribution_package": distribution == DISTRIBUTION_PACKAGE,
|
||||
"show_releases_section": False,
|
||||
"featured_version": None,
|
||||
"featured_channel": None,
|
||||
"featured_install_cells": [],
|
||||
"inline_download_channels": [],
|
||||
"show_older_versions_link": False,
|
||||
"package_versions": [],
|
||||
**package_button_labels(product),
|
||||
@@ -51,30 +71,36 @@ def build_release_context(distribution, active_versions, product):
|
||||
|
||||
if distribution == DISTRIBUTION_INSTALLABLE:
|
||||
featured = featured_version(active_versions)
|
||||
if (
|
||||
featured
|
||||
and not featured.has_any_install_asset()
|
||||
and not (featured.package_resource_url or "").strip()
|
||||
):
|
||||
if featured and not version_has_public_assets(featured):
|
||||
for cand in active_versions.exclude(pk=featured.pk).order_by("order", "pk"):
|
||||
if cand.has_any_install_asset() or (cand.package_resource_url or "").strip():
|
||||
if version_has_public_assets(cand):
|
||||
featured = cand
|
||||
break
|
||||
context["featured_version"] = featured
|
||||
if featured and (
|
||||
featured.has_any_install_asset()
|
||||
or (featured.package_resource_url or "").strip()
|
||||
):
|
||||
if featured.has_any_install_asset():
|
||||
specs = install_specs_from_versions([featured])
|
||||
context["featured_install_cells"] = featured.install_urls_for_specs(specs)
|
||||
context["show_releases_section"] = True
|
||||
older_list = list(
|
||||
active_versions.exclude(pk=featured.pk).order_by("order", "pk")
|
||||
if featured
|
||||
else active_versions.order_by("order", "pk")
|
||||
)
|
||||
context["show_older_versions_link"] = len(older_list) > 0
|
||||
if featured and version_has_public_assets(featured):
|
||||
featured_block = build_installable_channel_block(featured)
|
||||
if featured_block:
|
||||
context["featured_channel"] = featured_block
|
||||
context["featured_install_cells"] = featured_block["install_cells"]
|
||||
context["show_releases_section"] = True
|
||||
|
||||
inline_blocks = []
|
||||
for ver in active_versions.order_by("order", "pk"):
|
||||
if featured and ver.pk == featured.pk:
|
||||
continue
|
||||
if not ver.show_on_product_page:
|
||||
continue
|
||||
block = build_installable_channel_block(ver)
|
||||
if block:
|
||||
inline_blocks.append(block)
|
||||
context["inline_download_channels"] = inline_blocks
|
||||
|
||||
shown_pks = {featured.pk} if featured else set()
|
||||
shown_pks.update(block["version"].pk for block in inline_blocks)
|
||||
older_qs = active_versions.order_by("order", "pk")
|
||||
if shown_pks:
|
||||
older_qs = older_qs.exclude(pk__in=shown_pks)
|
||||
context["show_older_versions_link"] = older_qs.exists()
|
||||
|
||||
elif distribution == DISTRIBUTION_PACKAGE:
|
||||
pkg_versions = list(active_versions.order_by("order", "pk"))
|
||||
@@ -86,9 +112,16 @@ def build_release_context(distribution, active_versions, product):
|
||||
|
||||
def build_archive_context(distribution, active_versions, product):
|
||||
featured = featured_version(active_versions)
|
||||
inline_pks = set(
|
||||
active_versions.filter(show_on_product_page=True).values_list("pk", flat=True)
|
||||
)
|
||||
exclude_pks = set()
|
||||
if featured:
|
||||
exclude_pks.add(featured.pk)
|
||||
exclude_pks.update(inline_pks)
|
||||
archive = list(
|
||||
active_versions.exclude(pk=featured.pk).order_by("order", "pk")
|
||||
if featured
|
||||
active_versions.exclude(pk__in=exclude_pks).order_by("order", "pk")
|
||||
if exclude_pks
|
||||
else active_versions.order_by("order", "pk")
|
||||
)
|
||||
context = {
|
||||
|
||||
Reference in New Issue
Block a user