--- Begin Message ---
Hi,
On Sun, 07 Feb 2016, Esa Peuha wrote:
> Here is a patch that hopefully fixes this issue. It adds two new
> template tags, "octicon" which renders any octicon with alternate
> text (which should appear as both mouseover text and text-mode-only
> text), and "toggle_chevron" which gives a downward chevron to toggle
> the display of details (this was so frequent special case that it
> seemed worth its own tag). The only testing I have done is to make
> sure that "manage.py test" didn't break.
Thanks I merged your work but I had to fix it up a little bit. It was
not working entirely as you expected it. You probably should have tried
to run it :)
Instead of the expected octicons in the "versioned links" panel, we had
a dump of the dict returned by the octicon function. Also you used
"toggle-chevron" instead of "toggle_chevron" in two places.
I also made some other changes, cf attached patch.
Cheers,
--
Raphaël Hertzog ◈ Debian Developer
Support Debian LTS: http://www.freexian.com/services/debian-lts.html
Learn to master Debian: http://debian-handbook.info/get/
commit a907a76bb3e990158e751ce9fffa4659a7d1aaf9 (HEAD -> master)
Author: Raphaël Hertzog <hertzog@debian.org>
Date: Wed Feb 10 11:18:13 2016 +0100
templates: rework slightly the new templatetags
* Do not use an intermediary template file for toggle chevron.
* Allow use of different texts for tooltip and textual rendering,
defaulting to [tooltip] for the textual rendering of the icon.
* Fix octicon function to return the expected string directly so that
it can be used outside of the templating system too (direct usage
was returing a dict despite the @register.inclusion_tag decorator).
* Replace non-existing "toggle-chevron" tags with the correct
"toggle_chevron".
diff --git a/distro_tracker/core/templates/core/edit-team-membership.html b/distro_tracker/core/templates/core/edit-team-membership.html
index 77c4fe2..06125ed 100644
--- a/distro_tracker/core/templates/core/edit-team-membership.html
+++ b/distro_tracker/core/templates/core/edit-team-membership.html
@@ -22,7 +22,8 @@
<div class="accordion-heading">
<div class="row">
<div class="col-md-10">
- <button class="btn btn-sm btn-default" data-toggle="collapse" data-parent="#{{ accordion_id }}" data-target="#{{ accordion_id }}-details-{{ forloop.counter }}">{% toggle-chevron %}</button>
+ <button class="btn btn-sm btn-default" data-toggle="collapse"
+ data-parent="#{{ accordion_id }}" data-target="#{{ accordion_id }}-details-{{ forloop.counter }}">{% toggle_chevron %}</button>
{% if pkg.get_absolute_url %}
<a href="{{ pkg.get_absolute_url }}">{{ pkg }}</a>
{% else %}
diff --git a/distro_tracker/core/templates/core/octicon.html b/distro_tracker/core/templates/core/octicon.html
index 7af8464..0ae758d 100644
--- a/distro_tracker/core/templates/core/octicon.html
+++ b/distro_tracker/core/templates/core/octicon.html
@@ -1 +1 @@
-<span class="octicon octicon-{{ name }}" title="{{ text }}"><span class="sr-only">{{ text }}</span></span>
+<span class="octicon octicon-{{ name }}" title="{{ title }}"><span class="sr-only">{{ content }}</span></span>
diff --git a/distro_tracker/core/templates/core/panels/action-needed.html b/distro_tracker/core/templates/core/panels/action-needed.html
index 9d4078c..a5bf272 100644
--- a/distro_tracker/core/templates/core/panels/action-needed.html
+++ b/distro_tracker/core/templates/core/panels/action-needed.html
@@ -11,7 +11,7 @@
data-parent="#action-needed-list"
data-target="#action-needed-details-{{ forloop.counter }}"
class="chevron">
- {% toggle-chevron %}
+ {% toggle_chevron %}
</span>
{# The short description is allowed to contain some HTML markup #}
{{ item.short_description|safe }}
diff --git a/distro_tracker/core/templates/core/toggle-chevron.html b/distro_tracker/core/templates/core/toggle-chevron.html
deleted file mode 100644
index 9ec7def..0000000
--- a/distro_tracker/core/templates/core/toggle-chevron.html
+++ /dev/null
@@ -1,2 +0,0 @@
-{% load distro_tracker_extras %}
-{% octicon 'chevron-down' 'Toggle details' %}
diff --git a/distro_tracker/core/templatetags/distro_tracker_extras.py b/distro_tracker/core/templatetags/distro_tracker_extras.py
index fd81af6..3f33fc7 100644
--- a/distro_tracker/core/templatetags/distro_tracker_extras.py
+++ b/distro_tracker/core/templatetags/distro_tracker_extras.py
@@ -9,7 +9,9 @@
# except according to the terms contained in the LICENSE file.
"""Additional distro-tracker specific template tags."""
from __future__ import unicode_literals
+
from django import template
+from django.template.loader import render_to_string
register = template.Library()
@@ -49,20 +51,26 @@ def repeat(parser, token):
return RepeatNode(nodelist, count)
-@register.inclusion_tag('core/octicon.html')
-def octicon(name, text):
+@register.simple_tag()
+def octicon(name, title='', content=None):
"""
Renders an octicon with alternate text.
"""
- return { 'name':name, 'text':text }
+ if content is None:
+ content = "[{}]".format(title)
+
+ return render_to_string(
+ 'core/octicon.html',
+ {'name': name, 'title': title, 'content': content}
+ )
-@register.inclusion_tag('core/toggle-chevron.html')
-def toggle_chevron():
+@register.simple_tag()
+def toggle_chevron(title='Toggle details', content=None):
"""
Renders a chevron to toggle details.
"""
- return {}
+ return octicon('chevron-down', title, content)
@register.filter(name='zip')
--- End Message ---