[json] handle format_collection
This commit is contained in:
parent
7b5ab26d0f
commit
aeab3fac71
2 changed files with 17 additions and 0 deletions
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue