Ticket #105: show-hide-toggle.diff
File show-hide-toggle.diff, 7.7 KB (added by , 19 years ago) |
---|
-
django/tests/template_tests.py
259 259 expected = '<h1>Default \\ slash</h1>' 260 260 self.assertEqual(expected, t.render(c)) 261 261 262 def testDefaultFilter4(self):263 "Use the default argument when a variable passed through the 'default' filter doesn't exist (single backslash)"264 t = '<h1>{{ nonvar|default:"Default \\ slash" }}</h1>'265 self.assertRaises(template.TemplateSyntaxError, template.Template, t)266 267 262 def testIllegalCharacterInFilterName(self): 268 263 "Raise TemplateSyntaxError when trying to access a filter containing an illegal character" 269 264 t = '<h1>{{ blah|(lower) }}</h1>' … … 516 511 def testNormalUsage(self): 517 512 "A cycle tag should work as expected" 518 513 c = template.Context({'set':range(10)}) 519 t = template.Template('{% for i in set %}{% cycle red, 514 t = template.Template('{% for i in set %}{% cycle red,green %}-{{ i }} {% endfor %}') 520 515 expected = 'red-0 green-1 red-2 green-3 red-4 green-5 red-6 green-7 red-8 green-9 ' 521 516 self.assertEqual(expected, t.render(c)) 522 517 … … 525 520 t = '{% cycle %}' 526 521 self.assertRaises(template.TemplateSyntaxError, template.Template, t) 527 522 528 def testOneArgument(self): 529 "Raise TemplateSyntaxError in cycle tags with only one argument" 530 t = '{% cycle hello %}' 531 self.assertRaises(template.TemplateSyntaxError, template.Template, t) 523 def testNamedGroup(self): 524 "cycle tags with named groups should work as expected" 525 t = template.Template('{% cycle red,blue as colours %}{% cycle colours %}{% cycle colours %}') 526 c = template.Context() 527 self.assertEqual('redbluered', t.render(c)) 532 528 533 def testExtraInitialSpaces(self):534 "Extra spaces around cycle tags and their arguments should be ignored"535 c = template.Context({'set':range(5)})536 t = template.Template('{% for i in set %}{% cycle red, green %}{% endfor %}')537 expected = 'redgreenredgreenred'538 self.assertEqual(expected, t.render(c))539 540 529 class TemplateTagNodeCheck(unittest.TestCase): 541 530 542 531 def testNormalUsage(self): -
django/conf/admin_media/css/global.css
228 228 /* COLLAPSED FIELDSETS */ 229 229 230 230 fieldset.collapsed * { display:none; } 231 fieldset.collapsed h2, fieldset.collapsed .collapse-toggle { display:block !important; } 231 fieldset.collapsed h2, fieldset.collapsed { display:block !important; } 232 fieldset.collapsed .collapse-toggle { display: inline !important; } 232 233 fieldset.collapsed h2 { background-image:url(../img/admin/nav-bg.gif); background-position:bottom left; color:#999; } 233 fieldset.collapsed .collapse-toggle { padding:3px 5px !important; background:#efefef; }234 fieldset.collapsed .collapse-toggle a { display:inline !important; }235 234 236 235 /* MESSAGES & ERRORS */ 237 236 -
django/conf/admin_media/js/admin/CollapsedFieldsets.js
1 1 // Finds all fieldsets with class="collapse", collapses them, and gives each 2 // one a "Show foo" link that uncollapses it. 2 // one a "Show" link that uncollapses it. The "Show" link becomes a "Hide" 3 // link when the fieldset is visible. 3 4 4 5 function findForm(node) { 5 6 // returns the node of the form containing the given node … … 16 17 init: function() { 17 18 var fieldsets = document.getElementsByTagName('fieldset'); 18 19 var collapsed_seen = false; 19 for (var i=0; i<fieldsets.length; i++) { 20 var fs = fieldsets[i]; 20 for (var i = 0, fs; fs = fieldsets[i]; i++) { 21 21 // Collapse this fieldset if it has the correct class, and if it 22 22 // doesn't have any errors. (Collapsing shouldn't apply in the case 23 23 // of error messages.) 24 24 if (fs.className.match(CollapsedFieldsets.collapse_re) && !CollapsedFieldsets.fieldset_has_errors(fs)) { 25 26 25 collapsed_seen = true; 27 28 26 // Give it an additional class, used by CSS to hide it. 29 27 fs.className += ' ' + CollapsedFieldsets.collapsed_class; 30 31 // Get plural verbose name of object. 32 var verbose_name = fs.getElementsByTagName('h2')[0].innerHTML; 33 34 // <div class="form-row collapse-toggle" id="fieldsetcollapser1"> 35 // <a href="javascript:toggleDisplay;">Show section priorities…</a> 36 // </div> 37 var div = document.createElement('div'); 38 39 // Give it a hook so we can remove it later. 40 div.id = 'fieldsetcollapser' + i; 41 42 div.className = 'form-row collapse-toggle'; // CSS hook 28 // (<a id="fieldsetcollapser3" class="collapse-toggle" href="#">Show</a>) 43 29 var collapse_link = document.createElement('a'); 44 collapse_link.setAttribute('href', 'javascript:CollapsedFieldsets.display(' + i + ');'); 45 collapse_link.appendChild(document.createTextNode('Show ' + verbose_name)); 46 div.appendChild(collapse_link); 47 fs.appendChild(div); 30 collapse_link.className = 'collapse-toggle'; 31 collapse_link.id = 'fieldsetcollapser' + i; 32 collapse_link.onclick = new Function('CollapsedFieldsets.show('+i+'); return false;'); 33 collapse_link.href = '#'; 34 collapse_link.innerHTML = 'Show'; 35 var h2 = fs.getElementsByTagName('h2')[0]; 36 h2.appendChild(document.createTextNode(' (')); 37 h2.appendChild(collapse_link); 38 h2.appendChild(document.createTextNode(')')); 48 39 } 49 40 } 50 41 if (collapsed_seen) { … … 62 53 } 63 54 return false; 64 55 }, 65 display: function(fieldset_index) {56 show: function(fieldset_index) { 66 57 var fs = document.getElementsByTagName('fieldset')[fieldset_index]; 67 58 // Remove the class name that causes the "display: none". 68 59 fs.className = fs.className.replace(CollapsedFieldsets.collapsed_re, ''); 69 // Remove the "Show foo" link. 70 fs.removeChild(document.getElementById('fieldsetcollapser' + fieldset_index)); 60 // Toggle the "Show" link to a "Hide" link 61 var collapse_link = document.getElementById('fieldsetcollapser' + fieldset_index); 62 collapse_link.onclick = new Function('CollapsedFieldsets.hide('+fieldset_index+'); return false;'); 63 collapse_link.innerHTML = 'Hide'; 71 64 }, 65 hide: function(fieldset_index) { 66 var fs = document.getElementsByTagName('fieldset')[fieldset_index]; 67 // Add the class name that causes the "display: none". 68 fs.className += ' ' + CollapsedFieldsets.collapsed_class; 69 // Toggle the "Hide" link to a "Show" link 70 var collapse_link = document.getElementById('fieldsetcollapser' + fieldset_index); 71 collapse_link.onclick = new Function('CollapsedFieldsets.show('+fieldset_index+'); return false;'); 72 collapse_link.innerHTML = 'Show'; 73 }, 74 72 75 uncollapse_all: function() { 73 76 var fieldsets = document.getElementsByTagName('fieldset'); 74 77 for (var i=0; i<fieldsets.length; i++) { 75 78 if (fieldsets[i].className.match(CollapsedFieldsets.collapsed_re)) { 76 CollapsedFieldsets. display(i);79 CollapsedFieldsets.show(i); 77 80 } 78 81 } 79 82 } -
django/core/template.py
459 459 class VariableNode(Node): 460 460 def __init__(self, var_string): 461 461 self.var_string = var_string 462 # Compile time check of validity of var_string 463 get_filters_from_token(var_string) 462 464 463 465 def __repr__(self): 464 466 return "<Variable Node: %s>" % self.var_string