Commits

boralyl committed afc7ccf

Added a website app with a templatetag responsible for highlighting the nav based on the page you are on. Also added a History page.

  • Participants
  • Parent commits a18c9c5

Comments (0)

Files changed (8)

apps/website/__init__.py

Empty file added.

apps/website/models.py

+from django.db import models
+
+# Create your models here.

apps/website/templatetags/__init__.py

Empty file added.

apps/website/templatetags/website_tags.py

+import re
+
+from django import template
+
+
+register = template.Library()
+
+
+@register.simple_tag
+def nav_active(request, pattern, class_name):
+    pattern = "^%s$" % (pattern, )
+    if re.search(pattern, request.path):
+        return class_name
+    return ''

apps/website/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)

apps/website/views.py

+# Create your views here.
     os.path.join(DIRNAME, 'templates')
 )
 
+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.contrib.messages.context_processors.messages',
+    'django.core.context_processors.request',
+)
+
 INSTALLED_APPS = (
     #django apps
     'django.contrib.admin',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     # internal apps
+    'website',
     'vehiclemaintenance',
     # 3rd party
     'south',

templates/base.html

+{% load website_tags %}
 <!DOCTYPE html>
 <html lang="en">
 <head>
 			<span class="icon-bar"></span>
 		</a>
 		<a class="brand" href="/">Vehicle Maintenance</a>
+		{% url vm-index as home %}
+		{% url vm-outstanding-items as outstanding %}
+		{% url vm-history as history %}
 		<div class="nav-collapse">
 			<ul class="nav">
-			<li class="active"><a href="/">Home</a></li>
-			<li><a href="{% url outstanding-maintenance-items %}">Outstanding</a></li>
-			<li><a href="">History</a></li>
+			<li class="{% nav_active request home 'active' %}"><a href="{{ home }}">Home</a></li>
+			<li class="{% nav_active request outstanding 'active' %}"><a href="{{ outstanding }}">Outstanding</a></li>
+			<li class="{% nav_active request history 'active' %}"><a href="{{ history }}">History</a></li>
 			</ul>
 		</div><!--/.nav-collapse -->
 		</div>