Closed EricNeville closed 3 years ago
This logic should be in the enum imo. To avoid having to have a separate facilities class for each case, I would suggest something like this:
class FacilityEnum(enum.Enum):
@property
def post_value(self):
return self.value[0]
@property
def valid_types(self):
return self.value[1]
class Facilities(FacilityEnum):
ALARM = ("alarm", [SearchType.RESIDENTIAL_RENT,
SearchType.RESIDENTIAL_SALE,
...])
CENTRAL_HEATING_GAS = ("gas-fired-central-heating", [SearchType.RESIDENTIAL_RENT,
SearchType.RESIDENTIAL_SALE,
...])
...
class Daft:
...
def set_facilities(self, facilities: list[Facilities]):
for f in facilities:
if self.section in [s.value for s in f.valid_types]:
self._add_facility(f.post_value)
There may be a smarter way of doing this @AnthonyBloomer
Do you think it should be written to expect a list of facilities as you have above? That seems to make sense from the point of view of someone potentially wanting to search for a few facilities. However up until this point for the sake of consistency with other search parameters I had it adding one facility at a time to the search. For example adding property types works that way too, even though someone might want to add more than one property type to the search.
Actually it is possible to overwrite the value property so this is probably better to keep consistent with the other enums:
import enum
class Facilities(enum.Enum):
def __new__(cls, *args, **kwargs):
obj = object.__new__(cls)
obj._value_ = args[0]
return obj
def __init__(self, _, valid_types):
self.valid_types = valid_types
ALARM = "alarm", [SearchType.RESIDENTIAL_RENT,
SearchType.RESIDENTIAL_SALE]
print(Facilities.ALARM.value)
print(Facilities.ALARM.valid_types)
Output:
alarm
[<SearchType.RESIDENTIAL_RENT: 'residential-to-rent'>, <SearchType.RESIDENTIAL_SALE: 'residential-for-sale'>]
The facility options available for filtering are heavily dependent on the
SearchType
. In my local version I have facilities filtering added and functioning but without any checking related to this. I was planning to resolve this issue before pushing it. It will probably make sense to solve this in the same way as whatever ends up being done for the PropertyType SearchType combos issue (https://github.com/AnthonyBloomer/daftlistings/issues/108#issue-849665232), although there are more differences in the available facilities acrossSearchType
than there is inPropertyType
. The facilities values bySearchType
are as follows: