in bedrock/products/views.py [0:0]
def resource_center_article_view(request, slug):
"""Individual detail pages for the VPN Resource Center"""
template_name = "products/vpn/resource-center/article.html"
requested_locale = l10n_utils.get_locale(request)
vpn_available_in_country = vpn_available(request)
active_locales_for_this_article = ContentfulEntry.objects.get_active_locales_for_slug(
classification=CONTENT_CLASSIFICATION_VPN,
content_type=CONTENT_TYPE_PAGE_RESOURCE_CENTER,
slug=slug,
)
if not active_locales_for_this_article:
# ie, this article just isn't available in any locale
raise Http404()
if requested_locale not in active_locales_for_this_article:
# Calling render() early will redirect the user to the most
# appropriate default/alternative locale for their browser
return l10n_utils.redirect_to_best_locale(
request,
translations=active_locales_for_this_article,
)
ctx = {}
try:
article = ContentfulEntry.objects.get_entry_by_slug(
slug=slug,
locale=requested_locale,
classification=CONTENT_CLASSIFICATION_VPN,
content_type=CONTENT_TYPE_PAGE_RESOURCE_CENTER,
)
ctx.update(article.data)
except ContentfulEntry.DoesNotExist as ex:
# We shouldn't get this far, given active_locales_for_this_article,
# should only show up viable locales etc, so log it loudly before 404ing.
capture_exception(ex)
raise Http404()
ctx.update(
{
"active_locales": active_locales_for_this_article,
"vpn_available": vpn_available_in_country,
"related_articles": [x.data for x in article.get_related_entries()],
}
)
return l10n_utils.render(
request,
template_name,
ctx,
ftl_files=[
"products/vpn/resource-center",
"products/vpn/shared",
],
)