Skip to content

Commit b1dc102

Browse files
Merge pull request #612 from open5e/staging
Release 1.7.0 PR
2 parents 36a0baa + 13a1a13 commit b1dc102

File tree

119 files changed

+49788
-54311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+49788
-54311
lines changed

.github/workflows/rdme-openapi.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,24 @@ jobs:
1414
rdme-openapi:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Check out repo 📚
18-
uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.11"
21+
22+
- name: install pipenv
23+
run: |
24+
pip install pipenv
25+
26+
- name: install dependencies
27+
run: |
28+
pipenv install
29+
30+
- name: build oas file
31+
run: |
32+
pipenv run python manage.py spectacular --file openapi-schema.yml
1933
2034
- name: Run `openapi` command for v1🚀
2135
uses: readmeio/rdme@v8
2236
with:
23-
rdme: openapi openapi-schema.yml --key=${{ secrets.README_API_KEY }} --id=641f6d9e0ffbcd06c0e7343c
37+
rdme: openapi openapi-schema.yml --key=${{ secrets.README_API_KEY }} --id=6715b7fb7960ee004eb4a8cf

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ server/whoosh_index/
1818
# pyenv env file
1919
.python-version
2020

21-
api/tests/approved_files/*.recieved.*
21+
api/tests/approved_files/*.recieved.*
22+
openapi-schema.yml

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ newrelic = "*"
1212
requests = "*"
1313
whitenoise = "*"
1414
gunicorn = "*"
15+
drf-spectacular = "*"
1516

1617
[dev-packages]
1718
pytest = "*"

Pipfile.lock

Lines changed: 475 additions & 216 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ You can use our Dockerfile as inspiration, but it likely will not work without s
114114

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

120120
# Contributing
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.2 on 2024-10-23 13:28
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='document',
15+
name='v2_related_key',
16+
field=models.TextField(help_text='Key mapping for v2 document.', null=True),
17+
),
18+
]

api/models/models.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import uuid
33

44
from django.db import models
5-
5+
from django.urls import reverse
6+
from django.shortcuts import redirect
7+
from django.template.defaultfilters import slugify
8+
#from api_v2 import urls as urls_v2
69

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

63+
v2_related_key = models.TextField(
64+
null=True,
65+
help_text='Key mapping for v2 document.'
66+
)
67+
6068
@staticmethod
6169
def plural_str() -> str:
6270
"""Return a string specifying the plural name of this model."""
@@ -97,6 +105,54 @@ def document__license_url(self):
97105
def document__url(self):
98106
return self.document.url
99107

108+
def v2_converted_path(self):
109+
# Returns a text string that is the theoretical v2 object url related
110+
# to a given object. Does not guarantee that an object exists at that
111+
# url.
112+
113+
url_lookup = { #Looks up v1 object type to relevant v2 url.
114+
"Spell":"spell",
115+
"Monster":"creature",
116+
"Background":"background",
117+
"Plane":"environments",
118+
"Section":"rule",
119+
"Feat":"feat",
120+
"Condition":"condition",
121+
"Race":"race",
122+
"CharClass":"class",
123+
"MagicItem":"item",
124+
"Weapon":"item",
125+
"Armor":"item"
126+
}
127+
128+
exclude_doc_key = ['Condition']
129+
130+
a5e_doc_lookup = {
131+
"Monster":"mmenag",
132+
"MagicItem":"a5e-ddg",
133+
"Spell":"a5e-ag",
134+
"Background":"a5e-ag",
135+
"Plane":"a5e-ag",
136+
"Section":"a5e-ag",
137+
"Feat":"a5e-ag",
138+
"Condition":"a5e-ag",
139+
"Race":"a5e-ag",
140+
"CharClass":"a5e-ag",
141+
"Weapon":"a5e-ag",
142+
"Armor":"a5e-ag"
143+
}
144+
145+
resource = url_lookup[self.__class__.__name__]+"-detail"
146+
v2_document = self.document.v2_related_key
147+
if v2_document=="a5e":
148+
v2_document = a5e_doc_lookup[self.__class__.__name__]
149+
converted_name=slugify(self.name)
150+
151+
if self.__class__.__name__ in exclude_doc_key:
152+
return reverse(resource,kwargs={'pk':f"{converted_name}"})
153+
return redirect(reverse(resource,kwargs={'pk':f"{v2_document}_{converted_name}"})).url
154+
155+
100156
class Meta:
101157
abstract = True
102158

api/serializers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class Meta:
5454
'organization',
5555
'version',
5656
'copyright',
57-
'license_url',)
57+
'license_url',
58+
'v2_related_key')
5859

5960
class GroupSerializer(serializers.HyperlinkedModelSerializer):
6061
class Meta:
@@ -72,6 +73,7 @@ class MonsterSerializer(DynamicFieldsHyperlinkedModelSerializer):
7273
legendary_actions = serializers.SerializerMethodField()
7374
special_abilities = serializers.SerializerMethodField()
7475
img_main = serializers.SerializerMethodField()
76+
v2_converted_path = serializers.SerializerMethodField()
7577

7678
def get_img_main(self, monster):
7779
request = self.context.get('request')
@@ -106,6 +108,9 @@ def get_legendary_actions(self, monster):
106108
def get_special_abilities(self, monster):
107109
return monster.special_abilities()
108110

111+
def get_v2_converted_path(self, monster):
112+
return monster.v2_converted_path()
113+
109114

110115
class Meta:
111116
model = models.Monster
@@ -158,7 +163,8 @@ class Meta:
158163
'document__slug',
159164
'document__title',
160165
'document__license_url',
161-
'document__url'
166+
'document__url',
167+
'v2_converted_path'
162168
)
163169

164170
class SpellSerializer(DynamicFieldsModelSerializer):

api/tests/approved_files/TestAPIRoot.test_documents.approved.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"slug": "o5e",
1414
"title": "Open5e Original Content",
1515
"url": "open5e.com",
16+
"v2_related_key": "open5e",
1617
"version": "1.0"
1718
},
1819
{
@@ -25,6 +26,7 @@
2526
"slug": "wotc-srd",
2627
"title": "5e Core Rules",
2728
"url": "http://dnd.wizards.com/articles/features/systems-reference-document-srd",
29+
"v2_related_key": "srd",
2830
"version": "5.1"
2931
},
3032
{
@@ -37,6 +39,7 @@
3739
"slug": "tob",
3840
"title": "Tome of Beasts",
3941
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-for-5th-edition-print/",
42+
"v2_related_key": "tob",
4043
"version": "1.0"
4144
},
4245
{
@@ -49,6 +52,7 @@
4952
"slug": "cc",
5053
"title": "Creature Codex",
5154
"url": "https://koboldpress.com/kpstore/product/creature-codex-for-5th-edition-dnd/",
55+
"v2_related_key": "ccdx",
5256
"version": "1.0"
5357
},
5458
{
@@ -61,6 +65,7 @@
6165
"slug": "tob2",
6266
"title": "Tome of Beasts 2",
6367
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-2-for-5th-edition/",
68+
"v2_related_key": "tob2",
6469
"version": "1.0"
6570
},
6671
{
@@ -73,6 +78,7 @@
7378
"slug": "dmag",
7479
"title": "Deep Magic 5e",
7580
"url": "https://koboldpress.com/kpstore/product/deep-magic-for-5th-edition-hardcover/",
81+
"v2_related_key": "deepm",
7682
"version": "1.0"
7783
},
7884
{
@@ -85,6 +91,7 @@
8591
"slug": "menagerie",
8692
"title": "Level Up Advanced 5e Monstrous Menagerie",
8793
"url": "https://www.levelup5e.com",
94+
"v2_related_key": "mmenag",
8895
"version": "1.0"
8996
},
9097
{
@@ -97,6 +104,7 @@
97104
"slug": "tob3",
98105
"title": "Tome of Beasts 3",
99106
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-3-for-5th-edition/",
107+
"v2_related_key": "tob3",
100108
"version": "1.0"
101109
},
102110
{
@@ -109,6 +117,7 @@
109117
"slug": "a5e",
110118
"title": "Level Up Advanced 5e",
111119
"url": "https://a5esrd.com/a5esrd",
120+
"v2_related_key": "a5e",
112121
"version": "1.0"
113122
},
114123
{
@@ -121,6 +130,7 @@
121130
"slug": "kp",
122131
"title": "Kobold Press Compilation",
123132
"url": "https://koboldpress.com",
133+
"v2_related_key": "kp",
124134
"version": "1.0"
125135
},
126136
{
@@ -133,6 +143,7 @@
133143
"slug": "dmag-e",
134144
"title": "Deep Magic Extended",
135145
"url": "https://koboldpress.com",
146+
"v2_related_key": "deepmx",
136147
"version": "1.0"
137148
},
138149
{
@@ -145,6 +156,7 @@
145156
"slug": "warlock",
146157
"title": "Warlock Archives",
147158
"url": "https://koboldpress.com/kpstore/product-category/all-products/warlock-5th-edition-dnd/",
159+
"v2_related_key": "wz",
148160
"version": "1.0"
149161
},
150162
{
@@ -157,6 +169,7 @@
157169
"slug": "vom",
158170
"title": "Vault of Magic",
159171
"url": "https://koboldpress.com/kpstore/product/vault-of-magic-for-5th-edition/",
172+
"v2_related_key": "vom",
160173
"version": "1.0"
161174
},
162175
{
@@ -169,6 +182,7 @@
169182
"slug": "toh",
170183
"title": "Tome of Heroes",
171184
"url": "https://koboldpress.com/kpstore/product/tome-of-heroes-for-5th-edition/",
185+
"v2_related_key": "toh",
172186
"version": "1.0"
173187
},
174188
{
@@ -181,6 +195,7 @@
181195
"slug": "taldorei",
182196
"title": "Critical Role: Tal\u2019Dorei Campaign Setting",
183197
"url": "https://https://greenronin.com/blog/2017/09/25/ronin-round-table-integrating-wizards-5e-adventures-with-the-taldorei-campaign-setting/",
198+
"v2_related_key": "tdcs",
184199
"version": "1.0"
185200
},
186201
{
@@ -193,6 +208,7 @@
193208
"slug": "blackflag",
194209
"title": "Black Flag SRD",
195210
"url": "https://koboldpress.com/black-flag-reference-document/",
211+
"v2_related_key": "bfrd",
196212
"version": "0.2"
197213
},
198214
{
@@ -205,6 +221,7 @@
205221
"slug": "tob-2023",
206222
"title": "Tome of Beasts 2023",
207223
"url": "https://koboldpress.com/kpstore/product/tome-of-beasts-1-2023-edition/",
224+
"v2_related_key": "tob-2023",
208225
"version": "1.0"
209226
}
210227
]

0 commit comments

Comments
 (0)