Skip to content

Commit

Permalink
Merge pull request #612 from open5e/staging
Browse files Browse the repository at this point in the history
Release 1.7.0 PR
  • Loading branch information
augustjohnson authored Nov 23, 2024
2 parents 36a0baa + 13a1a13 commit b1dc102
Show file tree
Hide file tree
Showing 119 changed files with 49,788 additions and 54,311 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/rdme-openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ jobs:
rdme-openapi:
runs-on: ubuntu-latest
steps:
- name: Check out repo 📚
uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: install pipenv
run: |
pip install pipenv
- name: install dependencies
run: |
pipenv install
- name: build oas file
run: |
pipenv run python manage.py spectacular --file openapi-schema.yml
- name: Run `openapi` command for v1🚀
uses: readmeio/rdme@v8
with:
rdme: openapi openapi-schema.yml --key=${{ secrets.README_API_KEY }} --id=641f6d9e0ffbcd06c0e7343c
rdme: openapi openapi-schema.yml --key=${{ secrets.README_API_KEY }} --id=6715b7fb7960ee004eb4a8cf
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ server/whoosh_index/
# pyenv env file
.python-version

api/tests/approved_files/*.recieved.*
api/tests/approved_files/*.recieved.*
openapi-schema.yml
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ newrelic = "*"
requests = "*"
whitenoise = "*"
gunicorn = "*"
drf-spectacular = "*"

[dev-packages]
pytest = "*"
Expand Down
691 changes: 475 additions & 216 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ You can use our Dockerfile as inspiration, but it likely will not work without s

After completing a build, you can generate an OAS file to be used by another application.
```bash
pipenv run ./manage.py generateschema --generator_class api.schema_generator.Open5eSchemaGenerator > openapi-schema.yml` to build the OAS file.
pipenv run python manage.py spectacular --color --file openapi-schema.yml` to build the OAS file.
```

# Contributing
Expand Down
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
Loading

0 comments on commit b1dc102

Please sign in to comment.