airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-django-portal] 01/03: AIRAVATA-2698 Django app switchers added to header
Date Tue, 27 Feb 2018 17:08:01 GMT
This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit 771677f65abf8e4f2f9384d367821745281e331b
Author: Marcus Christie <machrist@iu.edu>
AuthorDate: Tue Feb 27 09:58:39 2018 -0500

    AIRAVATA-2698 Django app switchers added to header
---
 django_airavata/app_config.py          | 26 ++++++++++++++++++++++++++
 django_airavata/apps/groups/apps.py    |  8 ++++++--
 django_airavata/apps/workspace/apps.py |  8 ++++++--
 django_airavata/context_processors.py  | 19 +++++++++++++++++++
 django_airavata/settings.py            |  2 ++
 django_airavata/templates/base.html    | 33 ++++++++++++++++++++++++++++-----
 6 files changed, 87 insertions(+), 9 deletions(-)

diff --git a/django_airavata/app_config.py b/django_airavata/app_config.py
new file mode 100644
index 0000000..540c29e
--- /dev/null
+++ b/django_airavata/app_config.py
@@ -0,0 +1,26 @@
+
+from abc import ABC, abstractmethod
+
+from django.apps import AppConfig
+
+
+class AiravataAppConfig(AppConfig, ABC):
+    """Custom AppConfig for Django Airavata apps."""
+
+    @property
+    @abstractmethod
+    def url_app_name(self):
+        """Return the urls application namespace (typically, same as label)."""
+        pass
+
+    @property
+    @abstractmethod
+    def app_order(self):
+        """Return positive int order of app in listings, lowest sorts first."""
+        pass
+
+    @property
+    @abstractmethod
+    def url_home(self):
+        """Named route of home page for this application."""
+        pass
diff --git a/django_airavata/apps/groups/apps.py b/django_airavata/apps/groups/apps.py
index f5a0e34..30cd9f7 100755
--- a/django_airavata/apps/groups/apps.py
+++ b/django_airavata/apps/groups/apps.py
@@ -1,6 +1,10 @@
-from django.apps import AppConfig
+from django_airavata.app_config import AiravataAppConfig
 
 
-class GroupsConfig(AppConfig):
+class GroupsConfig(AiravataAppConfig):
     name = 'django_airavata.apps.groups'
     label = 'django_airavata_groups'
+    verbose_name = 'Groups'
+    url_app_name = label
+    app_order = 10
+    url_home = url_app_name + ':manage'
diff --git a/django_airavata/apps/workspace/apps.py b/django_airavata/apps/workspace/apps.py
index ffa1ad0..79c4a20 100644
--- a/django_airavata/apps/workspace/apps.py
+++ b/django_airavata/apps/workspace/apps.py
@@ -1,6 +1,10 @@
-from django.apps import AppConfig
+from django_airavata.app_config import AiravataAppConfig
 
 
-class WorkspaceConfig(AppConfig):
+class WorkspaceConfig(AiravataAppConfig):
     name = 'django_airavata.apps.workspace'
     label = 'django_airavata_workspace'
+    verbose_name = 'Workspace'
+    url_app_name = label
+    app_order = 0
+    url_home = 'django_airavata_workspace:dashboard'
diff --git a/django_airavata/context_processors.py b/django_airavata/context_processors.py
new file mode 100644
index 0000000..8bd45ef
--- /dev/null
+++ b/django_airavata/context_processors.py
@@ -0,0 +1,19 @@
+from django.apps import apps
+
+from django_airavata.app_config import AiravataAppConfig
+
+
+def airavata_app_registry(request):
+    """Put airavata django apps into the context."""
+    airavata_apps = [app for app in apps.get_app_configs()
+                     if isinstance(app, AiravataAppConfig)]
+    # Sort by app_order then by verbose_name (case-insensitive)
+    airavata_apps.sort(
+        key=lambda app: "{:09}-{}".format(app.app_order,
+                                          app.verbose_name.lower()))
+    return {'airavata_apps': airavata_apps}
+
+
+def resolver_match(request):
+    """Put resolver_match (ResolverMatch instance) into the context."""
+    return {'resolver_match': request.resolver_match}
diff --git a/django_airavata/settings.py b/django_airavata/settings.py
index fa5ccd9..14a20ab 100644
--- a/django_airavata/settings.py
+++ b/django_airavata/settings.py
@@ -72,6 +72,8 @@ TEMPLATES = [
                 'django.template.context_processors.request',
                 'django.contrib.auth.context_processors.auth',
                 'django.contrib.messages.context_processors.messages',
+                'django_airavata.context_processors.airavata_app_registry',
+                'django_airavata.context_processors.resolver_match',
             ],
         },
     },
diff --git a/django_airavata/templates/base.html b/django_airavata/templates/base.html
index 7a0dd01..afba8ad 100644
--- a/django_airavata/templates/base.html
+++ b/django_airavata/templates/base.html
@@ -35,14 +35,37 @@
     <div class=c-header__title><a href="{% url 'home' %}">{% block title %}Django
Airavata Gateway{% endblock %}</a></div>
     {% if user.is_authenticated %}
         <div class=c-header__controls>
-            <div class=dropdown><a href=#0 class="dropdown-toggle text-dark" id=dropdownMenuButton
data-toggle=dropdown
-                                   aria-haspopup=true aria-expanded=false><i
+            <div class="btn-group">
+                <div class=dropdown>
+                    <a href=#0 class="dropdown-toggle text-dark" id=appDropdownMenuButton
data-toggle=dropdown
+                            aria-haspopup=true aria-expanded=false>
+                        {% for app in airavata_apps %}
+                            {% if app.url_app_name == resolver_match.app_name %}
+                                {{ app.verbose_name }}
+                            {% endif %}
+                        {% endfor %}
+                    </a>
+                <div class=dropdown-menu aria-labelledby=appDropdownMenuButton>
+                        {% for app in airavata_apps %}
+                            {% if app.url_app_name == resolver_match.app_name %}
+                                <a class="dropdown-item active" href="{% url app.url_home
%}">{{ app.verbose_name }}</a>
+                            {% else %}
+                                <a class="dropdown-item" href="{% url app.url_home %}">{{
app.verbose_name }}</a>
+                            {% endif %}
+                        {% endfor %}
+                </div>
+                </div>
+            </div>
+            <div class="btn-group ml-3">
+                <div class=dropdown><a href=#0 class="dropdown-toggle text-dark"
id=dropdownMenuButton data-toggle=dropdown
+                    aria-haspopup=true aria-expanded=false><i
                     class="fa fa-user mr-2"></i> {{ request.session.USERINFO.given_name
}} {{ request.session.USERINFO.family_name }}
-            </a>
+                </a>
                 <div class=dropdown-menu aria-labelledby=dropdownMenuButton><a class=dropdown-item
href=#>User
                     settings</a> <a
-                        class=dropdown-item href="{% url 'django_airavata_auth:logout' %}">Logout
<i
-                        class="fa fa-sign-out"></i></a></div>
+                    class=dropdown-item href="{% url 'django_airavata_auth:logout' %}">Logout
<i
+                    class="fa fa-sign-out"></i></a></div>
+                </div>
             </div>
         </div>
     {% endif %}

-- 
To stop receiving notification emails like this one, please contact
machristie@apache.org.

Mime
View raw message