summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2016-02-22 21:07:12 +0200
committerLars Wirzenius <liw@liw.fi>2016-02-22 21:07:12 +0200
commit0ca787484889e75532f9493cf08c98ed14251c2d (patch)
treee3856a9eba4dc460e88430db74d601cc7814ba45
parentfdbcf82906fe978cae62dcc70dbd18c013261b8d (diff)
downloaddistix-0ca787484889e75532f9493cf08c98ed14251c2d.tar.gz
Change list plugin to use TextRenderer, template
-rw-r--r--distixlib/plugins/list_plugin.py21
-rw-r--r--distixlib/templates/list.j23
2 files changed, 17 insertions, 7 deletions
diff --git a/distixlib/plugins/list_plugin.py b/distixlib/plugins/list_plugin.py
index 232b776..433c8c5 100644
--- a/distixlib/plugins/list_plugin.py
+++ b/distixlib/plugins/list_plugin.py
@@ -43,8 +43,13 @@ class ListPlugin(cliapp.Plugin):
else:
tickets_to_list = all_tickets
- for ticket in tickets_to_list:
- self._list_ticket(ticket)
+ variables = {
+ 'tickets': tickets_to_list,
+ }
+
+ renderer = self._get_renderer()
+ text = renderer.render('list.j2', variables)
+ self.app.output.write(text)
def _select_tickets(self, tickets, pattern):
key, value = self._parse_pattern(pattern)
@@ -63,9 +68,11 @@ class ListPlugin(cliapp.Plugin):
metadata = ticket.get_ticket_metadata()
return key in metadata and value in metadata.get_all_values(key)
- def _list_ticket(self, ticket):
- ticket_id = ticket.get_ticket_id()
+ def _get_renderer(self):
_, encoding = locale.getdefaultlocale()
- title = ticket.get_title().encode(encoding or 'UTF8')
- self.app.output.write(
- '{ticket_id} {title}\n'.format(ticket_id=ticket_id, title=title))
+ if encoding is None:
+ encoding = 'UTF8'
+
+ renderer = distixlib.TextRenderer()
+ renderer.set_output_encoding(encoding)
+ return renderer
diff --git a/distixlib/templates/list.j2 b/distixlib/templates/list.j2
new file mode 100644
index 0000000..2d49824
--- /dev/null
+++ b/distixlib/templates/list.j2
@@ -0,0 +1,3 @@
+{% for ticket in tickets %}
+{{ ticket.get_ticket_id() }} {{ ticket.get_title() }}
+{% endfor %}