From 1142868dd78ce1f5306e6d5eb49670f90fe024f5 Mon Sep 17 00:00:00 2001 From: Alexandre Morignot Date: Thu, 27 Nov 2014 15:37:21 +0100 Subject: [PATCH] [boobcoming] search by ticket status --- weboob/applications/boobcoming/boobcoming.py | 47 +++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/weboob/applications/boobcoming/boobcoming.py b/weboob/applications/boobcoming/boobcoming.py index 8eff2391..679e81c4 100644 --- a/weboob/applications/boobcoming/boobcoming.py +++ b/weboob/applications/boobcoming/boobcoming.py @@ -24,7 +24,7 @@ from datetime import time, datetime from weboob.tools.date import parse_date from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter from weboob.capabilities.base import empty -from weboob.capabilities.calendar import CapCalendarEvent, Query, CATEGORIES, BaseCalendarEvent +from weboob.capabilities.calendar import CapCalendarEvent, Query, CATEGORIES, BaseCalendarEvent, TICKET from weboob.tools.application.repl import ReplApplication, defaultcount @@ -188,6 +188,29 @@ class Boobcoming(ReplApplication): return super(Boobcoming, self).comp_object(obj1, obj2) + def select_values(self, values_from, values_to, query_str): + r = 'notempty' + while r != '': + for value in values_from.values: + print(' %s%2d)%s [%s] %s' % (self.BOLD, + values_from.index[value] + 1, + self.NC, + 'x' if value in values_to else ' ', + value)) + r = self.ask(query_str, regexp='(\d+|)', default='') + + if not r.isdigit(): + continue + r = int(r) + if r <= 0 or r > len(values_from.values): + continue + value = values_from.values[r - 1] + if value in values_to: + values_to.remove(value) + else: + values_to.append(value) + + @defaultcount(10) def do_search(self, line): """ @@ -196,26 +219,10 @@ class Boobcoming(ReplApplication): search for an event. Parameters interactively asked """ query = Query() - r = 'notempty' - while r != '': - for category in CATEGORIES.values: - print(' %s%2d)%s [%s] %s' % (self.BOLD, - CATEGORIES.index[category] + 1, - self.NC, - 'x' if category in query.categories else ' ', category)) - r = self.ask(' Select category (or empty to stop)', regexp='(\d+|)', default='') - if not r.isdigit(): - continue - r = int(r) - if r <= 0 or r > len(CATEGORIES.values): - continue - value = CATEGORIES.values[r - 1] - if value in query.categories: - query.categories.remove(value) - else: - query.categories.append(value) + self.select_values(CATEGORIES, query.categories, ' Select categorie (or empty to stop)') + self.select_values(TICKET, query.ticket, ' Select tickets status (or empty to stop)') - if query.categories and len(query.categories) > 0: + if query.categories and len(query.categories) > 0 and query.ticket and len(query.ticket) > 0: query.city = self.ask('Enter a city', default='') query.summary = self.ask('Enter a title', default='')