Repository: mozilla/kitsune

Issue:
Add download button for non-Firefox browsers on home page
It appears the header Firefox download button (that only shows in non-Firefox browsers) is not appearing on the home page. It should!

From this comment: https://github.com/mozilla/kitsune/issues/3269#issuecomment-407227694


Discussion:
@madasan Can you help confirm the desired download button visible behavior across the site?

It appears the current rules apply on the live website:

Show Firefox download button in header on all pages EXCEPT:
 1. If the visitor is signed-in, do not show
 2. If the current page is the Firefox product page, do not show (as there is already a larger download button on that page)
3. If the visitor is already using Firefox (on any page)

I would propose the following for the redesign we drop the 2. exception, as the newly styled header download button is already quite large.

I think the header download button could replace the in-page download button on the Firefox product page. This screenshot shows both. I would propose we keep the top left button, but remove the 2nd button (right aligned, above the Help Topics heading):

![image](https://user-images.githubusercontent.com/58062/43524337-680c0f82-9575-11e8-8ff8-09117aa48b13.png)

@Dinodog @madasan and I spoke about this on the phone. The conclusion is that we'll show the header download button on ALL pages, including the home page.
Additional detail in [this comment](https://github.com/mozilla/kitsune/pull/3312#issuecomment-421388773)
To get the final requirements in this issue, copy/pasting from the [original comment](https://github.com/mozilla/kitsune/pull/3312#issuecomment-421388773):

> Show Firefox download button in header on all pages EXCEPT:
>
> - If the visitor is already using Firefox (on any page)
> - If the current page is the Firefox product page, do not show (as there is already a larger download button on that page). This includes all category and article pages under the Firefox product, that should all have the larger download button in the body of the page.

The [current logic](https://github.com/mozilla/kitsune/blob/master/kitsune/sumo/jinja2/base.html#L180) also includes a check for `user.is_authenticated()`, which, if true, will ensure the download button is _not_ shown.

@madasan Please confirm that user authentication status should be disregarded going forward.

Thanks!

Resolving patch:
diff --git a/kitsune/products/views.py b/kitsune/products/views.py
--- a/kitsune/products/views.py
+++ b/kitsune/products/views.py
@@ -7,7 +7,6 @@
 from product_details import product_details
 
 from kitsune.products.models import Product, Topic
-from kitsune.sumo.utils import get_browser
 from kitsune.wiki.decorators import check_simple_wiki_locale
 from kitsune.wiki.facets import topics_for, documents_for
 
@@ -44,19 +43,12 @@ def product_landing(request, template, slug):
         else:
             latest_version = 0
 
-    user_agent = request.META.get('HTTP_USER_AGENT', '')
-    browser = get_browser(user_agent)
-
-    # Only show firefox download button when product is firefox and browser is not Firefox
-    show_fx_download = (product.slug == 'firefox' and browser != 'Firefox')
-
     return render(request, template, {
         'product': product,
         'products': Product.objects.filter(visible=True),
         'topics': topics_for(product=product, parent=None),
         'search_params': {'product': slug},
         'latest_version': latest_version,
-        'show_fx_download': show_fx_download
     })
 
 
@@ -81,12 +73,6 @@ def document_listing(request, template, product_slug, topic_slug,
 
     documents, fallback_documents = documents_for(**doc_kw)
 
-    user_agent = request.META.get('HTTP_USER_AGENT', '')
-    browser = get_browser(user_agent)
-
-    # Only show firefox download button when product is firefox and browser is not Firefox
-    show_fx_download = (product.slug == 'firefox' and browser != 'Firefox')
-
     return render(request, template, {
         'product': product,
         'topic': topic,
@@ -96,5 +82,4 @@ def document_listing(request, template, product_slug, topic_slug,
         'documents': documents,
         'fallback_documents': fallback_documents,
         'search_params': {'product': product_slug},
-        'show_fx_download': show_fx_download
     })
diff --git a/kitsune/sumo/templatetags/jinja_helpers.py b/kitsune/sumo/templatetags/jinja_helpers.py
--- a/kitsune/sumo/templatetags/jinja_helpers.py
+++ b/kitsune/sumo/templatetags/jinja_helpers.py
@@ -507,3 +507,29 @@ def image_for_product(product_slug):
     except Product.DoesNotExist:
         return os.path.join(settings.STATIC_URL, 'products', 'img', 'product_placeholder.png')
     return obj.image_url
+
+
+@jinja2.contextfunction
+@library.global_function
+def show_header_fx_download(context):
+    """
+    Decides whether or not to render the Firefox download button in the header based on the
+    current product being displayed.
+
+    If a visitor is on a Firefox product page of any sort - help topics, KB article, etc -
+    the header download button should be hidden, because these Firefox product pages all
+    display a big download button in page. (We don't want to put multiple download buttons
+    on the page.)
+
+    This function is used in conjunction with show-fx-download.js. This function simply adds
+    markup to the template wrapped in a 'hidden' class. The JS removes the 'hidden' class if
+    the visitor is *NOT* already using Firefox.
+    """
+    product = context.get('product', None)
+
+    # product is *usually* an instance of Product, but sometimes (during AAQ process) product
+    # is a dict (see questions/config.py).
+    if product and hasattr(product, 'slug'):
+        return product.slug != 'firefox'
+    else:
+        return True
diff --git a/kitsune/wiki/views.py b/kitsune/wiki/views.py
--- a/kitsune/wiki/views.py
+++ b/kitsune/wiki/views.py
@@ -31,7 +31,7 @@
 from kitsune.sumo.templatetags.jinja_helpers import urlparams
 from kitsune.sumo.redis_utils import redis_client, RedisError
 from kitsune.sumo.urlresolvers import reverse
-from kitsune.sumo.utils import paginate, smart_int, get_next_url, truncated_json_dumps, get_browser
+from kitsune.sumo.utils import paginate, smart_int, get_next_url, truncated_json_dumps
 from kitsune.wiki.config import (
     CATEGORIES, MAJOR_SIGNIFICANCE, TEMPLATES_CATEGORY, DOCUMENTS_PER_PAGE,
     COLLAPSIBLE_DOCUMENTS, FALLBACK_LOCALES)
@@ -218,10 +218,6 @@ def document(request, document_slug, template=None, document=None):
     # The list above was built backwards, so flip this.
     breadcrumbs.reverse()
 
-    user_agent = request.META.get('HTTP_USER_AGENT', '')
-    browser = get_browser(user_agent)
-    show_fx_download = (product.slug == 'firefox' and browser != 'Firefox')
-
     data = {
         'document': doc,
         'redirected_from': redirected_from,
@@ -235,7 +231,6 @@ def document(request, document_slug, template=None, document=None):
         'breadcrumb_items': breadcrumbs,
         'document_css_class': document_css_class,
         'any_localizable_revision': any_localizable_revision,
-        'show_fx_download': show_fx_download,
         'full_locale_name': full_locale_name
     }
 


Test patch: