Faza 1 complete: bilingual+enrichment plumbing, UI/filters, frozen DB
Extraction finished (575/588 chunks; 6 content-filter-blocked, 7 await re-extraction). DB rebuilt and frozen at 9418 activities — content_keys are now stable for the enrichment overlay. Part A (plumbing + UI): - database.py: name_ro/description_ro/rules_ro/variations_ro, indoor_outdoor, space_needed, estimated_fields, source_id/source_ids/chunk_key columns; FTS5 indexes the 4 *_ro columns across CREATE + all 3 triggers; new equality filters + category counts for both axes. - activity.py: new fields + bilingual display helpers (get_display_*, is_estimated, axis displays). - config_taxonomy.py: INDOOR_OUTDOOR/SPACE_NEEDED enums + normalizers (None on unrecognised, no fabrication). - search.py / routes.py / config.py / templates / css: new dropdowns, RO-primary rendering with "(estimat)" markers and collapsible original text, and a /source/<id> download route shipped DARK behind SOURCE_DOWNLOAD_ENABLED (copyright opt-in). - build_database.py: source_id/chunk_key in dict_to_activity; merge_cluster unions source_ids without touching enrichment fields. Part B (enrichment pipeline, built not yet run): - build_database.py: load_enrichment + apply_enrichment (post-dedup, keyed on content_key) + --enrichment CLI + stated-vs-estimated QA. - run_enrichment.py (resumable, --source/--limit pilot scoping, --collect), ENRICHMENT_PROMPT.md. Repair: scripts/repair_extractions.py fixes the subagents' systematic unescaped-ASCII-quote bug with a faithful char-scanner (escapes, never truncates) + schema validation + a strictly-more-text guard. json_repair was tried first, truncated silently, and is NOT used. build_database has no repair dependency. Tests: tests/test_enrichment.py added; 99 pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,18 @@ class Config:
|
||||
# Search settings
|
||||
SEARCH_RESULTS_LIMIT = int(os.environ.get('SEARCH_RESULTS_LIMIT', '100'))
|
||||
FTS_ENABLED = True
|
||||
|
||||
# Source-file download (plan A6). Shipped DARK by default: serving the
|
||||
# original PDFs/books carries a copyright exposure the user must opt into.
|
||||
# The /source/<id> route 404s entirely while this is false; the UI hides
|
||||
# the download link. Enable with SOURCE_DOWNLOAD_ENABLED=true.
|
||||
SOURCE_DOWNLOAD_ENABLED = (
|
||||
os.environ.get('SOURCE_DOWNLOAD_ENABLED', 'false').lower() == 'true'
|
||||
)
|
||||
# Root of the original corpus. source_file values are relative to this.
|
||||
CORPUS_DIR = os.environ.get('CORPUS_DIR') or str(
|
||||
Path(__file__).parent.parent / 'data' / 'carti-camp-jocuri'
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def ensure_directories():
|
||||
|
||||
@@ -8,7 +8,7 @@ the UI displays the Romanian name. `category` (thematic domain) and
|
||||
|
||||
import unicodedata
|
||||
import re
|
||||
from typing import Dict, List
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
# --- Categories (thematic domain) --------------------------------------------
|
||||
# slug -> Romanian display name. ~16 fixed slugs; `altele` is the mandatory
|
||||
@@ -215,6 +215,89 @@ def normalize_content_type(value: str) -> str:
|
||||
return aliases.get(slug, DEFAULT_CONTENT_TYPE)
|
||||
|
||||
|
||||
# --- Indoor / outdoor (enrichment axis) --------------------------------------
|
||||
# Where the activity is run. Inferred during enrichment when the source is
|
||||
# silent — such inferences are flagged in `estimated_fields`. slug -> RO label.
|
||||
INDOOR_OUTDOOR: Dict[str, str] = {
|
||||
"indoor": "Interior",
|
||||
"outdoor": "Exterior",
|
||||
"either": "Interior sau exterior",
|
||||
}
|
||||
|
||||
# --- Space needed (enrichment axis) ------------------------------------------
|
||||
# Rough footprint the activity requires. slug -> RO label.
|
||||
SPACE_NEEDED: Dict[str, str] = {
|
||||
"mic": "Spațiu mic",
|
||||
"mediu": "Spațiu mediu",
|
||||
"mare": "Spațiu mare",
|
||||
}
|
||||
|
||||
# Aliases for robustness against LLM output variation. Keys are _slugify'd.
|
||||
_INDOOR_OUTDOOR_ALIASES: Dict[str, str] = {
|
||||
"interior": "indoor",
|
||||
"inside": "indoor",
|
||||
"in": "indoor",
|
||||
"exterior": "outdoor",
|
||||
"outside": "outdoor",
|
||||
"out": "outdoor",
|
||||
"aer-liber": "outdoor",
|
||||
"both": "either",
|
||||
"any": "either",
|
||||
"ambele": "either",
|
||||
"interior-exterior": "either",
|
||||
"indoor-outdoor": "either",
|
||||
}
|
||||
|
||||
_SPACE_NEEDED_ALIASES: Dict[str, str] = {
|
||||
"small": "mic",
|
||||
"redus": "mic",
|
||||
"putin": "mic",
|
||||
"medium": "mediu",
|
||||
"moderat": "mediu",
|
||||
"large": "mare",
|
||||
"big": "mare",
|
||||
"mult": "mare",
|
||||
"spatiu-mic": "mic",
|
||||
"spatiu-mediu": "mediu",
|
||||
"spatiu-mare": "mare",
|
||||
}
|
||||
|
||||
|
||||
def normalize_indoor_outdoor(value: str) -> Optional[str]:
|
||||
"""Map an arbitrary string to an indoor_outdoor slug, or None.
|
||||
|
||||
Unlike categories, this has NO mandatory fallback: an unrecognised or
|
||||
empty value yields None (field simply absent), so we never fabricate a
|
||||
location the enrichment did not assert.
|
||||
"""
|
||||
if not value:
|
||||
return None
|
||||
slug = _slugify(str(value))
|
||||
if slug in INDOOR_OUTDOOR:
|
||||
return slug
|
||||
return _INDOOR_OUTDOOR_ALIASES.get(slug)
|
||||
|
||||
|
||||
def normalize_space_needed(value: str) -> Optional[str]:
|
||||
"""Map an arbitrary string to a space_needed slug, or None (no fallback)."""
|
||||
if not value:
|
||||
return None
|
||||
slug = _slugify(str(value))
|
||||
if slug in SPACE_NEEDED:
|
||||
return slug
|
||||
return _SPACE_NEEDED_ALIASES.get(slug)
|
||||
|
||||
|
||||
def indoor_outdoor_display_name(slug: str) -> str:
|
||||
"""RO display name for an indoor_outdoor slug."""
|
||||
return INDOOR_OUTDOOR.get(slug, slug)
|
||||
|
||||
|
||||
def space_needed_display_name(slug: str) -> str:
|
||||
"""RO display name for a space_needed slug."""
|
||||
return SPACE_NEEDED.get(slug, slug)
|
||||
|
||||
|
||||
def is_valid_category(slug: str) -> bool:
|
||||
"""True if `slug` is a valid category slug."""
|
||||
return slug in CATEGORIES
|
||||
|
||||
@@ -76,6 +76,25 @@ class Activity:
|
||||
extraction_confidence: Optional[str] = None # 'high' / 'med' / 'low'
|
||||
needs_review: int = 0
|
||||
|
||||
# Enrichment overlay (applied at build time from data/enrichment.json; see
|
||||
# plan Part B). Bilingual: the EN/source text stays in name/description/...
|
||||
# and the Romanian rendering lands in the *_ro twins. Absent fields leave
|
||||
# the underlying DB value untouched.
|
||||
name_ro: Optional[str] = None
|
||||
description_ro: Optional[str] = None
|
||||
rules_ro: Optional[str] = None
|
||||
variations_ro: Optional[str] = None
|
||||
indoor_outdoor: Optional[str] = None # slug: indoor / outdoor / either
|
||||
space_needed: Optional[str] = None # slug: mic / mediu / mare
|
||||
# Names of fields whose value was INFERRED by enrichment (source was
|
||||
# silent) rather than stated in the source — surfaced as "(estimat)" in UI.
|
||||
estimated_fields: List[str] = field(default_factory=list)
|
||||
|
||||
# Source provenance for the download route + enrichment keying.
|
||||
source_id: Optional[str] = None # e.g. "876d1a2d_marcaje_turistice"
|
||||
source_ids: List[str] = field(default_factory=list) # all source_ids merged
|
||||
chunk_key: Optional[str] = None # e.g. "<source_id>.part01"
|
||||
|
||||
# Database fields
|
||||
id: Optional[int] = None
|
||||
created_at: Optional[str] = None
|
||||
@@ -117,6 +136,16 @@ class Activity:
|
||||
'normalized_name': self.normalized_name or normalize_name(self.name),
|
||||
'extraction_confidence': self.extraction_confidence,
|
||||
'needs_review': self.needs_review,
|
||||
'name_ro': self.name_ro,
|
||||
'description_ro': self.description_ro,
|
||||
'rules_ro': self.rules_ro,
|
||||
'variations_ro': self.variations_ro,
|
||||
'indoor_outdoor': self.indoor_outdoor,
|
||||
'space_needed': self.space_needed,
|
||||
'estimated_fields': json.dumps(self.estimated_fields) if self.estimated_fields else None,
|
||||
'source_id': self.source_id,
|
||||
'source_ids': json.dumps(self.source_ids) if self.source_ids else None,
|
||||
'chunk_key': self.chunk_key,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
@@ -140,6 +169,19 @@ class Activity:
|
||||
elif source_files is None:
|
||||
source_files = []
|
||||
|
||||
# estimated_fields / source_ids: JSON string (DB) or list (in-memory)
|
||||
def _json_list(value):
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
parsed = json.loads(value)
|
||||
return parsed if isinstance(parsed, list) else []
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
return []
|
||||
return list(value) if value else []
|
||||
|
||||
estimated_fields = _json_list(data.get('estimated_fields'))
|
||||
source_ids = _json_list(data.get('source_ids'))
|
||||
|
||||
return cls(
|
||||
id=data.get('id'),
|
||||
name=data.get('name', ''),
|
||||
@@ -170,6 +212,16 @@ class Activity:
|
||||
normalized_name=data.get('normalized_name'),
|
||||
extraction_confidence=data.get('extraction_confidence'),
|
||||
needs_review=data.get('needs_review', 0) or 0,
|
||||
name_ro=data.get('name_ro'),
|
||||
description_ro=data.get('description_ro'),
|
||||
rules_ro=data.get('rules_ro'),
|
||||
variations_ro=data.get('variations_ro'),
|
||||
indoor_outdoor=data.get('indoor_outdoor'),
|
||||
space_needed=data.get('space_needed'),
|
||||
estimated_fields=estimated_fields,
|
||||
source_id=data.get('source_id'),
|
||||
source_ids=source_ids,
|
||||
chunk_key=data.get('chunk_key'),
|
||||
created_at=data.get('created_at'),
|
||||
updated_at=data.get('updated_at')
|
||||
)
|
||||
@@ -210,4 +262,44 @@ class Activity:
|
||||
return self.materials_category
|
||||
elif self.materials_list:
|
||||
return self.materials_list[:100] + "..." if len(self.materials_list) > 100 else self.materials_list
|
||||
return "nu specificate"
|
||||
return "nu specificate"
|
||||
|
||||
# --- Enrichment / bilingual display helpers ------------------------------
|
||||
def get_display_name(self) -> str:
|
||||
"""Romanian name when enriched, else the original."""
|
||||
return self.name_ro or self.name
|
||||
|
||||
def get_display_description(self) -> str:
|
||||
"""Romanian description when enriched, else the original."""
|
||||
return self.description_ro or self.description
|
||||
|
||||
def get_display_rules(self) -> Optional[str]:
|
||||
"""Romanian rules when enriched, else the original."""
|
||||
return self.rules_ro or self.rules
|
||||
|
||||
def get_display_variations(self) -> Optional[str]:
|
||||
"""Romanian variations when enriched, else the original."""
|
||||
return self.variations_ro or self.variations
|
||||
|
||||
def has_translation(self) -> bool:
|
||||
"""True if any Romanian enrichment text is present."""
|
||||
return bool(self.name_ro or self.description_ro
|
||||
or self.rules_ro or self.variations_ro)
|
||||
|
||||
def is_estimated(self, field_name: str) -> bool:
|
||||
"""True if `field_name` was inferred by enrichment (source was silent)."""
|
||||
return field_name in (self.estimated_fields or [])
|
||||
|
||||
def get_indoor_outdoor_display(self) -> Optional[str]:
|
||||
"""RO label for indoor_outdoor, or None when unset."""
|
||||
if not self.indoor_outdoor:
|
||||
return None
|
||||
from app.config_taxonomy import indoor_outdoor_display_name
|
||||
return indoor_outdoor_display_name(self.indoor_outdoor)
|
||||
|
||||
def get_space_needed_display(self) -> Optional[str]:
|
||||
"""RO label for space_needed, or None when unset."""
|
||||
if not self.space_needed:
|
||||
return None
|
||||
from app.config_taxonomy import space_needed_display_name
|
||||
return space_needed_display_name(self.space_needed)
|
||||
@@ -72,6 +72,18 @@ class DatabaseManager:
|
||||
extraction_confidence TEXT,
|
||||
needs_review INTEGER DEFAULT 0,
|
||||
|
||||
-- Enrichment overlay (bilingual + inferred filters; Part B)
|
||||
name_ro TEXT,
|
||||
description_ro TEXT,
|
||||
rules_ro TEXT,
|
||||
variations_ro TEXT,
|
||||
indoor_outdoor TEXT,
|
||||
space_needed TEXT,
|
||||
estimated_fields TEXT,
|
||||
source_id TEXT,
|
||||
source_ids TEXT,
|
||||
chunk_key TEXT,
|
||||
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
@@ -82,6 +94,7 @@ class DatabaseManager:
|
||||
CREATE VIRTUAL TABLE IF NOT EXISTS activities_fts USING fts5(
|
||||
name, description, rules, variations, keywords,
|
||||
materials_list, skills_developed,
|
||||
name_ro, description_ro, rules_ro, variations_ro,
|
||||
content='activities',
|
||||
content_rowid='id'
|
||||
)
|
||||
@@ -106,6 +119,8 @@ class DatabaseManager:
|
||||
"CREATE INDEX IF NOT EXISTS idx_activities_participants ON activities(participants_min, participants_max)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_activities_duration ON activities(duration_min, duration_max)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_activities_normalized_name ON activities(normalized_name)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_activities_indoor_outdoor ON activities(indoor_outdoor)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_activities_space_needed ON activities(space_needed)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_categories_type ON categories(type)"
|
||||
]
|
||||
|
||||
@@ -117,9 +132,11 @@ class DatabaseManager:
|
||||
CREATE TRIGGER IF NOT EXISTS activities_fts_insert AFTER INSERT ON activities
|
||||
BEGIN
|
||||
INSERT INTO activities_fts(rowid, name, description, rules, variations,
|
||||
keywords, materials_list, skills_developed)
|
||||
keywords, materials_list, skills_developed,
|
||||
name_ro, description_ro, rules_ro, variations_ro)
|
||||
VALUES (new.id, new.name, new.description, new.rules, new.variations,
|
||||
new.keywords, new.materials_list, new.skills_developed);
|
||||
new.keywords, new.materials_list, new.skills_developed,
|
||||
new.name_ro, new.description_ro, new.rules_ro, new.variations_ro);
|
||||
END
|
||||
""")
|
||||
|
||||
@@ -127,9 +144,11 @@ class DatabaseManager:
|
||||
CREATE TRIGGER IF NOT EXISTS activities_fts_delete AFTER DELETE ON activities
|
||||
BEGIN
|
||||
INSERT INTO activities_fts(activities_fts, rowid, name, description, rules,
|
||||
variations, keywords, materials_list, skills_developed)
|
||||
variations, keywords, materials_list, skills_developed,
|
||||
name_ro, description_ro, rules_ro, variations_ro)
|
||||
VALUES ('delete', old.id, old.name, old.description, old.rules,
|
||||
old.variations, old.keywords, old.materials_list, old.skills_developed);
|
||||
old.variations, old.keywords, old.materials_list, old.skills_developed,
|
||||
old.name_ro, old.description_ro, old.rules_ro, old.variations_ro);
|
||||
END
|
||||
""")
|
||||
|
||||
@@ -137,13 +156,17 @@ class DatabaseManager:
|
||||
CREATE TRIGGER IF NOT EXISTS activities_fts_update AFTER UPDATE ON activities
|
||||
BEGIN
|
||||
INSERT INTO activities_fts(activities_fts, rowid, name, description, rules,
|
||||
variations, keywords, materials_list, skills_developed)
|
||||
variations, keywords, materials_list, skills_developed,
|
||||
name_ro, description_ro, rules_ro, variations_ro)
|
||||
VALUES ('delete', old.id, old.name, old.description, old.rules,
|
||||
old.variations, old.keywords, old.materials_list, old.skills_developed);
|
||||
old.variations, old.keywords, old.materials_list, old.skills_developed,
|
||||
old.name_ro, old.description_ro, old.rules_ro, old.variations_ro);
|
||||
INSERT INTO activities_fts(rowid, name, description, rules, variations,
|
||||
keywords, materials_list, skills_developed)
|
||||
keywords, materials_list, skills_developed,
|
||||
name_ro, description_ro, rules_ro, variations_ro)
|
||||
VALUES (new.id, new.name, new.description, new.rules, new.variations,
|
||||
new.keywords, new.materials_list, new.skills_developed);
|
||||
new.keywords, new.materials_list, new.skills_developed,
|
||||
new.name_ro, new.description_ro, new.rules_ro, new.variations_ro);
|
||||
END
|
||||
""")
|
||||
|
||||
@@ -210,6 +233,10 @@ class DatabaseManager:
|
||||
('duration', activity.get_duration_display()),
|
||||
('materials', activity.get_materials_display()),
|
||||
('difficulty', activity.difficulty_level),
|
||||
# Enrichment axes — slugs stored as value; UI maps to RO via
|
||||
# DISPLAY_NAMES. Without these the new dropdowns would be empty.
|
||||
('indoor_outdoor', activity.indoor_outdoor),
|
||||
('space_needed', activity.space_needed),
|
||||
]
|
||||
|
||||
for cat_type, cat_value in categories_to_update:
|
||||
@@ -236,6 +263,8 @@ class DatabaseManager:
|
||||
duration_max: Optional[int] = None,
|
||||
materials_category: Optional[str] = None,
|
||||
difficulty_level: Optional[str] = None,
|
||||
indoor_outdoor: Optional[str] = None,
|
||||
space_needed: Optional[str] = None,
|
||||
limit: int = 100) -> List[Dict[str, Any]]:
|
||||
"""Enhanced search with FTS5 and filters"""
|
||||
|
||||
@@ -293,7 +322,15 @@ class DatabaseManager:
|
||||
if difficulty_level:
|
||||
base_query += " AND difficulty_level = ?"
|
||||
params.append(difficulty_level)
|
||||
|
||||
|
||||
if indoor_outdoor:
|
||||
base_query += " AND indoor_outdoor = ?"
|
||||
params.append(indoor_outdoor)
|
||||
|
||||
if space_needed:
|
||||
base_query += " AND space_needed = ?"
|
||||
params.append(space_needed)
|
||||
|
||||
# Add ordering and limit
|
||||
query = f"{base_query} {order_clause} LIMIT ?"
|
||||
params.append(limit)
|
||||
|
||||
@@ -200,7 +200,14 @@ class SearchService:
|
||||
|
||||
elif filter_key == 'difficulty':
|
||||
db_filters['difficulty_level'] = filter_value
|
||||
|
||||
|
||||
elif filter_key == 'indoor_outdoor':
|
||||
# Equality filter on the slug column (mirror difficulty).
|
||||
db_filters['indoor_outdoor'] = filter_value
|
||||
|
||||
elif filter_key == 'space_needed':
|
||||
db_filters['space_needed'] = filter_value
|
||||
|
||||
# Handle any other custom filters
|
||||
else:
|
||||
# Generic filter handling - try to match against keywords or tags
|
||||
|
||||
@@ -705,4 +705,30 @@ body {
|
||||
box-shadow: none;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
}
|
||||
|
||||
/* Enrichment markers (plan Part A7) */
|
||||
.estimated {
|
||||
color: #8a6d3b;
|
||||
font-style: italic;
|
||||
font-size: 0.85em;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.original-text > summary {
|
||||
cursor: pointer;
|
||||
color: #555;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.original-text .original-content {
|
||||
margin-top: 0.75rem;
|
||||
padding-left: 1rem;
|
||||
border-left: 3px solid #e0e0e0;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.download-hint {
|
||||
color: #888;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
@@ -8,13 +8,13 @@
|
||||
<nav class="breadcrumb">
|
||||
<a href="{{ url_for('main.index') }}">Căutare</a>
|
||||
<span class="breadcrumb-separator">»</span>
|
||||
<span class="breadcrumb-current">{{ activity.name }}</span>
|
||||
<span class="breadcrumb-current">{{ activity.get_display_name() }}</span>
|
||||
</nav>
|
||||
|
||||
<!-- Activity header -->
|
||||
<header class="activity-detail-header">
|
||||
<div class="activity-title-section">
|
||||
<h1 class="activity-detail-title">{{ activity.name }}</h1>
|
||||
<h1 class="activity-detail-title">{{ activity.get_display_name() }}</h1>
|
||||
<span class="activity-category-badge">{{ display_names.get(activity.category, activity.category) }}</span>
|
||||
{% if activity.content_type %}
|
||||
<span class="activity-content-type-badge">{{ display_names.get(activity.content_type, activity.content_type) }}</span>
|
||||
@@ -31,27 +31,46 @@
|
||||
|
||||
<!-- Activity content -->
|
||||
<div class="activity-detail-content">
|
||||
<!-- Main description -->
|
||||
<!-- Main description (Romanian-primary, falls back to original) -->
|
||||
<section class="activity-section">
|
||||
<h2 class="section-title">Descriere</h2>
|
||||
<div class="activity-description">{{ activity.description }}</div>
|
||||
<div class="activity-description">{{ activity.get_display_description() }}</div>
|
||||
</section>
|
||||
|
||||
<!-- Rules and variations -->
|
||||
{% if activity.rules %}
|
||||
{% if activity.get_display_rules() %}
|
||||
<section class="activity-section">
|
||||
<h2 class="section-title">Reguli</h2>
|
||||
<div class="activity-rules">{{ activity.rules }}</div>
|
||||
<div class="activity-rules">{{ activity.get_display_rules() }}</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.variations %}
|
||||
{% if activity.get_display_variations() %}
|
||||
<section class="activity-section">
|
||||
<h2 class="section-title">Variații</h2>
|
||||
<div class="activity-variations">{{ activity.variations }}</div>
|
||||
<div class="activity-variations">{{ activity.get_display_variations() }}</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
<!-- Original (pre-translation) text, collapsed by default -->
|
||||
{% if activity.has_translation() %}
|
||||
<details class="activity-section original-text">
|
||||
<summary class="section-title">Text original ({{ display_names.get(activity.language, activity.language or 'sursă') }})</summary>
|
||||
<div class="original-content">
|
||||
<h3 class="metadata-title">{{ activity.name }}</h3>
|
||||
<div class="activity-description">{{ activity.description }}</div>
|
||||
{% if activity.rules %}
|
||||
<h4 class="metadata-title">Reguli</h4>
|
||||
<div class="activity-rules">{{ activity.rules }}</div>
|
||||
{% endif %}
|
||||
{% if activity.variations %}
|
||||
<h4 class="metadata-title">Variații</h4>
|
||||
<div class="activity-variations">{{ activity.variations }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</details>
|
||||
{% endif %}
|
||||
|
||||
<!-- Metadata grid -->
|
||||
<section class="activity-section">
|
||||
<h2 class="section-title">Detalii activitate</h2>
|
||||
@@ -59,21 +78,35 @@
|
||||
{% if activity.get_age_range_display() != "toate vârstele" %}
|
||||
<div class="metadata-card">
|
||||
<h3 class="metadata-title">Grupa de vârstă</h3>
|
||||
<p class="metadata-value">{{ activity.get_age_range_display() }}</p>
|
||||
<p class="metadata-value">{{ activity.get_age_range_display() }}{% if activity.is_estimated('age_group_min') or activity.is_estimated('age_group_max') %} <em class="estimated">(estimat)</em>{% endif %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.get_participants_display() != "orice număr" %}
|
||||
<div class="metadata-card">
|
||||
<h3 class="metadata-title">Participanți</h3>
|
||||
<p class="metadata-value">{{ activity.get_participants_display() }}</p>
|
||||
<p class="metadata-value">{{ activity.get_participants_display() }}{% if activity.is_estimated('participants_min') or activity.is_estimated('participants_max') %} <em class="estimated">(estimat)</em>{% endif %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.get_duration_display() != "durată variabilă" %}
|
||||
<div class="metadata-card">
|
||||
<h3 class="metadata-title">Durata</h3>
|
||||
<p class="metadata-value">{{ activity.get_duration_display() }}</p>
|
||||
<p class="metadata-value">{{ activity.get_duration_display() }}{% if activity.is_estimated('duration_min') or activity.is_estimated('duration_max') %} <em class="estimated">(estimat)</em>{% endif %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.get_indoor_outdoor_display() %}
|
||||
<div class="metadata-card">
|
||||
<h3 class="metadata-title">Interior / exterior</h3>
|
||||
<p class="metadata-value">{{ activity.get_indoor_outdoor_display() }}{% if activity.is_estimated('indoor_outdoor') %} <em class="estimated">(estimat)</em>{% endif %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.get_space_needed_display() %}
|
||||
<div class="metadata-card">
|
||||
<h3 class="metadata-title">Spațiu necesar</h3>
|
||||
<p class="metadata-value">{{ activity.get_space_needed_display() }}{% if activity.is_estimated('space_needed') %} <em class="estimated">(estimat)</em>{% endif %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -125,9 +158,15 @@
|
||||
<h2 class="section-title">Informații sursă</h2>
|
||||
<div class="source-info">
|
||||
{% if activity.source_file %}
|
||||
{% if config.SOURCE_DOWNLOAD_ENABLED %}
|
||||
<p><strong>Fișier sursă:</strong>
|
||||
<a href="{{ url_for('main.source_download', activity_id=activity.id) }}">{{ activity.source_file }}</a>
|
||||
<span class="download-hint">(descarcă)</span></p>
|
||||
{% else %}
|
||||
<p><strong>Fișier sursă:</strong> {{ activity.source_file }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if activity.page_reference %}
|
||||
<p><strong>Referință:</strong> {{ activity.page_reference }}</p>
|
||||
{% endif %}
|
||||
|
||||
@@ -125,6 +125,30 @@
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if filters.indoor_outdoor %}
|
||||
<div class="filter-group">
|
||||
<label for="indoor_outdoor" class="filter-label">Interior / exterior</label>
|
||||
<select name="indoor_outdoor" id="indoor_outdoor" class="filter-select">
|
||||
<option value="">Oriunde</option>
|
||||
{% for io in filters.indoor_outdoor %}
|
||||
<option value="{{ io }}">{{ display_names.get(io, io) }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if filters.space_needed %}
|
||||
<div class="filter-group">
|
||||
<label for="space_needed" class="filter-label">Spațiu necesar</label>
|
||||
<select name="space_needed" id="space_needed" class="filter-select">
|
||||
<option value="">Orice spațiu</option>
|
||||
{% for sp in filters.space_needed %}
|
||||
<option value="{{ sp }}">{{ display_names.get(sp, sp) }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -85,6 +85,28 @@
|
||||
</select>
|
||||
{% endif %}
|
||||
|
||||
{% if filters.indoor_outdoor %}
|
||||
<select name="indoor_outdoor" class="filter-select compact">
|
||||
<option value="">Oriunde</option>
|
||||
{% for io in filters.indoor_outdoor %}
|
||||
<option value="{{ io }}" {% if applied_filters.indoor_outdoor == io %}selected{% endif %}>
|
||||
{{ display_names.get(io, io) }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endif %}
|
||||
|
||||
{% if filters.space_needed %}
|
||||
<select name="space_needed" class="filter-select compact">
|
||||
<option value="">Orice spațiu</option>
|
||||
{% for sp in filters.space_needed %}
|
||||
<option value="{{ sp }}" {% if applied_filters.space_needed == sp %}selected{% endif %}>
|
||||
{{ display_names.get(sp, sp) }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endif %}
|
||||
|
||||
<button type="button" class="btn btn-secondary btn-sm" onclick="clearFilters()">
|
||||
Resetează
|
||||
</button>
|
||||
@@ -128,7 +150,7 @@
|
||||
<header class="activity-header">
|
||||
<h3 class="activity-title">
|
||||
<a href="{{ url_for('main.activity_detail', activity_id=activity.id) }}">
|
||||
{{ activity.name }}
|
||||
{{ activity.get_display_name() }}
|
||||
</a>
|
||||
</h3>
|
||||
<span class="activity-category">{{ display_names.get(activity.category, activity.category) }}</span>
|
||||
@@ -138,24 +160,36 @@
|
||||
</header>
|
||||
|
||||
<div class="activity-content">
|
||||
<p class="activity-description">{{ activity.description }}</p>
|
||||
|
||||
<p class="activity-description">{{ activity.get_display_description() }}</p>
|
||||
|
||||
<div class="activity-metadata">
|
||||
{% if activity.get_age_range_display() != "toate vârstele" %}
|
||||
<span class="metadata-item">
|
||||
<strong>Vârsta:</strong> {{ activity.get_age_range_display() }}
|
||||
<strong>Vârsta:</strong> {{ activity.get_age_range_display() }}{% if activity.is_estimated('age_group_min') or activity.is_estimated('age_group_max') %} <em class="estimated">(estimat)</em>{% endif %}
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.get_participants_display() != "orice număr" %}
|
||||
<span class="metadata-item">
|
||||
<strong>Participanți:</strong> {{ activity.get_participants_display() }}
|
||||
<strong>Participanți:</strong> {{ activity.get_participants_display() }}{% if activity.is_estimated('participants_min') or activity.is_estimated('participants_max') %} <em class="estimated">(estimat)</em>{% endif %}
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.get_duration_display() != "durată variabilă" %}
|
||||
<span class="metadata-item">
|
||||
<strong>Durata:</strong> {{ activity.get_duration_display() }}
|
||||
<strong>Durata:</strong> {{ activity.get_duration_display() }}{% if activity.is_estimated('duration_min') or activity.is_estimated('duration_max') %} <em class="estimated">(estimat)</em>{% endif %}
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.get_indoor_outdoor_display() %}
|
||||
<span class="metadata-item">
|
||||
<strong>Loc:</strong> {{ activity.get_indoor_outdoor_display() }}{% if activity.is_estimated('indoor_outdoor') %} <em class="estimated">(estimat)</em>{% endif %}
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
{% if activity.get_space_needed_display() %}
|
||||
<span class="metadata-item">
|
||||
<strong>Spațiu:</strong> {{ activity.get_space_needed_display() }}{% if activity.is_estimated('space_needed') %} <em class="estimated">(estimat)</em>{% endif %}
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
@@ -168,7 +202,11 @@
|
||||
|
||||
{% if activity.source_file %}
|
||||
<div class="activity-source">
|
||||
{% if config.SOURCE_DOWNLOAD_ENABLED %}
|
||||
<small>Sursă: <a href="{{ url_for('main.source_download', activity_id=activity.id) }}">{{ activity.source_file }}</a></small>
|
||||
{% else %}
|
||||
<small>Sursă: {{ activity.source_file }}</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -3,20 +3,27 @@ Flask routes for INDEX-SISTEM-JOCURI v2.0
|
||||
Clean, minimalist web interface with dynamic filters
|
||||
"""
|
||||
|
||||
from flask import Blueprint, request, render_template, jsonify, current_app
|
||||
from flask import (
|
||||
Blueprint, request, render_template, jsonify, current_app,
|
||||
send_from_directory,
|
||||
)
|
||||
from app.models.database import DatabaseManager
|
||||
from app.models.activity import Activity
|
||||
from app.services.search import SearchService
|
||||
from app.config_taxonomy import CATEGORIES, CONTENT_TYPES
|
||||
import os
|
||||
from pathlib import Path
|
||||
from app.config_taxonomy import (
|
||||
CATEGORIES, CONTENT_TYPES, INDOOR_OUTDOOR, SPACE_NEEDED,
|
||||
)
|
||||
|
||||
bp = Blueprint('main', __name__)
|
||||
|
||||
# Slug -> Romanian display name. Category and content_type slugs never collide,
|
||||
# so a single flat map is enough for the UI filter labels.
|
||||
# Slug -> Romanian display name. Category, content_type, indoor_outdoor and
|
||||
# space_needed slugs never collide, so a single flat map is enough for the UI
|
||||
# filter labels.
|
||||
LANGUAGE_NAMES = {'ro': 'Română', 'en': 'Engleză'}
|
||||
DISPLAY_NAMES = {**CATEGORIES, **CONTENT_TYPES, **LANGUAGE_NAMES}
|
||||
DISPLAY_NAMES = {
|
||||
**CATEGORIES, **CONTENT_TYPES, **INDOOR_OUTDOOR, **SPACE_NEEDED,
|
||||
**LANGUAGE_NAMES,
|
||||
}
|
||||
|
||||
# Initialize database manager (will be configured in application factory)
|
||||
def get_db_manager():
|
||||
@@ -138,6 +145,44 @@ def activity_detail(activity_id):
|
||||
print(f"Error loading activity {activity_id}: {e}")
|
||||
return render_template('404.html'), 404
|
||||
|
||||
@bp.route('/source/<int:activity_id>')
|
||||
def source_download(activity_id):
|
||||
"""Download the original source file for an activity (plan A6).
|
||||
|
||||
Shipped DARK: returns 404 unless SOURCE_DOWNLOAD_ENABLED is set (copyright
|
||||
exposure — the user opts in). Resolves the activity's `source_file` under
|
||||
CORPUS_DIR. send_from_directory does the safe-join and blocks traversal;
|
||||
web-mirror / extension-less sources that are not real files 404 gracefully.
|
||||
"""
|
||||
if not current_app.config.get('SOURCE_DOWNLOAD_ENABLED', False):
|
||||
return render_template('404.html'), 404
|
||||
try:
|
||||
db = get_db_manager()
|
||||
activity_data = db.get_activity_by_id(activity_id)
|
||||
if not activity_data:
|
||||
return render_template('404.html'), 404
|
||||
|
||||
source_file = (activity_data.get('source_file') or '').strip()
|
||||
if not source_file:
|
||||
return render_template('404.html'), 404
|
||||
|
||||
corpus_dir = current_app.config.get('CORPUS_DIR')
|
||||
if not corpus_dir:
|
||||
return render_template('404.html'), 404
|
||||
try:
|
||||
# send_from_directory rejects path traversal and missing files with
|
||||
# a 404 (NotFound) — no manual safe_join needed.
|
||||
return send_from_directory(
|
||||
corpus_dir, source_file, as_attachment=True
|
||||
)
|
||||
except Exception:
|
||||
# Missing file / web-mirror source with no on-disk original.
|
||||
return render_template('404.html'), 404
|
||||
except Exception as e:
|
||||
print(f"Source download error for {activity_id}: {e}")
|
||||
return render_template('404.html'), 404
|
||||
|
||||
|
||||
@bp.route('/health')
|
||||
def health_check():
|
||||
"""Health check endpoint for Docker"""
|
||||
|
||||
Reference in New Issue
Block a user