Beispiel #1
0
    def create_with_data(self, user=None, **kwargs) -> "Team":
        team = Team.objects.create(**kwargs)

        if not user or not posthoganalytics.feature_enabled("actions-ux-201012", user.distinct_id):
            # Don't create default `Pageviews` action on actions-ux-201012 feature flag
            action = Action.objects.create(team=team, name="Pageviews")
            ActionStep.objects.create(action=action, event="$pageview")

        # Create default dashboard
        if user and posthoganalytics.feature_enabled("1694-dashboards", user.distinct_id):
            # Create app template dashboard if feature flag is active
            dashboard = Dashboard.objects.create(name="My App Dashboard", pinned=True, team=team,)
            create_dashboard_from_template("DEFAULT_APP", dashboard)
        else:
            # DEPRECATED: Will be retired in favor of dashboard_templates.py
            dashboard = Dashboard.objects.create(
                name="Default", pinned=True, team=team, share_token=generate_random_token()
            )

            DashboardItem.objects.create(
                team=team,
                dashboard=dashboard,
                name="Pageviews this week",
                type=TRENDS_LINEAR,
                filters={TREND_FILTER_TYPE_EVENTS: [{"id": "$pageview", "type": TREND_FILTER_TYPE_EVENTS}]},
                last_refresh=timezone.now(),
            )
            DashboardItem.objects.create(
                team=team,
                dashboard=dashboard,
                name="Most popular browsers this week",
                type="ActionsTable",
                filters={
                    TREND_FILTER_TYPE_EVENTS: [{"id": "$pageview", "type": TREND_FILTER_TYPE_EVENTS}],
                    "display": "ActionsTable",
                    "breakdown": "$browser",
                },
                last_refresh=timezone.now(),
            )
            DashboardItem.objects.create(
                team=team,
                dashboard=dashboard,
                name="Daily Active Users",
                type=TRENDS_LINEAR,
                filters={
                    TREND_FILTER_TYPE_EVENTS: [{"id": "$pageview", "math": "dau", "type": TREND_FILTER_TYPE_EVENTS}]
                },
                last_refresh=timezone.now(),
            )

        return team
Beispiel #2
0
 def enable_new_onboarding(self, user: Optional[User] = None) -> bool:
     if user is None:
         user = self._user
     return posthoganalytics.feature_enabled(
         "new-onboarding-2822", user.distinct_id) or settings.DEBUG
Beispiel #3
0
def endpoint_enabled(endpoint_flag: str, distinct_id: str):
    return posthoganalytics.feature_enabled(
        endpoint_flag, distinct_id) or settings.DEBUG or settings.TEST
Beispiel #4
0
    def create_with_data(self,
                         users: Optional[List[Any]] = None,
                         **kwargs) -> "Team":
        kwargs["api_token"] = kwargs.get("api_token", generate_random_token())
        kwargs["signup_token"] = kwargs.get("signup_token",
                                            generate_random_token(22))
        team = Team.objects.create(**kwargs)
        if users:
            team.users.set(users)

        if not users or not posthoganalytics.feature_enabled(
                "actions-ux-201012", users[0].distinct_id):
            # Don't create default `Pageviews` action on actions-ux-201012 feature flag (use first user as proxy for org)
            action = Action.objects.create(team=team, name="Pageviews")

        ActionStep.objects.create(action=action, event="$pageview")

        dashboard = Dashboard.objects.create(
            name="Default",
            pinned=True,
            team=team,
            share_token=generate_random_token())

        DashboardItem.objects.create(
            team=team,
            dashboard=dashboard,
            name="Pageviews this week",
            type=TRENDS_LINEAR,
            filters={
                TREND_FILTER_TYPE_EVENTS: [{
                    "id": "$pageview",
                    "type": TREND_FILTER_TYPE_EVENTS
                }]
            },
            last_refresh=timezone.now(),
        )
        DashboardItem.objects.create(
            team=team,
            dashboard=dashboard,
            name="Most popular browsers this week",
            type="ActionsTable",
            filters={
                TREND_FILTER_TYPE_EVENTS: [{
                    "id": "$pageview",
                    "type": TREND_FILTER_TYPE_EVENTS
                }],
                "display":
                "ActionsTable",
                "breakdown":
                "$browser",
            },
            last_refresh=timezone.now(),
        )
        DashboardItem.objects.create(
            team=team,
            dashboard=dashboard,
            name="Daily Active Users",
            type=TRENDS_LINEAR,
            filters={
                TREND_FILTER_TYPE_EVENTS: [{
                    "id": "$pageview",
                    "math": "dau",
                    "type": TREND_FILTER_TYPE_EVENTS
                }]
            },
            last_refresh=timezone.now(),
        )
        return team