Changeset - b38bff5ff039
[Not reviewed]
default
0 3 5
Branko Majic (branko) - 11 years ago 2013-02-26 20:44:56
branko@majic.rs
Created the initial skeleton for templates. Added some custom template tags. Created first dummy index view. Configured the test project to use the django.core.context_processors.request template context processor (needed for active links detection).
8 files changed with 128 insertions and 2 deletions:
0 comments (0 inline, 0 general)
conntrackt/templates/conntrackt/index.html
Show inline comments
 
new file 100644
 
{% extends "conntrackt/template.html" %}
 

	
 
{% block content %}
 
<h1>Welcome to Conntrackt</h1>
 
{% endblock %}
 

	
conntrackt/templates/conntrackt/link.html
Show inline comments
 
new file 100644
 
{% load url from future %}
 

	
 
{% if identifier %}
 
<a href="{% url view identifier %}" {% if html_class %}class="{{html_class}}"{% endif %}>{{title}}</a>
 
{% else %}
 
<a href="{% url view %}" {% if html_class %}class="{{html_class}}"{% endif %}>{{title}}</a>
 
{% endif %}
conntrackt/templates/conntrackt/template.html
Show inline comments
 
new file 100644
 
{% load conntrackt %}
 

	
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
  <head>
 
    <title>{% block title %}Conntrackt{% endblock %}</title>
 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
    <link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap.css" />
 
    <style>
 
    body {
 
      padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
 
    }
 
    </style>
 
    <link href="/static/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
 
    <link href="/static/custom.css" rel="stylesheet">
 
  </head>
 
  <body>
 

	
 
    <div class="navbar navbar-inverse navbar-fixed-top">
 
      <div class="navbar-inner">
 
        <div class="container">
 
          <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
 
            <span class="icon-bar"></span>
 
            <span class="icon-bar"></span>
 
            <span class="icon-bar"></span>
 
            <span class="icon-bar"></span>
 
          </button>
 
          {% block header_title %}{% html_link 'index' 'Conntrackt' "" "brand" %}{% endblock %}
 
          <div class="nav-collapse collapse">
 
              {% block header %}
 
            <ul class="nav">
 
              <li class="{% active_link 'index' %}"><a href="{% url index %}"><i class="icon-home icon-white"></i> Main Page</a></li>
 
            </ul>
 
              {% endblock %}
 
          </div>
 
        </div>
 
      </div>
 
    </div>
 

	
 
    <div class="container">
 
      <div id="content" class="block">
 
      {% block content %}
 
      {% endblock %}
 
      </div>
 
    </div>
 

	
 
    <script src="/static/jquery-min.js"></script>
 
    <script src="/static/bootstrap/js/bootstrap.js"></script>
 
  </body>
 
</html>
 

	
conntrackt/templatetags/__init__.py
Show inline comments
 
new file 100644
conntrackt/templatetags/conntrackt.py
Show inline comments
 
new file 100644
 
from django import template
 
from django.core import urlresolvers
 

	
 
register = template.Library()
 

	
 
@register.inclusion_tag('conntrackt/link.html')
 
def html_link(view, title, identifier = None, html_class = None):
 
    '''
 
    A small wrapper for showing HTML links.
 

	
 
    Arguments:
 

	
 
    view - View name for which the URL should be shown.
 

	
 
    title - Title which will be shown as the link.
 

	
 
    identifier - Identifier which is passed to the view for processing.
 

	
 
    html_class - Class which should be assigned to the link.
 
    '''
 

	
 
    return {'view': view, 'identifier': identifier, 'title': title, 'html_class': html_class}
 

	
 
@register.simple_tag(takes_context = True)
 
def active_link(context, url_name, return_value='active', **kwargs):
 
    matches = current_url_equals(context, url_name, **kwargs)
 
    return return_value if matches else ''
 
 
 
 
 
def current_url_equals(context, url_name, **kwargs):
 
    resolved = False
 
    try:
 
        resolved = urlresolvers.resolve(context.get('request').path)
 
    except:
 
        pass
 
    matches = resolved and resolved.url_name == url_name
 
    if matches and kwargs:
 
        for key in kwargs:
 
            kwarg = kwargs.get(key)
 
            resolved_kwarg = resolved.kwargs.get(key)
 
            if not resolved_kwarg or kwarg != resolved_kwarg:
 
                return False
 
    return matches
 

	
conntrackt/urls.py
Show inline comments
 
from django.conf.urls import patterns, include, url
 

	
 
from conntrackt.views import IndexView
 

	
 
urlpatterns = patterns(
 
    'threadedcomments_zinnia.views',
 
    url(r'^$', IndexView.as_view(), name="index"),
 
)
 

	
conntrackt/views.py
Show inline comments
 
# Create your views here.
 
from django.views.generic import TemplateView
 

	
 
class IndexView(TemplateView):
 
    """
 
    Custom view used for rendering the index page.
 
    """
 

	
 
    template_name = 'conntrackt/index.html'
 

	
projtest/projtest/settings.py
Show inline comments
 
# Django settings for projtest project.
 

	
 
DEBUG = True
 
TEMPLATE_DEBUG = DEBUG
 

	
 
@@ -108,6 +107,13 @@ TEMPLATE_DIRS = (
 
    # Don't forget to use absolute paths, not relative paths.
 
)
 

	
 
# Extend the default TEMPLATE_CONTEXT_PROCESSORS
 
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
 
TEMPLATE_CONTEXT_PROCESSORS += (
 
    "django.core.context_processors.request",
 
    )
 

	
 

	
 
INSTALLED_APPS = (
 
    'django.contrib.auth',
 
    'django.contrib.contenttypes',
0 comments (0 inline, 0 general)