in bedrock/firefox/views.py [0:0]
def firefox_all(request, product_slug=None, platform=None, locale=None):
ftl_files = "firefox/all"
# A product object for android OR ios.
class MobileRelease:
slug = "mobile-release"
mobile_release = MobileRelease()
product_map = {
"desktop-release": {
"slug": "desktop-release",
"product": firefox_desktop,
"channel": "release",
"name": ftl("firefox-all-product-firefox", ftl_files=ftl_files),
},
"desktop-beta": {
"slug": "desktop-beta",
"product": firefox_desktop,
"channel": "beta",
"name": ftl("firefox-all-product-firefox-beta", ftl_files=ftl_files),
},
"desktop-developer": {
"slug": "desktop-developer",
"product": firefox_desktop,
"channel": "devedition",
"name": ftl("firefox-all-product-firefox-developer", ftl_files=ftl_files),
},
"desktop-nightly": {
"slug": "desktop-nightly",
"product": firefox_desktop,
"channel": "nightly",
"name": ftl("firefox-all-product-firefox-nightly", ftl_files=ftl_files),
},
"desktop-esr": {
"slug": "desktop-esr",
"product": firefox_desktop,
"channel": "esr",
"name": ftl("firefox-all-product-firefox-esr", ftl_files=ftl_files),
},
"android-release": {
"slug": "android-release",
"product": firefox_android,
"channel": "release",
"name": ftl("firefox-all-product-firefox-android", ftl_files=ftl_files),
},
"android-beta": {
"slug": "android-beta",
"product": firefox_android,
"channel": "beta",
"name": ftl("firefox-all-product-firefox-android-beta", ftl_files=ftl_files),
},
"android-nightly": {
"slug": "android-nightly",
"product": firefox_android,
"channel": "nightly",
"name": ftl("firefox-all-product-firefox-android-nightly", ftl_files=ftl_files),
},
"ios-release": {
"slug": "ios-release",
"product": firefox_ios,
"channel": "release",
"name": ftl("firefox-all-product-firefox-ios", ftl_files=ftl_files),
},
"ios-beta": {
"slug": "ios-beta",
"product": firefox_ios,
"channel": "beta",
"name": ftl("firefox-all-product-firefox-ios", ftl_files=ftl_files),
},
# mobile-release is a special case for both android and ios.
"mobile-release": {
"slug": "mobile-release",
"product": mobile_release,
"channel": "release",
"name": ftl("firefox-all-product-firefox", ftl_files=ftl_files),
},
}
platform_map = {
"win64": "Windows 64-bit",
"win64-msi": "Windows 64-bit MSI",
"win64-aarch64": "Windows ARM64/AArch64",
"win": "Windows 32-bit",
"win-msi": "Windows 32-bit MSI",
"win-store": "Microsoft Store",
"osx": "macOS",
"linux64": "Linux 64-bit",
"linux": "Linux 32-bit",
"linux64-aarch64": "Linux ARM64/AArch64",
}
# 404 checks.
if product_slug and product_slug not in product_map.keys():
raise Http404()
if platform and platform not in platform_map.keys():
raise Http404()
if locale and locale not in product_details.languages.keys():
raise Http404()
# 404 if win-store and not desktop-release.
if platform == "win-store" and product_slug not in ["desktop-release", "desktop-beta"]:
raise Http404()
product = product_map.get(product_slug)
platform_name = None
locale_name = None
download_url = None
template_name = "firefox/all/base.html"
lang_multi = ftl("firefox-all-lang-multi", ftl_files=ftl_files)
if product:
if product_slug.startswith(("mobile", "android", "ios")):
locale = "en-US"
locale_name = lang_multi
download_url = True # Set to True to avoid trying to generate this later below.
if product_slug.startswith("mobile"):
platform = "mobile"
platform_name = ftl("firefox-all-plat-mobile", ftl_files=ftl_files)
elif product_slug.startswith("android"):
platform = "android"
platform_name = "Android"
elif product_slug.startswith("ios"):
platform = "ios"
platform_name = "iOS"
elif product_slug in ("desktop-release", "desktop-beta") and platform == "win-store":
platform_name = "Microsoft Store"
locale = "en-US"
locale_name = lang_multi
download_url = {
"desktop-release": settings.MICROSOFT_WINDOWS_STORE_FIREFOX_WEB_LINK,
"desktop-beta": settings.MICROSOFT_WINDOWS_STORE_FIREFOX_BETA_WEB_LINK,
}.get(product_slug)
else:
platform_name = platform and platform_map[platform]
locale_name = None
if locale:
try:
build = list(filter(lambda b: b["locale"] == locale, product["product"].get_filtered_full_builds(product["channel"])))[0]
except IndexError:
raise Http404()
locale_name = f"{build['name_en']} - {build['name_native']}"
context = {
"product": product,
"platform": platform,
"platform_name": platform_name,
"locale": locale,
"locale_name": locale_name,
}
# `firefox_desktop.esr_minor_versions` could have 0, 1, or 2 elements. This adds defaults so we always have 2 to unpack.
esr_latest_version, esr_next_version = (firefox_desktop.esr_minor_versions + [None, None])[:2]
if esr_next_version:
context.update(
desktop_esr_latest_version=esr_latest_version,
desktop_esr_next_version=esr_next_version,
)
# Show download link
if locale:
if not download_url:
download_url = list(filter(lambda b: b["locale"] == locale, product["product"].get_filtered_full_builds(product["channel"])))[0][
"platforms"
][platform]["download_url"]
context.update(
download_url=download_url,
)
try:
if product_slug == "desktop-esr":
download_esr_115_url = list(filter(lambda b: b["locale"] == locale, firefox_desktop.get_filtered_full_builds("esr115")))[0][
"platforms"
][platform]["download_url"]
# ESR115 builds do not exist for "sat" ans "skr" languages (see issue #15437).
if locale in ["sat", "skr"]:
download_esr_115_url = None
context.update(
download_esr_115_url=download_esr_115_url,
)
except IndexError:
pass
if product_slug == "desktop-esr" and esr_next_version:
try:
download_esr_next_url = list(filter(lambda b: b["locale"] == locale, firefox_desktop.get_filtered_full_builds("esr_next")))[0][
"platforms"
][platform]["download_url"]
context.update(
download_esr_next_url=download_esr_next_url,
)
except IndexError:
# If the ESR next version is not available for the locale, remove the context variables.
context.pop("desktop_esr_latest_version", None)
context.pop("desktop_esr_next_version", None)
# Show platforms with download links
elif platform:
locales = []
for b in product["product"].get_filtered_full_builds(product["channel"]):
locale_name = f"{b['name_en']} - {b['name_native']}"
if b["locale"] == request.locale:
# If locale matches request's locale, put it at the top.
locales.insert(0, (b["locale"], locale_name))
else:
locales.append((b["locale"], locale_name))
context.update(
locales=locales,
)
# Show locales.
elif product_slug:
platforms = product["product"].platforms(product["channel"])
if product_slug in ["desktop-release", "desktop-beta"]:
idx = platforms.index(("osx", "macOS"))
platforms.insert(idx, ("win-store", "Microsoft Store"))
context.update(platforms=platforms)
# Show products.
else:
context.update(
products=[{"slug": k, "name": v["name"]} for k, v in product_map.items()],
)
return l10n_utils.render(request, template_name, context, ftl_files=ftl_files)