comparison frontends/src/jp/cmd_blog.py @ 2164:63d191c05ecd

jp (blog): set default template and data mapping for the new template output
author Goffi <goffi@goffi.org>
date Tue, 21 Feb 2017 21:01:40 +0100
parents 62dfa6e02f54
children 301bb52c8715
comparison
equal deleted inserted replaced
2163:75667727c500 2164:63d191c05ecd
20 20
21 import base 21 import base
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 from sat_frontends.jp.constants import Const as C 23 from sat_frontends.jp.constants import Const as C
24 from sat.tools.common.ansi import ANSI as A 24 from sat.tools.common.ansi import ANSI as A
25 from sat.tools.common import data_objects
25 from sat.tools import config 26 from sat.tools import config
26 from ConfigParser import NoSectionError, NoOptionError 27 from ConfigParser import NoSectionError, NoOptionError
27 import json 28 import json
28 import sys 29 import sys
29 import os.path 30 import os.path
186 self.disp(u"Couldn't parse editor cmd [{cmd}]: {reason}".format(cmd=cmd_line, reason=e)) 187 self.disp(u"Couldn't parse editor cmd [{cmd}]: {reason}".format(cmd=cmd_line, reason=e))
187 return [] 188 return []
188 189
189 190
190 class Get(base.CommandBase): 191 class Get(base.CommandBase):
192 TEMPLATE = u"blog/articles.html"
191 193
192 def __init__(self, host): 194 def __init__(self, host):
193 extra_outputs = {'default': self.default_output, 195 extra_outputs = {'default': self.default_output,
194 'fancy': self.fancy_output} 196 'fancy': self.fancy_output}
195 base.CommandBase.__init__(self, host, 'get', use_verbose=True, use_output='complex', extra_outputs=extra_outputs, help=_(u'get blog item(s)')) 197 base.CommandBase.__init__(self, host, 'get', use_verbose=True, use_output='complex', extra_outputs=extra_outputs, help=_(u'get blog item(s)'))
204 self.parser.add_argument("-k", "--key", type=base.unicode_decoder, action='append', dest='keys', 206 self.parser.add_argument("-k", "--key", type=base.unicode_decoder, action='append', dest='keys',
205 help=_(u"microblog data key(s) to display (default: depend of verbosity)")) 207 help=_(u"microblog data key(s) to display (default: depend of verbosity)"))
206 self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'', 208 self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'',
207 help=_(u"JID of the PubSub service (default: request profile own blog)")) 209 help=_(u"JID of the PubSub service (default: request profile own blog)"))
208 # TODO: add MAM filters 210 # TODO: add MAM filters
211
212 def template_data_mapping(self, data):
213 return {u'items': data_objects.BlogItems(data)}
209 214
210 def format_comments(self, item, keys): 215 def format_comments(self, item, keys):
211 comments_data = data_format.dict2iterdict(u'comments', item, (u'node', u'service'), pop=True) 216 comments_data = data_format.dict2iterdict(u'comments', item, (u'node', u'service'), pop=True)
212 lines = [] 217 lines = []
213 for data in comments_data: 218 for data in comments_data: