Exemplo n.º 1
0
    def to_representation(self, instance):
        if self.context["request"].GET.get("refresh"):
            update_dashboard_item_cache(instance, None)
            instance.refresh_from_db()

        representation = super().to_representation(instance)
        representation["filters"] = instance.dashboard_filters(
            dashboard=self.context.get("dashboard"))
        return representation
Exemplo n.º 2
0
    def get_result(self, dashboard_item: DashboardItem):
        # If it's more than a day old, don't return anything
        if dashboard_item.last_refresh and (
                now() - dashboard_item.last_refresh).days > 0:
            return None

        if not dashboard_item.filters_hash:
            return None

        if self.context["request"].GET.get("refresh"):
            update_dashboard_item_cache(dashboard_item, None)

        result = get_safe_cache(dashboard_item.filters_hash)
        if not result or result.get("task_id", None):
            return None
        return result.get("result")
Exemplo n.º 3
0
    def get_result(self, insight: Insight):
        if not insight.filters:
            return None
        if self.context["request"].GET.get("refresh"):
            return update_dashboard_item_cache(insight, None)

        result = get_safe_cache(insight.filters_hash)
        if not result or result.get("task_id", None):
            return None
        # Data might not be defined if there is still cached results from before moving from 'results' to 'data'
        return result.get("result")