feat: add is_disney column for reliable Disney/Non-Disney filtering

- Added is_disney INTEGER DEFAULT 0 column to assets table
- Backfilled 996 Disney assets based on D- customer prefix
- Server: is_disney in AssetCreate/AssetUpdate models, INSERT/UPDATE
- Server: disney_filter query param now uses is_disney column (no JOIN needed)
- import_cantaloupe.py: sets is_disney=1 when customer starts with D-
- import_machines.py: sets is_disney=1 when customer starts with D-
- disney_classify.py: sets is_disney=1 when classifying
- Frontend: new Location Type dropdown with Disney/Non-Disney toggle
  (replaces the __disney__/__non_disney__ park dropdown pseudo-options)
This commit is contained in:
2026-05-22 18:34:13 -04:00
parent 60dfd3434a
commit e8a918fc7b
5 changed files with 39 additions and 25 deletions
+11 -8
View File
@@ -165,6 +165,7 @@ def _create_v2_tables(conn: sqlite3.Connection):
longitude REAL DEFAULT NULL,
geofence_radius_meters INTEGER DEFAULT 50,
disney_park TEXT DEFAULT NULL,
is_disney INTEGER DEFAULT 0,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
);
@@ -629,6 +630,7 @@ class AssetCreate(BaseModel):
latitude: Optional[float] = None
longitude: Optional[float] = None
geofence_radius_meters: Optional[int] = 50
is_disney: Optional[bool] = None
keys: Optional[List[AssetKey]] = []
badges: Optional[List[str]] = []
@@ -658,6 +660,7 @@ class AssetUpdate(BaseModel):
latitude: Optional[float] = None
longitude: Optional[float] = None
geofence_radius_meters: Optional[int] = None
is_disney: Optional[bool] = None
keys: Optional[List[AssetKey]] = None
badges: Optional[List[str]] = None
@@ -867,7 +870,7 @@ def _build_asset_insert(body: AssetCreate, machine_id: str, name: str):
"make", "model", "address", "building_name", "building_number", "floor",
"room", "trailer_number", "walking_directions", "map_link",
"parking_location", "photo_path", "customer_id", "location_id",
"assigned_to", "latitude", "longitude", "geofence_radius_meters",
"assigned_to", "latitude", "longitude", "geofence_radius_meters", "is_disney",
]
values = (
machine_id, body.serial_number or "", name, body.description or "",
@@ -880,6 +883,7 @@ def _build_asset_insert(body: AssetCreate, machine_id: str, name: str):
body.customer_id, body.location_id, body.assigned_to,
body.latitude, body.longitude,
body.geofence_radius_meters if body.geofence_radius_meters is not None else 50,
body.is_disney if body.is_disney is not None else None,
)
return columns, values
@@ -1010,9 +1014,9 @@ def list_assets(
conditions.append("disney_park = ?")
params.append(disney_park)
if disney_filter == "disney":
conditions.append("(disney_park IS NOT NULL OR c.name LIKE 'D-%')")
conditions.append("is_disney = 1")
elif disney_filter == "non_disney":
conditions.append("(disney_park IS NULL AND (c.name IS NULL OR c.name NOT LIKE 'D-%'))")
conditions.append("(is_disney IS NULL OR is_disney = 0)")
if model:
conditions.append("model = ?")
params.append(model)
@@ -1031,10 +1035,7 @@ def list_assets(
params.extend([like, like, like, like])
where = " AND ".join(conditions)
join_clause = ""
if disney_filter:
join_clause = " LEFT JOIN customers c ON assets.customer_id = c.id"
sql = f"SELECT assets.* FROM assets{join_clause}"
sql = "SELECT * FROM assets"
if where:
sql += f" WHERE {where}"
sql += " ORDER BY created_at DESC LIMIT ? OFFSET ?"
@@ -1042,7 +1043,7 @@ def list_assets(
rows = conn.execute(sql, params).fetchall()
# Get total count for pagination
count_sql = f"SELECT COUNT(*) FROM assets{join_clause}"
count_sql = "SELECT COUNT(*) FROM assets"
if where:
count_sql += f" WHERE {where}"
total = conn.execute(count_sql, params[:len(params)-2]).fetchone()[0]
@@ -1206,6 +1207,8 @@ def update_asset(asset_id: int, body: AssetUpdate):
updates["longitude"] = body.longitude
if body.geofence_radius_meters is not None:
updates["geofence_radius_meters"] = body.geofence_radius_meters
if body.is_disney is not None:
updates["is_disney"] = 1 if body.is_disney else 0
# Auto-populate address from GPS when lat/lng are provided
lat = updates.get("latitude") if "latitude" in updates else None