Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add spells to monsters and fix backgrounds #24

Merged
merged 6 commits into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ RUN pipenv run python manage.py populatedb --append ./data/tome_of_beasts/
#add the creature codex
RUN pipenv run python manage.py populatedb --append ./data/creature_codex/

#add original open5e content
RUN pipenv run python manage.py populatedb --append ./data/open5e_original/

#build the search index
RUN pipenv run python manage.py update_index --remove

Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
django = "==2.1"
django = "==2.1.5"
djangorestframework = "==3.8.2"
django-filter = "*"
django-cors-headers = "*"
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ Open5e is a community project driven by a small number of volunteers in their sp

The Django API uses Django REST Framework for its browsability and ease of use when developing CRUD endpoints. It uses django's default SQLite database, and pulls the data from the /data directory.

# Quickstart
The API uses docker-compose to run, and by default binds https:// on port 443, which may not work for your system (I believe windows has problems binding on low ports.) Here's the default command, run from the root.
> docker-compose up

This will allow you to access the project on https://localhost.

If you'd like to use docker and docker-compose for development, I would suggest rebinding the ports. Here's an example command that would allow for running the project on a non-standard port.

> docker-compose run --publish 8888:8888 server

This command runs the Server module (defined in docker-compose.yml), binding the port 8888 to 8888 locally. This should allow you to access the site on https://localhost:8888.

# Development using Django Server
To do any python development on the django application itself, I would suggest using django's built-in server as it allows for various things (such as debug mode and quick reloads). Here's the general process for getting that up and running.

Expand All @@ -24,7 +12,19 @@ First, install pipenv from here (https://pipenv.readthedocs.io/en/latest/).
Once pipenv is installed locally, you can then use it to install of the project dependencies defined in the Pipfile.
> pipenv install

Then you will need to use the built-in django migration function to define your database, making sure to run it within the pipenv environment.
## Quick Setup
If you want to work with existing data sources and just get working you can quickly stand up the server with

> pipenv run python manage.py quicksetup

followed by

> pipenv run python manage.py runserver

This will stand up the server with full content and search index at http://localhost:8000.

## Manual Setup Steps
If you want to customize your setup, particularly useful if adding new content sources, then you will need to use the built-in django migration function to define your database, making sure to run it within the pipenv environment.
> pipenv run python manage.py migrate

You will then need to collect the static files (this makes django-resk-framework look presentable when viewing it in html).
Expand Down
17 changes: 15 additions & 2 deletions api/management/commands/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def displayer(self, object_type, name):
message= 'loading... ' + name + '. '
return message

def update_monster(self, monster, spell):
db_monster = Monster.objects.get(slug=monster)
db_spell = Spell.objects.get(slug=slugify(spell))
MonsterSpell.objects.create(spell=db_spell, monster=db_monster) # <----- Create m2m relation

def DocumentImporter(self, options, json_object):
skipped,added,updated,tested = (0,0,0,0) #Count for all of the different results.
Expand Down Expand Up @@ -75,6 +79,8 @@ def BackgroundImporter(self, options, json_object):
i.desc = o['desc']
if 'skill-proficiencies' in o:
i.skill_proficiencies = o['skill-proficiencies']
if 'tool-proficiencies' in o:
i.tool_proficiencies = o['tool-proficiencies']
if 'languages' in o:
i.languages = o['languages']
if 'equipment' in o:
Expand Down Expand Up @@ -269,7 +275,6 @@ def MonsterImporter(self, options, json_object, skip_flush=False):
for o in json_object:
new = False
exists = False
# print( 'Monster ' + o['name'] ) # this is useful for debugging new JSON files

if Monster.objects.filter(slug=slugify(o['name'])).exists():
i = Monster.objects.get(slug=slugify(o['name']))
Expand Down Expand Up @@ -413,6 +418,12 @@ def MonsterImporter(self, options, json_object, skip_flush=False):
i.reactions_json = json.dumps("")
if 'legendary_desc' in o:
i.legendary_desc = o['legendary_desc']
# import spells array
if 'spells' in o:
i.spells_json = json.dumps(o['spells'])
else:
i.spells_json=json.dumps("")
# import legendary actions array
if 'legendary_actions' in o:
for idx, z in enumerate(o['legendary_actions']):
if 'attack_bonus' in z:
Expand All @@ -426,9 +437,11 @@ def MonsterImporter(self, options, json_object, skip_flush=False):
skipped += 1
else:
i.save()
if 'spells' in o:
for spell in o['spells']:
self.update_monster(i.slug, spell)
if new: added += 1
else: updated += 1

return self.returner('Monsters',added,updated,skipped)

def PlaneImporter(self, options, json_object):
Expand Down
12 changes: 6 additions & 6 deletions api/management/commands/populatedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def handle(self, *args, **options):
mag = json.load(mag_data)
self.stdout.write(self.style.SUCCESS(importer.MagicItemImporter(options, mag)))

spl_file = Path(dir+'spells.json')
if spl_file.exists():
with open(spl_file) as spl_data:
spl = json.load(spl_data)
self.stdout.write(self.style.SUCCESS(importer.SpellImporter(options, spl)))

mon_file = Path(dir+'monsters.json')
if mon_file.exists():
with open(mon_file) as mon_data:
Expand All @@ -99,12 +105,6 @@ def handle(self, *args, **options):
rac = json.load(rac_data)
self.stdout.write(self.style.SUCCESS(importer.RaceImporter(options, rac)))

spl_file = Path(dir+'spells.json')
if spl_file.exists():
with open(spl_file) as spl_data:
spl = json.load(spl_data)
self.stdout.write(self.style.SUCCESS(importer.SpellImporter(options, spl)))

wea_file = Path(dir+'weapons.json')
if wea_file.exists():
with open(wea_file) as wea_data:
Expand Down
15 changes: 15 additions & 0 deletions api/management/commands/quicksetup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
from django.core.management.base import BaseCommand

class Command(BaseCommand):
def handle(self, *args, **options):

migrations = 'python manage.py makemigrations && pipenv run python manage.py migrate'
collect_static = 'python manage.py collectstatic --noinput'
populate_db= 'pipenv run python manage.py populatedb --flush ./data/WOTC_5e_SRD_v5.1/ && pipenv run python manage.py populatedb --append ./data/tome_of_beasts/ && pipenv run python manage.py populatedb --append ./data/creature_codex/ && pipenv run python manage.py populatedb --append ./data/open5e_original/'
rebuild_index= 'pipenv run python manage.py update_index --remove'

os.system(migrations)
os.system(collect_static)
os.system(populate_db)
os.system(rebuild_index)
Loading