mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-02 14:32:45 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
122 lines
4.1 KiB
Python
122 lines
4.1 KiB
Python
import uuid
|
|
|
|
from django.db import models
|
|
from django.db.models import Q
|
|
|
|
|
|
class ProductTourManager(models.Manager):
|
|
"""Default manager that excludes archived tours."""
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().filter(archived=False)
|
|
|
|
|
|
class ProductTour(models.Model):
|
|
"""A product tour guides users through application features."""
|
|
|
|
# nosemgrep: prefer-uuid7-django-pk -- TODO: migrate to uuid7 or clarify intent
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
team = models.ForeignKey(
|
|
"insights.Team",
|
|
on_delete=models.CASCADE,
|
|
related_name="product_tours",
|
|
related_query_name="product_tour",
|
|
)
|
|
|
|
name = models.CharField(max_length=400)
|
|
description = models.TextField(blank=True, default="")
|
|
|
|
internal_targeting_flag = models.ForeignKey(
|
|
"feature_flags.FeatureFlag",
|
|
null=True,
|
|
blank=True,
|
|
on_delete=models.SET_NULL,
|
|
related_name="product_tours_internal_targeting_flag",
|
|
related_query_name="product_tour_internal_targeting_flag",
|
|
)
|
|
|
|
linked_flag = models.ForeignKey(
|
|
"feature_flags.FeatureFlag",
|
|
null=True,
|
|
blank=True,
|
|
on_delete=models.SET_NULL,
|
|
related_name="product_tours_linked_flag",
|
|
related_query_name="product_tour_linked_flag",
|
|
db_index=False,
|
|
)
|
|
|
|
linked_surveys = models.ManyToManyField(
|
|
"surveys.Survey",
|
|
blank=True,
|
|
related_name="product_tours",
|
|
related_query_name="product_tour",
|
|
)
|
|
|
|
content = models.JSONField(default=dict, blank=True)
|
|
draft_content = models.JSONField(null=True, blank=True, default=None)
|
|
|
|
auto_launch = models.BooleanField(default=False)
|
|
|
|
start_date = models.DateTimeField(null=True, blank=True)
|
|
end_date = models.DateTimeField(null=True, blank=True)
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
created_by = models.ForeignKey(
|
|
"insights.User",
|
|
on_delete=models.SET_NULL,
|
|
null=True,
|
|
blank=True,
|
|
related_name="product_tours_created",
|
|
)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
archived = models.BooleanField(default=False)
|
|
|
|
objects = ProductTourManager()
|
|
all_objects: models.Manager["ProductTour"] = models.Manager()
|
|
|
|
class Meta:
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["team", "name"],
|
|
condition=Q(archived=False),
|
|
name="unique_product_tour_name_per_team",
|
|
)
|
|
]
|
|
indexes = [
|
|
models.Index(fields=["team", "archived"]),
|
|
]
|
|
|
|
def __str__(self):
|
|
return f"{self.name} ({self.id})"
|
|
|
|
def get_analytics_metadata(self) -> dict:
|
|
steps = self.content.get("steps", []) if self.content else []
|
|
tour_type = self.content.get("type", "tour") if self.content else "tour"
|
|
conditions = self.content.get("conditions", {}) if self.content else {}
|
|
|
|
if tour_type == "announcement" and steps:
|
|
first_step_type = steps[0].get("type")
|
|
if first_step_type == "banner":
|
|
tour_type = "banner"
|
|
elif first_step_type == "modal":
|
|
tour_type = "modal_announcement"
|
|
|
|
return {
|
|
"tour_id": str(self.id),
|
|
"tour_name": self.name,
|
|
"tour_type": tour_type,
|
|
"step_count": len(steps),
|
|
"has_targeting": self.internal_targeting_flag is not None,
|
|
"has_survey_steps": any(s.get("survey") for s in steps),
|
|
"auto_launch": self.auto_launch,
|
|
"display_frequency": self.content.get("displayFrequency") if self.content else None,
|
|
"has_url_condition": bool(conditions.get("url")),
|
|
"url_match_type": conditions.get("urlMatchType"),
|
|
"has_delay": bool(conditions.get("autoShowDelaySeconds")),
|
|
"has_selector_condition": bool(conditions.get("selector")),
|
|
"has_action_triggers": bool((conditions.get("actions") or {}).get("values")),
|
|
"has_event_triggers": bool((conditions.get("events") or {}).get("values")),
|
|
}
|