[PATCH] [frontend] Add optional fedmenu resources to every page.

Ralph Bean rbean at redhat.com
Wed Apr 22 14:51:21 UTC 2015


This is for https://fedoraproject.org/wiki/Fedora_Engineering/FY16_Plan

If the FEDMENU_URL and FEDMENU_DATA_URL options are left out of the
config, then nothing should change on the displayed page.  If they are
included, then they will be pulled in at page load time to render little
menu buttons on the bottom right hand corner of the page.

There's an example up at http://threebean.org/fedmenu/

It will be a while until we are able to turn this on globally across all
our apps.
---
 frontend/coprs_frontend/config/copr.conf            |  4 ++++
 frontend/coprs_frontend/coprs/__init__.py           |  2 +-
 frontend/coprs_frontend/coprs/context_processors.py | 11 +++++++++++
 frontend/coprs_frontend/coprs/templates/layout.html | 16 ++++++++++++++++
 4 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/frontend/coprs_frontend/config/copr.conf b/frontend/coprs_frontend/config/copr.conf
index ab4fb96..064baa4 100644
--- a/frontend/coprs_frontend/config/copr.conf
+++ b/frontend/coprs_frontend/config/copr.conf
@@ -45,6 +45,10 @@ SEND_EMAILS = True
 ## post-process url leading to frontend
 # ENFORCE_PROTOCOL_FOR_FRONTEND_URL = "https"
 
+# URLs for fedmenu resources
+#FEDMENU_URL = "http://threebean.org/fedmenu/"
+#FEDMENU_DATA_URL = "http://threebean.org/fedmenu/dev-data.js"
+
 # Kerberos authentication configuration.  Example configuration abbreviated
 # like 'RH' (should not changed once used, reflects what is stored in database).
 # This requires mod_auth_kerb package (Fedora/RHEL) installed on your frontend
diff --git a/frontend/coprs_frontend/coprs/__init__.py b/frontend/coprs_frontend/coprs/__init__.py
index e86bb64..032ed4d 100644
--- a/frontend/coprs_frontend/coprs/__init__.py
+++ b/frontend/coprs_frontend/coprs/__init__.py
@@ -52,7 +52,7 @@ from coprs.views import recent_ns
 from coprs.views.recent_ns import recent_general
 from coprs.views.stats_ns import stats_receiver
 
-from .context_processors import include_banner
+from .context_processors import include_banner, inject_fedmenu
 
 setup_log()
 
diff --git a/frontend/coprs_frontend/coprs/context_processors.py b/frontend/coprs_frontend/coprs/context_processors.py
index b84c241..895bb03 100644
--- a/frontend/coprs_frontend/coprs/context_processors.py
+++ b/frontend/coprs_frontend/coprs/context_processors.py
@@ -10,3 +10,14 @@ def include_banner():
         return {"copr_banner": open(BANNER_LOCATION).read()}
     else:
         return {}
+
+
+ at app.context_processor
+def inject_fedmenu():
+    """ Inject fedmenu url if available. """
+    if 'FEDMENU_URL' in app.config:
+        return dict(
+            fedmenu_url=app.config['FEDMENU_URL'],
+            fedmenu_data_url=app.config['FEDMENU_DATA_URL'],
+        )
+    return dict()
diff --git a/frontend/coprs_frontend/coprs/templates/layout.html b/frontend/coprs_frontend/coprs/templates/layout.html
index bef3fbf..f9981e9 100644
--- a/frontend/coprs_frontend/coprs/templates/layout.html
+++ b/frontend/coprs_frontend/coprs/templates/layout.html
@@ -58,5 +58,21 @@
   </small>
 </p>
 </div>
+
+{% if fedmenu_url is defined %}
+<script src="{{fedmenu_url}}/js/fedora-libravatar.js"></script>
+<script src="{{fedmenu_url}}/js/fedmenu.js"></script>
+<script>
+  fedmenu({
+      'url': '{{fedmenu_data_url}}',
+      'mimeType': 'application/javascript',
+      'position': 'bottom-right',
+      {% if copr is defined %}
+      'user': '{{copr.owner.name}}',
+      {% endif %}
+  });
+</script>
+{% endif %}
+
 </body>
 </html>
-- 
2.1.0



More information about the copr-devel mailing list