From 2fa98cb02eb9ddf473027017abe2ba9aae7c8e93 Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Tue, 31 Jan 2017 22:03:03 +0100 Subject: [PATCH] add command to create dirs and html files for a new camp --- README.md | 14 ++++- src/bornhack/settings.py | 2 + src/utils/management/commands/createcamp.py | 70 +++++++++++++++++++++ 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 src/utils/management/commands/createcamp.py diff --git a/README.md b/README.md index e77cb91c..8994ae4d 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,13 @@ Enjoy! ### How to add a camp +Add a new camp in the admin interface and run ` + +``` + (venv) $ ./manage.py createcamp {camp-slug} +``` +or go through the manuel process below: + * Add a new camp in the admin interface. * Add a sponsers page, `{camp-slug}-sponsors.html`, to `sponsors/templates`. * Add a frontpage, `{camp-slug}-camp_detail.html`, to `camps/templates`. @@ -66,7 +73,8 @@ Enjoy! * `{camp-slug}-logo-small.png` ### multicamp prod migration notes -#### when villages.0008 migration fails go add camp_id to all existing villages -#### go to admin interface and add bornhack 2017, and set slug for bornhack 2016 -#### convert events to the new format (somehow) + +* when villages.0008 migration fails go add camp_id to all existing villages +* go to admin interface and add bornhack 2017, and set slug for bornhack 2016 +* convert events to the new format (somehow) diff --git a/src/bornhack/settings.py b/src/bornhack/settings.py index 8a7a12d1..ac005230 100644 --- a/src/bornhack/settings.py +++ b/src/bornhack/settings.py @@ -10,6 +10,8 @@ def local_dir(entry): entry ) +DJANGO_BASE_PATH = os.path.dirname(os.path.dirname(__file__)) + WSGI_APPLICATION = 'bornhack.wsgi.application' ROOT_URLCONF = 'bornhack.urls' diff --git a/src/utils/management/commands/createcamp.py b/src/utils/management/commands/createcamp.py new file mode 100644 index 00000000..e686f464 --- /dev/null +++ b/src/utils/management/commands/createcamp.py @@ -0,0 +1,70 @@ +# coding: utf-8 +from django.core.management.base import BaseCommand +from django.utils import timezone +from django.conf import settings +import os + + +class Command(BaseCommand): + help = 'Creates html files needed for a camp' + + def add_arguments(self, parser): + parser.add_argument('camp_slug', type=str) + + def output(self, message): + self.stdout.write('{}: {}'.format( + timezone.now().strftime("%Y-%m-%d %H:%M:%S"), + message + ) + ) + + def local_dir(self, entry): + return os.path.join( + settings.DJANGO_BASE_PATH, + entry + ) + + def handle(self, *args, **options): + + # files to create, relative to DJANGO_BASE_PATH + files = [ + 'sponsors/templates/{camp_slug}-sponsors.html', + 'camps/templates/{camp_slug}-camp_detail.html', + 'program/templates/{camp_slug}-call_for_speakers.html' + ] + + # directories to create, relative to DJANGO_BASE_PATH + dirs = [ + 'static/img/{camp_slug}/logo' + ] + + camp_slug = options['camp_slug'] + + for _file in files: + path = self.local_dir(_file.format(camp_slug=camp_slug)) + if os.path.isfile(_file): + self.output('File {} exists...'.format(path)) + else: + self.output('Creating {}'.format(path)) + with open(path, mode='w', encoding='utf-8') as f: + f.write(_file.format(camp_slug=camp_slug)) + + for _dir in dirs: + path = self.local_dir(_file.format(camp_slug=camp_slug)) + if os.path.exists(path): + self.output('Path {} exists...'.format(path)) + else: + self.output('Creating {}'.format(path)) + os.mkdir(path, mode=0o644) + + self.output('All there is left is to create:') + self.output( + self.local_dir( + 'static/img/{camp_slug}/logo/{camp_slug}-logo-large.png'.format(camp_slug=camp_slug) + ) + ) + self.output( + self.local_dir( + 'static/img/{camp_slug}/logo/{camp_slug}-logo-small.png'.format(camp_slug=camp_slug) + ) + )