1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/utils/urls.py

27 lines
829 B
Python
Raw Permalink Normal View History

2021-09-26 19:02:25 +02:00
from typing import Dict
from characters.models import Character
2021-10-03 16:57:06 +02:00
from factions.models import Faction
2021-09-26 19:02:25 +02:00
from locations.models import Location
from loot.models import Loot
2021-10-03 16:57:06 +02:00
from notes.models import Note
2021-09-26 19:02:25 +02:00
2023-04-25 22:16:28 +02:00
def name2url() -> dict[str, str]:
2021-09-26 19:02:25 +02:00
data = {}
objects = []
2022-07-05 18:37:21 +02:00
objects.extend(Character.objects.all())
objects.extend(Location.objects.all())
objects.extend(Loot.objects.all())
objects.extend(Faction.objects.all())
objects.extend(Note.objects.all())
for object in objects:
data[object.name] = (object.get_absolute_url(), object)
2022-07-05 18:37:21 +02:00
if object.aliases:
for alias in object.aliases:
data[alias] = (object.get_absolute_url(), object)
# longer replacements first
data = {k: v for k, v in sorted(data.items(), key=lambda item: -len(item[0]))}
2021-09-26 19:02:25 +02:00
return data