-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
black, flake8, and docker fixes for demo
- Loading branch information
Showing
10 changed files
with
156 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:3.7.2-alpine3.9 | ||
FROM python:3.12.7-alpine | ||
MAINTAINER David Krauth "[email protected]" | ||
|
||
COPY . /app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,124 @@ | ||
''' | ||
""" | ||
#---------------------------------------------------------------------------------+ | ||
| Welcome to the swingtime demo project. This project's theme is a Karate dojo | | ||
| and the database will be pre-populated with some data relative to today's date. | | ||
#---------------------------------------------------------------------------------+ | ||
''' | ||
""" | ||
import os | ||
import django | ||
from django.core.management import call_command | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.core.management.base import BaseCommand | ||
from django.contrib.auth.models import User | ||
from datetime import datetime, date, time, timedelta | ||
from datetime import datetime, time, timedelta | ||
from django.conf import settings | ||
from django.db.models import signals | ||
from django.utils.termcolors import make_style | ||
from django.core.management.color import color_style | ||
from dateutil import rrule | ||
from swingtime import models as swingtime | ||
|
||
|
||
class Term: | ||
info = staticmethod(make_style(opts=('bold',), fg='green')) | ||
warn = staticmethod(make_style(opts=('bold',), fg='yellow', bg='black')) | ||
error = staticmethod(make_style(opts=('bold',), fg='red', bg='black')) | ||
info = staticmethod(make_style(opts=("bold",), fg="green")) | ||
warn = staticmethod(make_style(opts=("bold",), fg="yellow", bg="black")) | ||
error = staticmethod(make_style(opts=("bold",), fg="red", bg="black")) | ||
|
||
|
||
def create_sample_data(): | ||
|
||
# Create the studio's event types | ||
ets = dict(( | ||
(abbr, swingtime.EventType.objects.create(abbr=abbr, label=label)) | ||
for abbr, label in ( | ||
('prv', 'Private Lesson'), | ||
('bgn', 'Beginner Class'), | ||
('adv', 'Advanced Class'), | ||
('bbc', 'Black Belt Class'), | ||
('spr', 'Sparring'), | ||
('open', 'Open Dojo'), | ||
('spc', 'Special Event'), | ||
ets = dict( | ||
( | ||
(abbr, swingtime.EventType.objects.create(abbr=abbr, label=label)) | ||
for abbr, label in ( | ||
("prv", "Private Lesson"), | ||
("bgn", "Beginner Class"), | ||
("adv", "Advanced Class"), | ||
("bbc", "Black Belt Class"), | ||
("spr", "Sparring"), | ||
("open", "Open Dojo"), | ||
("spc", "Special Event"), | ||
) | ||
) | ||
)) | ||
) | ||
print(__doc__) | ||
print('Created event types: %s' % ( | ||
', '.join(['%s' % et for et in swingtime.EventType.objects.all()]), | ||
)) | ||
|
||
print( | ||
"Created event types: %s" | ||
% (", ".join(["%s" % et for et in swingtime.EventType.objects.all()]),) | ||
) | ||
|
||
now = datetime.now() | ||
|
||
# create a single occurrence event | ||
evt = swingtime.create_event( | ||
'Grand Opening', | ||
ets['spc'], | ||
description='Open house', | ||
"Grand Opening", | ||
ets["spc"], | ||
description="Open house", | ||
start_time=datetime.combine(now.date(), time(16)), | ||
end_time=datetime.combine(now.date(), time(18)), | ||
note='Free tea, sushi, and sake' | ||
note="Free tea, sushi, and sake", | ||
) | ||
print('Created event "%s" with %d occurrences' % (evt, evt.occurrence_set.count())) | ||
|
||
# create an event with multiple occurrences by fixed count | ||
evt = swingtime.create_event( | ||
'Beginner Class', | ||
ets['bgn'], | ||
description='Open to all white and yellow belts', | ||
"Beginner Class", | ||
ets["bgn"], | ||
description="Open to all white and yellow belts", | ||
start_time=datetime.combine(now.date(), time(19)), | ||
count=30, | ||
byweekday=(rrule.MO, rrule.WE, rrule.FR) | ||
byweekday=(rrule.MO, rrule.WE, rrule.FR), | ||
) | ||
print('Created event "%s" with %d occurrences' % (evt, evt.occurrence_set.count())) | ||
|
||
# create an event with multiple occurrences by ending date (until) | ||
evt = swingtime.create_event( | ||
'Advance Class', | ||
ets['adv'], | ||
description='Open to all green and brown belts', | ||
"Advance Class", | ||
ets["adv"], | ||
description="Open to all green and brown belts", | ||
start_time=datetime.combine(now.date(), time(18)), | ||
until=now + timedelta(days=+70), | ||
byweekday=(rrule.MO, rrule.WE, rrule.FR) | ||
byweekday=(rrule.MO, rrule.WE, rrule.FR), | ||
) | ||
print('Created event "%s" with %d occurrences' % (evt, evt.occurrence_set.count())) | ||
|
||
# create an event with multiple occurrences by fixed count on monthly basis | ||
evt = swingtime.create_event( | ||
'Black Belt Class', | ||
ets['bbc'], | ||
description='Open to all black belts', | ||
"Black Belt Class", | ||
ets["bbc"], | ||
description="Open to all black belts", | ||
start_time=datetime.combine(now.date(), time(18, 30)), | ||
end_time=datetime.combine(now.date(), time(20, 30)), | ||
count=6, | ||
freq=rrule.MONTHLY, | ||
byweekday=(rrule.TH(+1), rrule.TH(+3)) | ||
byweekday=(rrule.TH(+1), rrule.TH(+3)), | ||
) | ||
print('Created event "%s" with %d occurrences' % (evt, evt.occurrence_set.count())) | ||
|
||
# create an event with multiple occurrences and alternate intervale | ||
evt = swingtime.create_event( | ||
'Open Dojo', | ||
ets['open'], | ||
description='Open to all students', | ||
"Open Dojo", | ||
ets["open"], | ||
description="Open to all students", | ||
start_time=datetime.combine(now.date(), time(12)), | ||
end_time=datetime.combine(now.date(), time(16)), | ||
interval=2, | ||
count=6, | ||
byweekday=(rrule.SU) | ||
byweekday=(rrule.SU), | ||
) | ||
print( | ||
'Created event "%s" with %d occurrences\n' % (evt, evt.occurrence_set.count()) | ||
) | ||
print('Created event "%s" with %d occurrences\n' % (evt, evt.occurrence_set.count())) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Run the swingtime demo. If an existing demo database exists, it will recreated.' | ||
help = "Run the swingtime demo. If an existing demo database exists, it will recreated." | ||
|
||
def handle(self, **options): | ||
dbpath = settings.DATABASES['default']['NAME'] | ||
dbpath = settings.DATABASES["default"]["NAME"] | ||
if os.path.exists(dbpath): | ||
self.stdout.write(Term.warn('Removing old database %s' % dbpath)) | ||
self.stdout.write(Term.warn("Removing old database %s" % dbpath)) | ||
os.remove(dbpath) | ||
self.stdout.write(Term.info('Creating database %s' % dbpath)) | ||
self.stdout.write(Term.info("Creating database %s" % dbpath)) | ||
|
||
call_command('migrate', no_input=True, interactive=False) | ||
User.objects.create_superuser('admin', '[email protected]', 'password') | ||
print('Done.\n\nCreating sample data...') | ||
call_command("migrate", no_input=True, interactive=False) | ||
User.objects.create_superuser("admin", "[email protected]", "password") | ||
print("Done.\n\nCreating sample data...") | ||
create_sample_data() | ||
print('Done\n') | ||
|
||
print("Done\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
from datetime import datetime, timedelta | ||
from django.template.context import RequestContext | ||
from django.shortcuts import get_object_or_404, render | ||
|
||
from swingtime import models as swingtime | ||
|
||
|
||
def event_type(request, abbr): | ||
event_type = get_object_or_404(swingtime.EventType, abbr=abbr) | ||
now = datetime.now() | ||
occurrences = swingtime.Occurrence.objects.filter( | ||
event__event_type=event_type, | ||
start_time__gte=now, | ||
start_time__lte=now+timedelta(days=+30) | ||
start_time__lte=now + timedelta(days=+30), | ||
) | ||
return render( | ||
request, | ||
"karate/upcoming_by_event_type.html", | ||
{"occurrences": occurrences, "event_type": event_type}, | ||
) | ||
return render(request, 'karate/upcoming_by_event_type.html', { | ||
'occurrences': occurrences, | ||
'event_type': event_type | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,90 @@ | ||
import os | ||
import sys | ||
import datetime | ||
import django | ||
|
||
try: | ||
# dateutil is an absolute requirement | ||
import dateutil | ||
import dateutil # noqa | ||
except ImportError: | ||
raise ImportError('django-swingtime requires the "python-dateutil" package') | ||
|
||
dirname = os.path.dirname | ||
sys.path.extend([ | ||
os.path.dirname(__file__), | ||
os.path.abspath('..'), # relative location of swingtime app | ||
]) | ||
sys.path.extend( | ||
[ | ||
os.path.dirname(__file__), | ||
os.path.abspath(".."), # relative location of swingtime app | ||
] | ||
) | ||
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' | ||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField" | ||
DEBUG = True | ||
DATABASES = {'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'karate.db', | ||
}} | ||
LANGUAGES = (('en', 'English'),) | ||
STATIC_URL = '/static/' | ||
STATIC_ROOT = 'static' | ||
TIME_ZONE = 'America/New_York' | ||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django.db.backends.sqlite3", | ||
"NAME": "karate.db", | ||
} | ||
} | ||
LANGUAGES = (("en", "English"),) | ||
STATIC_URL = "/static/" | ||
STATIC_ROOT = "static" | ||
TIME_ZONE = "America/New_York" | ||
SITE_ID = 1 | ||
USE_I18N = True | ||
USE_TZ = False | ||
SECRET_KEY = 'swingtime-demo' | ||
TEST_RUNNER = 'django.test.runner.DiscoverRunner' | ||
TEMPLATES = [{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': (os.path.join(dirname(__file__), 'templates'),), | ||
'OPTIONS': { | ||
'debug': True, | ||
'loaders': ( | ||
'django.template.loaders.filesystem.Loader', | ||
'django.template.loaders.app_directories.Loader', | ||
), | ||
'context_processors': ( | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
'swingtime.context_processors.current_datetime', | ||
) | ||
SECRET_KEY = "swingtime-demo" | ||
TEST_RUNNER = "django.test.runner.DiscoverRunner" | ||
TEMPLATES = [ | ||
{ | ||
"BACKEND": "django.template.backends.django.DjangoTemplates", | ||
"DIRS": (os.path.join(dirname(__file__), "templates"),), | ||
"OPTIONS": { | ||
"debug": True, | ||
"loaders": ( | ||
"django.template.loaders.filesystem.Loader", | ||
"django.template.loaders.app_directories.Loader", | ||
), | ||
"context_processors": ( | ||
"django.template.context_processors.debug", | ||
"django.template.context_processors.request", | ||
"django.contrib.auth.context_processors.auth", | ||
"django.contrib.messages.context_processors.messages", | ||
"swingtime.context_processors.current_datetime", | ||
), | ||
}, | ||
} | ||
}] | ||
ALLOWED_HOSTS = ['*'] | ||
] | ||
ALLOWED_HOSTS = ["*"] | ||
|
||
ROOT_URLCONF = 'urls' | ||
ROOT_URLCONF = "urls" | ||
INSTALLED_APPS = ( | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.admin', | ||
'django.contrib.staticfiles', | ||
'swingtime', | ||
'karate', | ||
"django.contrib.auth", | ||
"django.contrib.contenttypes", | ||
"django.contrib.sessions", | ||
"django.contrib.messages", | ||
"django.contrib.admin", | ||
"django.contrib.staticfiles", | ||
"swingtime", | ||
"karate", | ||
) | ||
|
||
MIDDLEWARE = ( | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
"django.middleware.security.SecurityMiddleware", | ||
"django.contrib.sessions.middleware.SessionMiddleware", | ||
"django.middleware.common.CommonMiddleware", | ||
"django.middleware.csrf.CsrfViewMiddleware", | ||
"django.contrib.auth.middleware.AuthenticationMiddleware", | ||
"django.contrib.messages.middleware.MessageMiddleware", | ||
"django.middleware.clickjacking.XFrameOptionsMiddleware", | ||
) | ||
|
||
SWINGTIME = { | ||
'TIMESLOT_START_TIME': datetime.time(14), | ||
'TIMESLOT_END_TIME_DURATION': datetime.timedelta(hours=6.5) | ||
"TIMESLOT_START_TIME": datetime.time(14), | ||
"TIMESLOT_END_TIME_DURATION": datetime.timedelta(hours=6.5), | ||
} | ||
|
||
try: | ||
import django_extensions | ||
import django_extensions # noqa | ||
except ImportError: | ||
pass | ||
else: | ||
INSTALLED_APPS += ('django_extensions',) | ||
|
||
INSTALLED_APPS += ("django_extensions",) |
Oops, something went wrong.