From 9f95a42d9727015263f415ad5dd44ff7cb9ba177 Mon Sep 17 00:00:00 2001 From: David Krauth Date: Mon, 18 Nov 2024 12:30:48 -0800 Subject: [PATCH] black, flake8, and docker fixes for demo --- Dockerfile | 2 +- README.rst | 4 +- demo/karate/management/commands/loaddemo.py | 119 ++++++++++---------- demo/karate/models.py | 2 - demo/karate/urls.py | 7 +- demo/karate/views.py | 13 ++- demo/settings.py | 116 ++++++++++--------- demo/urls.py | 21 ++-- demo/wsgi.py | 17 +-- swingtime/__init__.py | 2 +- 10 files changed, 156 insertions(+), 147 deletions(-) diff --git a/Dockerfile b/Dockerfile index 091be9c..3d22b0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7.2-alpine3.9 +FROM python:3.12.7-alpine MAINTAINER David Krauth "dakrauth@gmail.com" COPY . /app diff --git a/README.rst b/README.rst index 11bd355..6b9e427 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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 `_. diff --git a/demo/karate/management/commands/loaddemo.py b/demo/karate/management/commands/loaddemo.py index 536115b..1332346 100644 --- a/demo/karate/management/commands/loaddemo.py +++ b/demo/karate/management/commands/loaddemo.py @@ -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', 'admin@example.com', 'password') - print('Done.\n\nCreating sample data...') + call_command("migrate", no_input=True, interactive=False) + User.objects.create_superuser("admin", "admin@example.com", "password") + print("Done.\n\nCreating sample data...") create_sample_data() - print('Done\n') - + print("Done\n") diff --git a/demo/karate/models.py b/demo/karate/models.py index 71a8362..6b20219 100644 --- a/demo/karate/models.py +++ b/demo/karate/models.py @@ -1,3 +1 @@ -from django.db import models - # Create your models here. diff --git a/demo/karate/urls.py b/demo/karate/urls.py index 0967850..7bfd587 100644 --- a/demo/karate/urls.py +++ b/demo/karate/urls.py @@ -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")), ] - diff --git a/demo/karate/views.py b/demo/karate/views.py index ea6fb1a..e8ae4bf 100644 --- a/demo/karate/views.py +++ b/demo/karate/views.py @@ -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 - }) diff --git a/demo/settings.py b/demo/settings.py index bf8e070..1517913 100644 --- a/demo/settings.py +++ b/demo/settings.py @@ -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",) diff --git a/demo/urls.py b/demo/urls.py index cf86b74..347f9cf 100644 --- a/demo/urls.py +++ b/demo/urls.py @@ -4,23 +4,26 @@ from django.urls import include, re_path from django.views.generic import TemplateView, RedirectView -doc_root = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'docs/') +doc_root = os.path.join(os.path.dirname(os.path.dirname(__file__)), "docs/") def docs(request): from django import http - return http.HttpResponsePermanentRedirect(os.path.join(request.path, 'index.html')) + + return http.HttpResponsePermanentRedirect(os.path.join(request.path, "index.html")) swingtime_patterns = [ - re_path(r'^$', TemplateView.as_view(template_name='intro.html'), name='demo-home'), - re_path(r'^karate/', include('karate.urls')), - re_path(r'^admin/', admin.site.urls), - re_path(r'^docs/$', docs, name='swingtime-docs'), - re_path(r'^docs/(?P.*)$', serve, dict(document_root=doc_root, show_indexes=False)) + re_path(r"^$", TemplateView.as_view(template_name="intro.html"), name="demo-home"), + re_path(r"^karate/", include("karate.urls")), + re_path(r"^admin/", admin.site.urls), + re_path(r"^docs/$", docs, name="swingtime-docs"), + re_path( + r"^docs/(?P.*)$", serve, dict(document_root=doc_root, show_indexes=False) + ), ] urlpatterns = [ - re_path(r'^$', RedirectView.as_view(url='/swingtime/')), - re_path(r'^swingtime/', include(swingtime_patterns)), + re_path(r"^$", RedirectView.as_view(url="/swingtime/")), + re_path(r"^swingtime/", include(swingtime_patterns)), ] diff --git a/demo/wsgi.py b/demo/wsgi.py index 778adf3..fffebd6 100644 --- a/demo/wsgi.py +++ b/demo/wsgi.py @@ -1,13 +1,16 @@ -import os, sys +""" +WSGI config for foo project. -ROOT_DIR = '/var/www/swingtime.com/' +It exposes the WSGI callable as a module-level variable named ``application``. -sys.path.extend([ROOT_DIR,]) -sys.stdout = sys.stderr +For more information on this file, see +https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/ +""" -os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' -os.chdir(ROOT_DIR) +import os from django.core.wsgi import get_wsgi_application -application = get_wsgi_application() +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") + +application = get_wsgi_application() diff --git a/swingtime/__init__.py b/swingtime/__init__.py index d02abc1..30e7d7f 100644 --- a/swingtime/__init__.py +++ b/swingtime/__init__.py @@ -1,4 +1,4 @@ -VERSION = (1, 5, 1) +VERSION = (1, 5, 2) def get_version():