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
|
|
|
|
|
|
|
|
|
|
|
def name2url() -> Dict[str, str]:
|
|
|
|
data = {}
|
2022-11-25 19:43:58 +01:00
|
|
|
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:
|
2022-11-25 19:43:58 +01:00
|
|
|
data[object.name] = (object.get_absolute_url(), object)
|
2022-07-05 18:37:21 +02:00
|
|
|
if object.aliases:
|
|
|
|
for alias in object.aliases:
|
2022-11-25 19:43:58 +01:00
|
|
|
data[alias] = (object.get_absolute_url(), object)
|
2022-04-10 17:15:03 +02:00
|
|
|
|
|
|
|
# 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
|