Skip to content

Commit

Permalink
Merge pull request #594 from open5e/442-way-to-compare-if-a-v1-data-i…
Browse files Browse the repository at this point in the history
…tem-has-not-been-converted-to-v2

442 way to compare if a v1 data item has not been converted to v2
  • Loading branch information
augustjohnson authored Oct 24, 2024
2 parents ed28901 + 5a7321a commit d997b3a
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 20 deletions.
18 changes: 18 additions & 0 deletions api/migrations/0002_document_v2_related_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2024-10-23 13:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='document',
name='v2_related_key',
field=models.TextField(help_text='Key mapping for v2 document.', null=True),
),
]
58 changes: 57 additions & 1 deletion api/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import uuid

from django.db import models

from django.urls import reverse
from django.shortcuts import redirect
from django.template.defaultfilters import slugify
#from api_v2 import urls as urls_v2

class Manifest(models.Model):
"""A Manifest contains a hash based on the contents of a file.
Expand Down Expand Up @@ -57,6 +60,11 @@ class Document(models.Model):
default="http://open5e.com/legal",
help_text='URL reference for the license.')

v2_related_key = models.TextField(
null=True,
help_text='Key mapping for v2 document.'
)

@staticmethod
def plural_str() -> str:
"""Return a string specifying the plural name of this model."""
Expand Down Expand Up @@ -97,6 +105,54 @@ def document__license_url(self):
def document__url(self):
return self.document.url

def v2_converted_path(self):
# Returns a text string that is the theoretical v2 object url related
# to a given object. Does not guarantee that an object exists at that
# url.

url_lookup = { #Looks up v1 object type to relevant v2 url.
"Spell":"spell",
"Monster":"creature",
"Background":"background",
"Plane":"environments",
"Section":"rule",
"Feat":"feat",
"Condition":"condition",
"Race":"race",
"CharClass":"class",
"MagicItem":"item",
"Weapon":"item",
"Armor":"item"
}

exclude_doc_key = ['Condition']

a5e_doc_lookup = {
"Monster":"mmenag",
"MagicItem":"a5e-ddg",
"Spell":"a5e-ag",
"Background":"a5e-ag",
"Plane":"a5e-ag",
"Section":"a5e-ag",
"Feat":"a5e-ag",
"Condition":"a5e-ag",
"Race":"a5e-ag",
"CharClass":"a5e-ag",
"Weapon":"a5e-ag",
"Armor":"a5e-ag"
}

resource = url_lookup[self.__class__.__name__]+"-detail"
v2_document = self.document.v2_related_key
if v2_document=="a5e":
v2_document = a5e_doc_lookup[self.__class__.__name__]
converted_name=slugify(self.name)

if self.__class__.__name__ in exclude_doc_key:
return reverse(resource,kwargs={'pk':f"{converted_name}"})
return redirect(reverse(resource,kwargs={'pk':f"{v2_document}_{converted_name}"})).url


class Meta:
abstract = True

Expand Down
10 changes: 8 additions & 2 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class Meta:
'organization',
'version',
'copyright',
'license_url',)
'license_url',
'v2_related_key')

class GroupSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
Expand All @@ -72,6 +73,7 @@ class MonsterSerializer(DynamicFieldsHyperlinkedModelSerializer):
legendary_actions = serializers.SerializerMethodField()
special_abilities = serializers.SerializerMethodField()
img_main = serializers.SerializerMethodField()
v2_converted_path = serializers.SerializerMethodField()

def get_img_main(self, monster):
request = self.context.get('request')
Expand Down Expand Up @@ -106,6 +108,9 @@ def get_legendary_actions(self, monster):
def get_special_abilities(self, monster):
return monster.special_abilities()

def get_v2_converted_path(self, monster):
return monster.v2_converted_path()


class Meta:
model = models.Monster
Expand Down Expand Up @@ -158,7 +163,8 @@ class Meta:
'document__slug',
'document__title',
'document__license_url',
'document__url'
'document__url',
'v2_converted_path'
)

class SpellSerializer(DynamicFieldsModelSerializer):
Expand Down
17 changes: 17 additions & 0 deletions api/tests/approved_files/TestAPIRoot.test_documents.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"slug": "o5e",
"title": "Open5e Original Content",
"url": "open5e.com",
"v2_related_key": "open5e",
"version": "1.0"
},
{
Expand All @@ -25,6 +26,7 @@
"slug": "wotc-srd",
"title": "5e Core Rules",
"url": "http://dnd.wizards.com/articles/features/systems-reference-document-srd",
"v2_related_key": "srd",
"version": "5.1"
},
{
Expand All @@ -37,6 +39,7 @@
"slug": "tob",
"title": "Tome of Beasts",
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-for-5th-edition-print/",
"v2_related_key": "tob",
"version": "1.0"
},
{
Expand All @@ -49,6 +52,7 @@
"slug": "cc",
"title": "Creature Codex",
"url": "https://koboldpress.com/kpstore/product/creature-codex-for-5th-edition-dnd/",
"v2_related_key": "ccdx",
"version": "1.0"
},
{
Expand All @@ -61,6 +65,7 @@
"slug": "tob2",
"title": "Tome of Beasts 2",
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-2-for-5th-edition/",
"v2_related_key": "tob2",
"version": "1.0"
},
{
Expand All @@ -73,6 +78,7 @@
"slug": "dmag",
"title": "Deep Magic 5e",
"url": "https://koboldpress.com/kpstore/product/deep-magic-for-5th-edition-hardcover/",
"v2_related_key": "deepm",
"version": "1.0"
},
{
Expand All @@ -85,6 +91,7 @@
"slug": "menagerie",
"title": "Level Up Advanced 5e Monstrous Menagerie",
"url": "https://www.levelup5e.com",
"v2_related_key": "mmenag",
"version": "1.0"
},
{
Expand All @@ -97,6 +104,7 @@
"slug": "tob3",
"title": "Tome of Beasts 3",
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-3-for-5th-edition/",
"v2_related_key": "tob3",
"version": "1.0"
},
{
Expand All @@ -109,6 +117,7 @@
"slug": "a5e",
"title": "Level Up Advanced 5e",
"url": "https://a5esrd.com/a5esrd",
"v2_related_key": "a5e",
"version": "1.0"
},
{
Expand All @@ -121,6 +130,7 @@
"slug": "kp",
"title": "Kobold Press Compilation",
"url": "https://koboldpress.com",
"v2_related_key": "kp",
"version": "1.0"
},
{
Expand All @@ -133,6 +143,7 @@
"slug": "dmag-e",
"title": "Deep Magic Extended",
"url": "https://koboldpress.com",
"v2_related_key": "deepmx",
"version": "1.0"
},
{
Expand All @@ -145,6 +156,7 @@
"slug": "warlock",
"title": "Warlock Archives",
"url": "https://koboldpress.com/kpstore/product-category/all-products/warlock-5th-edition-dnd/",
"v2_related_key": "wz",
"version": "1.0"
},
{
Expand All @@ -157,6 +169,7 @@
"slug": "vom",
"title": "Vault of Magic",
"url": "https://koboldpress.com/kpstore/product/vault-of-magic-for-5th-edition/",
"v2_related_key": "vom",
"version": "1.0"
},
{
Expand All @@ -169,6 +182,7 @@
"slug": "toh",
"title": "Tome of Heroes",
"url": "https://koboldpress.com/kpstore/product/tome-of-heroes-for-5th-edition/",
"v2_related_key": "toh",
"version": "1.0"
},
{
Expand All @@ -181,6 +195,7 @@
"slug": "taldorei",
"title": "Critical Role: Tal\u2019Dorei Campaign Setting",
"url": "https://https://greenronin.com/blog/2017/09/25/ronin-round-table-integrating-wizards-5e-adventures-with-the-taldorei-campaign-setting/",
"v2_related_key": "tdcs",
"version": "1.0"
},
{
Expand All @@ -193,6 +208,7 @@
"slug": "blackflag",
"title": "Black Flag SRD",
"url": "https://koboldpress.com/black-flag-reference-document/",
"v2_related_key": "bfrd",
"version": "0.2"
},
{
Expand All @@ -205,6 +221,7 @@
"slug": "tob-2023",
"title": "Tome of Beasts 2023",
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-1-2023-edition/",
"v2_related_key": "tob-2023",
"version": "1.0"
}
]
Expand Down
3 changes: 2 additions & 1 deletion data/v1/a5e/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://a5esrd.com/a5esrd",
"copyright": "This work includes material taken from the A5E System Reference Document (A5ESRD) by EN Publishing and available at A5ESRD.com, based on Level Up: Advanced 5th Edition, available at www.levelup5e.com. The A5ESRD is licensed under the Creative Commons Attribution 4.0 International License available at https://creativecommons.org/licenses/by/4.0/legalcode.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "a5e"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/blackflag/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "0.2",
"url": "https://koboldpress.com/black-flag-reference-document/",
"copyright": "ORC NOTICE: This product is licensed under the ORC License, located at the Library of Congress at TX 9-307-067, and available online at various locations including koboldpress.com/orclicense and others. All warranties are disclaimed as set forth therein.",
"license_url": "https://paizo.com/orclicense"
"license_url": "https://paizo.com/orclicense",
"v2_related_key": "bfrd"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/cc/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://koboldpress.com/kpstore/product/creature-codex-for-5th-edition-dnd/",
"copyright": "Creature Codex. © 2018 Open Design LLC; Authors Wolfgang Baur, Dan Dillon, Richard Green, James Haeck, Chris Harris, Jeremy Hochhalter, James Introcaso, Chris Lockey, Shawn Merwin, and Jon Sawatsky.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "ccdx"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/dmag-e/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://koboldpress.com",
"copyright": "© Open Design LLC",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "deepmx"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/dmag/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://koboldpress.com/kpstore/product/deep-magic-for-5th-edition-hardcover/",
"copyright": "Deep Magic for 5th Edition © 2020 Open Design LLC; Authors: Dan Dillon, Chris Harris, and Jeff Lee.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "deepm"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/kp/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://koboldpress.com",
"copyright": "© Open Design LLC",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "kp"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/menagerie/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://www.levelup5e.com",
"copyright": "Level Up: Advanced 5th Edition Monstrous Menagerie. Copyright 2021, EN Publishing.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "mmenag"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/o5e/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "open5e.com",
"copyright": "Open5e.com Copyright 2019.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "open5e"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/taldorei/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://https://greenronin.com/blog/2017/09/25/ronin-round-table-integrating-wizards-5e-adventures-with-the-taldorei-campaign-setting/",
"copyright": "Critical Role: Tal’Dorei Campaign Setting is ©2017 Green Ronin Publishing, LLC. All rights reserved.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "tdcs"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/tob-2023/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-1-2023-edition/",
"copyright": "Tome of Beasts. 2023 Open Design LLC. All rights reserved.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "tob-2023"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/tob/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-for-5th-edition-print/",
"copyright": "Tome of Beasts. Copyright 2016, Open Design; Authors Chris Harris, Dan Dillon, Rodrigo Garcia Carmona, and Wolfgang Baur.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "tob"
}
}
]
3 changes: 2 additions & 1 deletion data/v1/tob2/Document.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"version": "1.0",
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-2-for-5th-edition/",
"copyright": "Tome of Beasts 2. Copyright 2020 Open Design LLC; Authors Wolfgang Baur, Celeste Conowitch, Darrin Drader, James Introcaso, Philip Larwood, Jeff Lee, Kelly Pawlik, Brian Suskind, Mike Welham.",
"license_url": "http://open5e.com/legal"
"license_url": "http://open5e.com/legal",
"v2_related_key": "tob2"
}
}
]
Loading

0 comments on commit d997b3a

Please sign in to comment.