Skip to content

Commit

Permalink
Adding new format for import.
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Oct 6, 2023
1 parent 1577c84 commit 5d99ae7
Show file tree
Hide file tree
Showing 66 changed files with 197,905 additions and 3 deletions.
36 changes: 33 additions & 3 deletions api_v2/management/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.apps import AppConfig

from api_v2.models import *

from api import models as v1

class Command(BaseCommand):
"""Implementation for the `manage.py `export` subcommand."""
Expand All @@ -27,6 +27,7 @@ def add_arguments(self, parser):
help="Directory to write files to.")

def handle(self, *args, **options) -> None:

self.stdout.write('Checking if directory exists.')
if os.path.exists(options['dir']) and os.path.isdir(options['dir']):
self.stdout.write('Directory {} exists.'.format(options['dir']))
Expand All @@ -35,6 +36,37 @@ def handle(self, *args, **options) -> None:
'Directory {} does not exist.'.format(options['dir'])))
exit(0)

app_models = apps.get_models()

# Start v1 output.
v1documents = v1.Document.objects.all()
for v1doc in v1documents:
v1docq = v1.Document.objects.filter(slug=v1doc.slug).order_by('pk')
v1doc_path = get_filepath_by_model(
"Document",
"api",
doc_key=v1doc.slug,
base_path=options['dir'])
write_queryset_data(v1doc_path, v1docq)

for model in app_models:
SKIPPED_MODEL_NAMES = ['Document', 'Manifest','MonsterSpell']
if model._meta.app_label == 'api' and model.__name__ not in SKIPPED_MODEL_NAMES:
modelq = model.objects.filter(document=v1doc).order_by('pk')
else:
continue
model_path = get_filepath_by_model(
model.__name__,
model._meta.app_label,
doc_key=v1doc.slug,
base_path=options['dir'])
write_queryset_data(model_path, modelq)

self.stdout.write(self.style.SUCCESS(
'Wrote {} to {}'.format(v1doc.slug, v1doc_path)))

self.stdout.write(self.style.SUCCESS('Data for v1 data complete.'))

# Start V2 output.
rulesets = Ruleset.objects.all()
ruleset_path = get_filepath_by_model(
Expand Down Expand Up @@ -71,8 +103,6 @@ def handle(self, *args, **options) -> None:
base_path=options['dir'])
write_queryset_data(doc_path, docq)

app_models = apps.get_models()

for model in app_models:
SKIPPED_MODEL_NAMES = ['Document', 'Ruleset', 'License', 'Publisher']
CHILD_MODEL_NAMES = ['Trait', 'FeatBenefit', 'BackgroundBenefit']
Expand Down
306 changes: 306 additions & 0 deletions data/v1/a5e/Background.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions data/v1/a5e/Document.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"model": "api.document",
"pk": 24,
"fields": {
"slug": "a5e",
"title": "Level Up Advanced 5e",
"desc": "Advanced 5th Edition System Reference Document by EN Publishing",
"license": "Creative Commons Attribution 4.0 International License",
"author": "EN Publishing",
"organization": "EN Publishing™",
"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.",
"created_at": "2023-10-06T19:54:00.143",
"license_url": "http://open5e.com/legal"
}
}
]
Loading

0 comments on commit 5d99ae7

Please sign in to comment.