Skip to content

Commit

Permalink
black, flake8, and docker fixes for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrauth committed Nov 18, 2024
1 parent 6774c5e commit 9f95a42
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 147 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
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
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Django Swingtime
.. image:: https://badge.fury.io/py/django-swingtime.svg
:target: http://badge.fury.io/py/django-swingtime

:Version: 1.5.1
:Version: 1.5.2
:Demo: https://nerdfog.com/swingtime/
:Download: https://pypi.org/project/django-swingtime/
:Source: https://github.com/dakrauth/django-swingtime
Expand Down Expand Up @@ -81,7 +81,7 @@ To run a local demo using Docker, do the following:
.. code:: bash
$ docker build -t swingtime .
$ docker run -p 8000:80 -d swingtime:latest
$ docker run -p 8000:80 swingtime:latest
And browse to `localhost:8000 <http://localhost:8000>`_.

Expand Down
119 changes: 60 additions & 59 deletions demo/karate/management/commands/loaddemo.py
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")
2 changes: 0 additions & 2 deletions demo/karate/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.db import models

# Create your models here.
7 changes: 3 additions & 4 deletions demo/karate/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from karate import views

urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='karate.html'), name='karate-home'),
url(r'^swingtime/events/type/([^/]+)/$', views.event_type, name='karate-event'),
url(r'^swingtime/', include('swingtime.urls')),
url(r"^$", TemplateView.as_view(template_name="karate.html"), name="karate-home"),
url(r"^swingtime/events/type/([^/]+)/$", views.event_type, name="karate-event"),
url(r"^swingtime/", include("swingtime.urls")),
]

13 changes: 7 additions & 6 deletions demo/karate/views.py
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
})
116 changes: 60 additions & 56 deletions demo/settings.py
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",)
Loading

0 comments on commit 9f95a42

Please sign in to comment.