feat(announcements): Obsługa wielu kategorii dla aktualności

- Dodanie kolumny categories (ARRAY) do tabeli announcements
- Nowe metody: categories_labels, has_category()
- Migracja 029: dodanie kolumny i mapowanie danych
- Zachowanie kompatybilności wstecznej z polem category

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-01-29 15:14:15 +01:00
parent 53e6d14bdd
commit f5050b92cc
2 changed files with 51 additions and 4 deletions

View File

@ -3063,9 +3063,11 @@ class Announcement(Base):
excerpt = Column(String(500)) # Krótki opis do listy
content = Column(Text, nullable=False) # Pełna treść (HTML)
# Kategoryzacja
category = Column(String(50), default='general')
# Wartości: general, event, opportunity, member_news, partnership
# Kategoryzacja (obsługa wielu kategorii)
categories = Column(ARRAY(String), default=[]) # Tablica kategorii
# Wartości: internal, external, event, opportunity, partnership
# Stare pole dla kompatybilności wstecznej (do usunięcia po migracji)
category = Column(String(50), default='internal')
# Media
image_url = Column(String(1000))
@ -3111,9 +3113,24 @@ class Announcement(Base):
@property
def category_label(self):
"""Zwraca polską etykietę kategorii"""
"""Zwraca polską etykietę pierwszej kategorii (kompatybilność wsteczna)"""
if self.categories:
return self.CATEGORY_LABELS.get(self.categories[0], self.categories[0])
return self.CATEGORY_LABELS.get(self.category, self.category)
@property
def categories_labels(self):
"""Zwraca listę polskich etykiet wszystkich kategorii"""
if self.categories:
return [self.CATEGORY_LABELS.get(cat, cat) for cat in self.categories]
return [self.CATEGORY_LABELS.get(self.category, self.category)]
def has_category(self, category):
"""Sprawdza czy ogłoszenie ma daną kategorię"""
if self.categories:
return category in self.categories
return self.category == category
@property
def status_label(self):
"""Zwraca polską etykietę statusu"""

View File

@ -0,0 +1,30 @@
-- Migration: Add categories array to announcements
-- Date: 2026-01-29
-- Description: Dodanie obsługi wielu kategorii dla aktualności
-- 1. Dodaj nową kolumnę categories jako tablica
ALTER TABLE announcements
ADD COLUMN IF NOT EXISTS categories TEXT[] DEFAULT '{}';
-- 2. Migracja danych z category do categories
UPDATE announcements
SET categories = ARRAY[category]
WHERE categories IS NULL OR categories = '{}';
-- 3. Mapowanie starych wartości na nowe
UPDATE announcements
SET categories = ARRAY['internal']
WHERE 'general' = ANY(categories) OR 'member_news' = ANY(categories);
UPDATE announcements
SET categories = array_remove(categories, 'general');
UPDATE announcements
SET categories = array_remove(categories, 'member_news');
-- 4. Indeks dla szybszego wyszukiwania po kategorii
CREATE INDEX IF NOT EXISTS idx_announcements_categories
ON announcements USING GIN(categories);
-- 5. Nadaj uprawnienia
GRANT ALL ON TABLE announcements TO nordabiz_app;