diff --git a/anyway/infographics_utils.py b/anyway/infographics_utils.py index 6eb57f53..10c2c04a 100755 --- a/anyway/infographics_utils.py +++ b/anyway/infographics_utils.py @@ -212,8 +212,8 @@ def get_infographics_data_for_location(request_params: RequestParams) -> Dict: elif WIDGETS not in output: logging.error(f"get_infographics_data: 'widgets' key missing from output:{output}") else: - non_empty = list(filter(lambda x: x[DATA][ITEMS], output[WIDGETS])) - output[WIDGETS] = update_cache_results(request_params, non_empty) + updated_output = update_cache_results(request_params, output[WIDGETS]) + output[WIDGETS] = list(filter(lambda x: x[DATA][ITEMS], updated_output)) return output diff --git a/anyway/widgets/road_segment_widgets/street_view_widget.py b/anyway/widgets/road_segment_widgets/street_view_widget.py index 07d98cc9..bb6ff27a 100644 --- a/anyway/widgets/road_segment_widgets/street_view_widget.py +++ b/anyway/widgets/road_segment_widgets/street_view_widget.py @@ -1,7 +1,8 @@ +import logging from anyway.request_params import RequestParams from anyway.widgets.widget import register from anyway.widgets.road_segment_widgets.road_segment_widget import RoadSegmentWidget -from typing import Dict +from typing import Dict, Optional from flask_babel import _ @@ -23,8 +24,14 @@ def generate_items(self) -> None: def is_included(self): return self.request_params.gps and self.request_params.gps.get("lon") and self.request_params.gps.get("lat") - @staticmethod def localize_items(request_params: RequestParams, items: Dict) -> Dict: items["data"]["text"] = {"title": _("Street view widget")} return items + + @classmethod + def update_result(cls, request_params: RequestParams, cached_items: Dict) -> Optional[Dict]: + try: + return cls.generate_widget_data(request_params) + except Exception as e: + logging.debug(f"Encountered error when generating items for widget class {cls} : {e}")