Browse Source

Make use of django-activelink in order to highlight menu item on active links

Fabs 11 years ago
parent
commit
f65c704f52
4 changed files with 24 additions and 9 deletions
  1. 4 1
      coin/members/views.py
  2. 11 0
      coin/settings.py
  3. 8 8
      coin/templates/base.html
  4. 1 0
      requirements.txt

+ 4 - 1
coin/members/views.py

@@ -1,5 +1,7 @@
 #import pprint
 from django.http import HttpResponse
+from django.template import RequestContext
+
 # from django.template import Context, loader
 from django.shortcuts import render, render_to_response, get_object_or_404
 from django.contrib.auth.decorators import login_required
@@ -14,7 +16,8 @@ def index(request):
 @login_required
 def infos(request):
     member = request.user.member
-    return render_to_response('members/infos.html', {'member':member})
+    return render_to_response('members/infos.html', {'member':member},
+                              context_instance=RequestContext(request))
 
 @login_required
 def abos(request):

+ 11 - 0
coin/settings.py

@@ -151,6 +151,7 @@ INSTALLED_APPS = (
     'south',
     'ldapdb',  # LDAP as database backend
     'autocomplete_light', #Automagic autocomplete foreingkey form component
+    'activelink', #Detect if a link match actual page
     'coin',
     'coin.members',
     'coin.offers',
@@ -189,6 +190,16 @@ LOGGING = {
     }
 }
 
+TEMPLATE_CONTEXT_PROCESSORS = (
+    "django.contrib.auth.context_processors.auth",
+    "django.core.context_processors.debug",
+    "django.core.context_processors.i18n",
+    "django.core.context_processors.media",
+    "django.core.context_processors.static",
+    "django.core.context_processors.tz",
+    "django.core.context_processors.request",
+    "django.contrib.messages.context_processors.messages")
+
 AUTHENTICATION_BACKENDS = (
     'django_auth_ldap.backend.LDAPBackend',
     'django.contrib.auth.backends.ModelBackend',

+ 8 - 8
coin/templates/base.html

@@ -1,5 +1,6 @@
 <!doctype html>
 {% load staticfiles %}
+{% load activelink %}
 <html class="no-js" lang="en">
   <head>
     <meta charset="utf-8" />
@@ -24,16 +25,15 @@
 
    <div class="row">
    <div class="large-3 columns">
-    {% block sidenav %} 
+    {% block sidenav %}
     <nav id="sidebox" class="hide-for-small">
      <h3 id="nav">Navigation</h3>
-     ::{{ request.path_info }}
      <ul class="side-nav">
-         <li {% if request.path_info == "home" %}class="active"{% endif %}><a href="{% url 'home' %}">Tableau de bord</a></li>
-         <li {% if request.path_info == "members/info" %}class="active"{% endif %}><a href="{% url 'members:infos' %}">Mes informations personnelles</a></li>
-         <li {% if request.get_full_path == "/members/abo/" %}class="active"{% endif %}><a href="/members/abo/">Mes abonnements</a></li>
-         <li {% if request.get_full_path == "/members/contact/" %}class="active"{% endif %}><a href="/members/contact/">Contact / Support</a></li>
-         <li {% if request.get_full_path == "/members/logout/" %}class="active"{% endif %}><a href="{% url 'members:logout' %}">Déconnexion</a></li>
+         <li class="{% ifactive 'home' %}active{% endifactive %}"><a href="{% url 'home' %}">Tableau de bord</a></li>
+         <li class="{% ifactive 'members:infos' %}active{% endifactive %}"><a href="{% url 'members:infos' %}">Mes informations personnelles</a></li>
+         <li class="{% ifactive '' %}active{% endifactive %}"><a href="/members/abo/">Mes abonnements</a></li>
+         <li class="{% ifactive '' %}active{% endifactive %}"><a href="/members/contact/">Contact / Support</a></li>
+         <li class="{% ifactive '' %}active{% endifactive %}"><a href="{% url 'members:logout' %}">Déconnexion</a></li>
      </ul>
      </nav>
      {% endblock %}
@@ -44,7 +44,7 @@
     {% block content %}{% endblock %}
     </div>
 
-    <aside class="left-off-canvas-menu"> 
+    <aside class="left-off-canvas-menu">
         <ul class="off-canvas-list">
             <li><label>Navigation</label></li>
             <li><a href="#">Tableau de bord</a></li>

+ 1 - 0
requirements.txt

@@ -7,5 +7,6 @@ wsgiref==0.1.2
 python-dateutil==2.2
 django-autocomplete-light==2.0.0a8
 reportlab==2.5
+django-activelink==0.4
 -e git+https://github.com/jmacul2/django-postgresql-netfields@2d6e597c3d65ba8b0e1f6e3183869216e990e915#egg=django-netfields
 -e git+https://github.com/chrisglass/xhtml2pdf@a5d37ffd0ccb0603bdf668198de0f21766816104#egg=xhtml2pdf-master