Package madrona :: Package common :: Package templatetags :: Module layout_tags
[hide private]

Source Code for Module madrona.common.templatetags.layout_tags

  1  from django import template 
  2  from django.template import resolve_variable 
  3  register = template.Library() 
  4   
  5  @register.tag(name="home_link") 
 23   
24 -class HomeLinkNode(template.Node):
25 - def __init__(self, href, text):
26 self.href = href 27 self.text = text
28
29 - def render(self, context):
30 return """ 31 <a class="back_link" href="%s">%s</a> 32 """ % (self.href, self.text)
33 34 @register.tag(name="back_link") 56
57 -class BackLinkNode(template.Node):
58 - def __init__(self, title, urlvar, tab=None):
59 self.title = title 60 self.urlvar = urlvar 61 self.tab = tab
62
63 - def render(self, context):
64 url = resolve_variable(self.urlvar, context) 65 if self.tab != None: 66 url = url + '#' + self.tab 67 return """ 68 <a class="back_link" href="%s">%s</a> 69 """ % (url, self.title)
70 71 72 @register.tag(name="footer") 79
80 -class FooterNode(template.Node):
81 - def __init__(self, nodelist):
82 self.nodelist = nodelist
83
84 - def render(self, context):
85 print self.nodelist 86 output = self.nodelist.render(context) 87 return '<div class="sidebar-footer">%s</div>' % (output,)
88 89 90 @register.tag(name="panel")
91 -def do_panel(parser, token):
92 """Creates markup for a panel displayed using the panelManager widget. 93 """ 94 try: 95 # split_contents() knows not to split quoted strings. 96 tag_name, title = token.split_contents() 97 except ValueError: 98 raise template.TemplateSyntaxError, "%r tag requires a single argument. You must give your panel a title." % token.contents.split()[0] 99 100 nodelist = parser.parse(('endpanel',)) 101 parser.delete_first_token() 102 return PanelNode(nodelist, title)
103
104 -class PanelNode(template.Node):
105 - def __init__(self, nodelist, title):
106 self.nodelist = nodelist 107 self.title = title
108
109 - def render(self, context):
110 if not (self.title[0] == self.title[-1] and self.title[0] in ('"', "'")): 111 self.title = resolve_variable(self.title, context) 112 else: 113 self.title = self.title[1:-1] 114 output = self.nodelist.render(context) 115 return """<div class="sidebar-panel"> 116 <div class="sidebar-header"> 117 <h1>%s</h1> 118 </div> 119 <div class="sidebar-body"> 120 <div class="sidebar-wrapper"> 121 %s 122 </div> 123 </div> 124 </div> 125 """ % (self.title, output)
126 127 @register.tag(name="printable")
128 -def do_printable(parser, token):
129 """Use this tag to specify that the current panel should be accessible via 130 its url as a printable/static page in addition to the dynamic sidebar 131 form. 132 """ 133 return PrintableNode()
134
135 -class PrintableNode(template.Node):
136
137 - def render(self, context):
138 return """ 139 <a class="printable" href="#" target="_blank">Print View</a> 140 """
141 142 @register.tag(name="tabpanel")
143 -def do_tabpanel(parser, token):
144 """Creates markup for a panel that contains many tabs using the tab tag. 145 """ 146 try: 147 # split_contents() knows not to split quoted strings. 148 tag_name, title = token.split_contents() 149 except ValueError: 150 raise template.TemplateSyntaxError, "%r tag requires a single argument. You must give your tabpanel a title." % token.contents.split()[0] 151 nodelist = parser.parse(('endtabpanel',)) 152 parser.delete_first_token() 153 return TabPanelNode(nodelist, title)
154
155 -class TabPanelNode(template.Node):
156 - def __init__(self, nodelist, title):
157 self.nodelist = nodelist 158 self.title = title
159
160 - def render(self, context):
161 # print self.nodelist 162 if not (self.title[0] == self.title[-1] and self.title[0] in ('"', "'")): 163 self.title = resolve_variable(self.title, context) 164 else: 165 self.title = self.title[1:-1] 166 output = self.nodelist.render(context) 167 list_items = '' 168 for node in self.nodelist: 169 if node.__class__.__name__ is 'TabNode': 170 list_items += """ 171 <li><a href="#%s">%s</a></li> 172 """ % (node.tab_id, node.title) 173 return """<div class="sidebar-panel"> 174 <div class="sidebar-header"> 175 <h1>%s</h1> 176 </div> 177 <ul class="tabs"> 178 %s 179 </ul> 180 <div class="sidebar-body"> 181 <div class="sidebar-wrapper"> 182 %s 183 </div> 184 </div> 185 </div> 186 """ % (self.title, list_items, output)
187 188 @register.tag(name="tab")
189 -def do_tab(parser, token):
190 """Create a tab within a tab_panel. 191 """ 192 try: 193 # split_contents() knows not to split quoted strings. 194 tag_name, title = token.split_contents() 195 except ValueError: 196 raise template.TemplateSyntaxError, "%r tag requires a single argument. You must give your tab a title." % token.contents.split()[0] 197 198 nodelist = parser.parse(('endtab',)) 199 parser.delete_first_token() 200 return TabNode(nodelist, title)
201
202 -class TabNode(template.Node):
203 - def __init__(self, nodelist, title):
204 self.nodelist = nodelist 205 self.title = title 206 self.tab_id = title.replace("'", "").replace('"', '').replace(' ', '')
207
208 - def render(self, context):
209 if not (self.title[0] == self.title[-1] and self.title[0] in ('"', "'")): 210 self.title = resolve_variable(self.title, context) 211 else: 212 self.title = self.title[1:-1] 213 214 output = self.nodelist.render(context) 215 return """<div id="%s" class="sidebar-body"> 216 <div class="sidebar-wrapper"> 217 %s 218 </div> 219 </div> 220 """ % (self.tab_id, output)
221