Get all available subscriptions for details command

Add a new method get_object_list to ReplApplication
Should close #846.
This commit is contained in:
Florent 2012-04-24 19:38:15 +02:00 committed by Romain Bignon
commit 92d5e9ea0f
2 changed files with 43 additions and 23 deletions

View file

@ -35,6 +35,7 @@ class SubscriptionsFormatter(PrettyFormatter):
def get_title(self, obj):
return obj.label
class Boobill(ReplApplication):
APPNAME = 'boobill'
VERSION = '0.c'
@ -49,7 +50,6 @@ class Boobill(ReplApplication):
'ls': 'subscriptions',
}
def main(self, argv):
self.load_config()
return ReplApplication.main(self, argv)
@ -61,37 +61,42 @@ class Boobill(ReplApplication):
List subscriptions
"""
self.start_format()
for backend, subscription in self.do('iter_subscription'):
for subscription in self.get_object_list('iter_subscription'):
self.cached_format(subscription)
self.flush()
def do_details(self, id):
"""
details Id
details [ID]
Get details of a subscription.
Get details of subscriptions.
If no ID given, display all details of all backends
"""
l = []
id, backend_name = self.parse_id(id)
if not id:
print >>sys.stderr, 'Error: please give a subscription ID (hint: use subscriptions command)'
return 2
names = (backend_name,) if backend_name is not None else None
for subscrib in self.get_object_list('iter_subscription'):
l.append((subscrib.id, subscrib.backend))
else:
l.append((id, backend_name))
# XXX: should be generated by backend? -Flo
# XXX: no, but you should do it in a specific formatter -romain
mysum = Detail()
mysum.label = u"Sum"
mysum.infos = u"Generated by boobill"
mysum.price = Decimal("0.")
for id, backend in l:
names = (backend,) if backend is not None else None
# XXX: should be generated by backend? -Flo
# XXX: no, but you should do it in a specific formatter -romain
mysum = Detail()
mysum.label = u"Sum"
mysum.infos = u"Generated by boobill"
mysum.price = Decimal("0.")
self.start_format()
for backend, detail in self.do('get_details', id, backends=names):
self.format(detail)
mysum.price = detail.price + mysum.price
self.start_format()
for backend, detail in self.do('get_details', id, backends=names):
self.format(detail)
mysum.price = detail.price + mysum.price
self.format(mysum)
self.flush()
self.format(mysum)
self.flush()
def do_history(self, id):
"""