nordabiz/scripts/mark_test_classifieds.py
Maciej Pienczyn ffc6d8219f feat: Add toggle button to hide/show test items on B2B board
- Add is_test field to Classified model
- Add test-item styling (opacity + gray border + badge)
- Add yellow toggle button with localStorage persistence
- Add script to mark existing classifieds as test
2026-01-13 13:08:11 +01:00

52 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Oznacz wszystkie obecne ogłoszenia B2B jako testowe."""
import os
import sys
from dotenv import load_dotenv
# Load .env first
load_dotenv()
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlalchemy import text
from database import SessionLocal, Classified
def main():
db = SessionLocal()
# First, ensure the is_test column exists
try:
db.execute(text("ALTER TABLE classifieds ADD COLUMN IF NOT EXISTS is_test BOOLEAN DEFAULT FALSE"))
db.commit()
print("Kolumna is_test dodana (lub już istnieje)")
except Exception as e:
print(f"Uwaga przy dodawaniu kolumny: {e}")
db.rollback()
# Get all classifieds
classifieds = db.query(Classified).all()
if not classifieds:
print("Brak ogłoszeń w bazie danych.")
db.close()
return
print(f"Znaleziono {len(classifieds)} ogłoszeń do oznaczenia jako testowe...")
print()
for c in classifieds:
c.is_test = True
print(f" ID {c.id}: {c.title[:50]}... ({c.listing_type})")
db.commit()
db.close()
print()
print(f"Oznaczono {len(classifieds)} ogłoszeń jako testowe")
print("Gotowe!")
if __name__ == "__main__":
main()