~devcamcar/django-nova/projectlist_tags

« back to all changes in this revision

Viewing changes to src/django_nova/templatetags/sidebar_tags.py

  • Committer: Devin Carlen
  • Date: 2011-01-17 05:57:20 UTC
  • mfrom: (4.1.2 pagetype_templatetag)
  • Revision ID: devin.carlen@gmail.com-20110117055720-r04fvwzzkccdvbvz
MergedĀ lp:~devcamcar/django-nova/pagetype_templatetag

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2010 United States Government as represented by the
 
4
# Administrator of the National Aeronautics and Space Administration.
 
5
# All Rights Reserved.
 
6
#
 
7
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
8
#    not use this file except in compliance with the License. You may obtain
 
9
#    a copy of the License at
 
10
#
 
11
#         http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
#    Unless required by applicable law or agreed to in writing, software
 
14
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
16
#    License for the specific language governing permissions and limitations
 
17
#    under the License.
 
18
 
 
19
"""
 
20
Template tags for rendering the sidebar.
 
21
"""
 
22
 
 
23
from django import template
 
24
 
 
25
 
 
26
register = template.Library()
 
27
 
 
28
 
 
29
class SidebarSelectNode(template.Node):
 
30
    def __init__(self, selected):
 
31
        self.selected = selected
 
32
 
 
33
    def render(self, context):
 
34
        # Store page type in template context.
 
35
        context['sidebar_selected'] = self.selected
 
36
        return ''
 
37
 
 
38
 
 
39
@register.tag
 
40
def sidebar_select(parser, token):
 
41
    try:
 
42
        tag_name, selected = token.split_contents()
 
43
    except ValueError:
 
44
        raise template.TemplateSyntaxError, "%r tag requires exactly one argument" % token.contents.split()[0]
 
45
    return SidebarSelectNode(str(selected))
 
46