refs #1060 : move to_dict to base.py
This commit is contained in:
parent
8d8fe9090f
commit
1b47455225
2 changed files with 16 additions and 21 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Christophe Benz, Romain Bignon
|
||||
# Copyright(C) 2010-2013 Christophe Benz, Romain Bignon, Julien Hebert
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
|
|
@ -389,3 +389,15 @@ class CapBaseObject(object):
|
|||
self._fields.pop(name)
|
||||
except KeyError:
|
||||
object.__delattr__(self, name)
|
||||
|
||||
def to_dict(self):
|
||||
def iter_decorate(d):
|
||||
for key, value in d:
|
||||
if key == 'id' and self.backend is not None:
|
||||
value = self.fullid
|
||||
yield key, value
|
||||
|
||||
fields_iterator = self.iter_fields()
|
||||
return OrderedDict(iter_decorate(fields_iterator))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010-2011 Christophe Benz
|
||||
# Copyright(C) 2010-2013 Christophe Benz, Julien Hebert
|
||||
#
|
||||
# This file is part of weboob.
|
||||
#
|
||||
|
|
@ -48,7 +48,6 @@ else:
|
|||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||
|
||||
from weboob.capabilities.base import CapBaseObject
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
from weboob.tools.application.console import ConsoleApplication
|
||||
|
||||
|
||||
|
|
@ -173,7 +172,7 @@ class IFormatter(object):
|
|||
:type obj: CapBaseObject
|
||||
:rtype: str
|
||||
"""
|
||||
return self.format_dict(self.to_dict(obj))
|
||||
return self.format_dict(obj.to_dict())
|
||||
|
||||
def format_dict(self, obj):
|
||||
"""
|
||||
|
|
@ -185,23 +184,7 @@ class IFormatter(object):
|
|||
"""
|
||||
return NotImplementedError()
|
||||
|
||||
def to_dict(self, obj):
|
||||
if not isinstance(obj, CapBaseObject):
|
||||
try:
|
||||
return OrderedDict(obj)
|
||||
except ValueError:
|
||||
raise TypeError('Please give a CapBaseObject or a dict')
|
||||
|
||||
def iter_decorate(d):
|
||||
for key, value in d:
|
||||
if key == 'id' and obj.backend is not None:
|
||||
value = obj.fullid
|
||||
yield key, value
|
||||
|
||||
fields_iterator = obj.iter_fields()
|
||||
return OrderedDict(iter_decorate(fields_iterator))
|
||||
|
||||
|
||||
|
||||
class PrettyFormatter(IFormatter):
|
||||
def format_obj(self, obj, alias):
|
||||
title = self.get_title(obj)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue