Commit aeab3fac authored by Bezleputh's avatar Bezleputh Committed by Romain Bignon

[json] handle format_collection

parent 7b5ab26d
......@@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.ordereddict import OrderedDict
from .base import IBaseCap, CapBaseObject, UserError, StringField, Field
......@@ -54,6 +55,19 @@ class BaseCollection(CapBaseObject):
def path_level(self):
return len(self.split_path)
def to_dict(self):
def iter_decorate(d):
for key, value in d:
if key == 'id' and self.backend is not None:
value = u'%s@%s' % (self.basename, self.backend)
yield key, value
if key == 'split_path':
yield key, '/'.join(value)
fields_iterator = self.iter_fields()
return OrderedDict(iter_decorate(fields_iterator))
class Collection(BaseCollection):
"""
......
......@@ -57,6 +57,9 @@ class JsonFormatter(IFormatter):
def format_dict(self, item):
self.queue.append(item)
def format_collection(self, collection, only):
self.queue.append(collection.to_dict())
class JsonLineFormatter(IFormatter):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment