mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
created extract kwargs to read bathrooms and bedrooms
This commit is contained in:
parent
db6fd58af4
commit
ac8cf27169
2 changed files with 23 additions and 0 deletions
|
|
@ -139,6 +139,28 @@ class Property:
|
|||
|
||||
self.recommendations_scoring_data = []
|
||||
|
||||
@classmethod
|
||||
def extract_kwargs(cls, kwargs):
|
||||
"""
|
||||
This method is to be used in the router, to extract the kwargs from the request and prevent any errors such as
|
||||
non-integer values, or inputs that clash with the __init__ method of this class
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
n_bathrooms = kwargs.get("n_bathrooms", None)
|
||||
if n_bathrooms is not None:
|
||||
# We add on a small value to ensure that the number of bathrooms is rounded up, in case the value is 0.5
|
||||
n_bathrooms = int(round(n_bathrooms + 1e-5))
|
||||
|
||||
n_bedrooms = kwargs.get("n_bedrooms", None)
|
||||
if n_bedrooms is not None:
|
||||
n_bedrooms = int(round(n_bedrooms + 1e-5))
|
||||
|
||||
return {
|
||||
"n_bathrooms": n_bathrooms,
|
||||
"n_bedrooms": n_bedrooms,
|
||||
}
|
||||
|
||||
def parse_kwargs(self, kwargs):
|
||||
# We extract the elements from kwargs that we recognise. Anything additional is ignored
|
||||
self.n_bathrooms = kwargs.get("n_bathrooms", None)
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ async def trigger_plan(body: PlanTriggerRequest):
|
|||
address=epc_searcher.address_clean,
|
||||
postcode=epc_searcher.postcode_clean,
|
||||
epc_record=prepared_epc,
|
||||
**Property.extract_kwargs(config)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue