Spaces:
Running
Running
| """Safety / rating policy — the single source of truth for rating conversions. | |
| Historically three separate mappings lived in this module and tag_warehouse | |
| (UI order, tag order, UI->tag ceiling). They are unified here; tag_warehouse | |
| re-exports the canonical constants for backwards compatibility. | |
| """ | |
| SAFETY_TAG_MAP = { | |
| "pg": "safe", | |
| "pg13": "safe", | |
| "pg16": "sensitive", | |
| "r": "nsfw", | |
| "r+": "explicit", | |
| } | |
| # UI-facing rating levels (what the user picks in the rating dropdown). | |
| UI_RATING_ORDER = {"pg": 0, "pg13": 1, "pg16": 2, "r": 3, "r+": 4} | |
| # Pool / tag entry rating levels (the "rating" field of every pool entry). | |
| TAG_RATING_ORDER = {"sfw": 0, "suggestive": 1, "nsfw": 2, "explicit": 3} | |
| # The highest tag-pool rating allowed under a given UI rating. | |
| UI_TO_TAG_CEILING = { | |
| "pg": "sfw", | |
| "pg13": "sfw", | |
| "pg16": "suggestive", | |
| "r": "nsfw", | |
| "r+": "explicit", | |
| } | |
| def get_safety_tag(rating: str) -> str: | |
| return SAFETY_TAG_MAP.get(rating, "safe") | |
| def ui_rating_to_tag_ceiling(user_rating: str) -> str: | |
| """Map a UI rating (pg/pg13/pg16/r/r+) to the max tag-pool rating allowed.""" | |
| return UI_TO_TAG_CEILING.get(user_rating, "sfw") | |
| def is_tag_allowed(tag_rating: str, user_rating: str) -> bool: | |
| tag_level = TAG_RATING_ORDER.get(tag_rating, 0) | |
| ceiling_level = TAG_RATING_ORDER.get(ui_rating_to_tag_ceiling(user_rating), 0) | |
| return tag_level <= ceiling_level | |