diff --git a/weboob/applications/flatboob/flatboob.py b/weboob/applications/flatboob/flatboob.py index bd450fbcd425d7946a39cf5bc344b37804fb0a57..c9bf567468f0ddebb9c9a411092f35d12de3e664 100644 --- a/weboob/applications/flatboob/flatboob.py +++ b/weboob/applications/flatboob/flatboob.py @@ -18,7 +18,6 @@ # along with weboob. If not, see . - from weboob.capabilities.housing import CapHousing, Query from weboob.tools.application.repl import ReplApplication, defaultcount from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter @@ -137,6 +136,25 @@ def do_search(self, line): else: query.cities.append(city) + r = 'notempty' + while r != '': + for good in Query.HOUSE_TYPES.values: + print ' %s%2d)%s [%s] %s' % (self.BOLD, + Query.HOUSE_TYPES.index[good] + 1, + self.NC, + 'x' if good in query.house_types else ' ', good) + r = self.ask(' Select type of house (or empty to stop)', regexp='(\d+|)', default='') + if not r.isdigit(): + continue + r = int(r) + if r <= 0 or r > len(Query.TYPE_OF_GOOD.values): + continue + value = Query.TYPE_OF_GOOD.values[r - 1] + if value in query.type_of_good: + query.type_of_good.remove(value) + else: + query.type_of_good.append(value) + query.area_min = self.ask_int('Enter min area') query.area_max = self.ask_int('Enter max area') query.cost_min = self.ask_int('Enter min cost') diff --git a/weboob/capabilities/housing.py b/weboob/capabilities/housing.py index 38ec19b782d22f393b67c854c1e7cdfcabafed32..f7da4f38395191314102de676937bfa7fac5a210 100644 --- a/weboob/capabilities/housing.py +++ b/weboob/capabilities/housing.py @@ -70,16 +70,37 @@ class Query(BaseObject): TYPE_RENT = 0 TYPE_SALE = 1 - type = IntField('Type of housing to find (TYPE_* constants)') - cities = Field('List of cities to search in', list, tuple) - area_min = IntField('Minimal area (in m2)') - area_max = IntField('Maximal area (in m2)') - cost_min = IntField('Minimal cost') - cost_max = IntField('Maximal cost') - nb_rooms = IntField('Number of rooms') + def enum(**enums): + _values = enums.values() + _items = enums.items() + _index = dict((value, i) for i, value in enumerate(enums.values())) + _types = list((type(value) for value in enums.values())) + enums['values'] = _values + enums['items'] = _items + enums['index'] = _index + enums['types'] = _types + return type('Enum', (), enums) + + HOUSE_TYPES = enum(APART=u'Apartment', + HOUSE=u'House', + PARKING=u'Parking', + LAND=u'Land', + OTHER=u'Other') + + type = IntField('Type of housing to find (TYPE_* constants)') + cities = Field('List of cities to search in', list, tuple) + area_min = IntField('Minimal area (in m2)') + area_max = IntField('Maximal area (in m2)') + cost_min = IntField('Minimal cost') + cost_max = IntField('Maximal cost') + nb_rooms = IntField('Number of rooms') + house_types = Field('List of house types', list, tuple) def __init__(self): BaseObject.__init__(self, '') + self.house_types = [] + for value in self.HOUSE_TYPES.values: + self.house_types.append(value) class City(BaseObject):