diff --git a/dcc/dcc/__init__.py b/dcc/dcc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dcc/dcc/asgi.py b/dcc/dcc/asgi.py new file mode 100644 index 0000000..0db25d5 --- /dev/null +++ b/dcc/dcc/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for dcc project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dcc.settings') + +application = get_asgi_application() diff --git a/dcc/dcc/settings.py b/dcc/dcc/settings.py new file mode 100644 index 0000000..aec95c7 --- /dev/null +++ b/dcc/dcc/settings.py @@ -0,0 +1,129 @@ +""" +Django settings for dcc project. + +Generated by 'django-admin startproject' using Django 4.0. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +import os +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-1fgtf05rwp0qp05@ef@a7%x#o+t6vk6063py=vhdmut0j!8s4u' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'dcc', + 'roster', +] + +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', +] + +ROOT_URLCONF = 'dcc.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'dcc.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +MEDIA_URL = 'media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') diff --git a/dcc/dcc/urls.py b/dcc/dcc/urls.py new file mode 100644 index 0000000..96b5eaa --- /dev/null +++ b/dcc/dcc/urls.py @@ -0,0 +1,23 @@ +"""dcc URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.conf import settings +from django.conf.urls.static import static +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/dcc/dcc/utils.py b/dcc/dcc/utils.py new file mode 100644 index 0000000..1c3efea --- /dev/null +++ b/dcc/dcc/utils.py @@ -0,0 +1,7 @@ +from django.utils.html import format_html + + +def get_image_preview(url): + return format_html( + '' % url) diff --git a/dcc/dcc/wsgi.py b/dcc/dcc/wsgi.py new file mode 100644 index 0000000..8435ef1 --- /dev/null +++ b/dcc/dcc/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for dcc project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dcc.settings') + +application = get_wsgi_application() diff --git a/dcc/manage.py b/dcc/manage.py new file mode 100755 index 0000000..88b1b9e --- /dev/null +++ b/dcc/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dcc.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/dcc/media/images/R33255.jpeg b/dcc/media/images/R33255.jpeg new file mode 100644 index 0000000..8756b25 Binary files /dev/null and b/dcc/media/images/R33255.jpeg differ diff --git a/dcc/media/images/R33255_qDu1zPt.jpeg b/dcc/media/images/R33255_qDu1zPt.jpeg new file mode 100644 index 0000000..8756b25 Binary files /dev/null and b/dcc/media/images/R33255_qDu1zPt.jpeg differ diff --git a/dcc/roster/__init__.py b/dcc/roster/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dcc/roster/admin.py b/dcc/roster/admin.py new file mode 100644 index 0000000..de6802c --- /dev/null +++ b/dcc/roster/admin.py @@ -0,0 +1,33 @@ +from django.contrib import admin +from roster.models import Cab, Decoder, Manufacturer + + +@admin.register(Cab) +class CabAdmin(admin.ModelAdmin): + readonly_fields = ('image_thumbnail', 'creation_time', 'updated_time',) + list_display = ('identifier', 'manufacturer', 'address') + list_filter = list_display + search_fields = list_display + + fieldsets = ( + (None, { + 'fields': ('identifier', + 'address', + 'manufacturer', + 'decoder', + 'epoch', + 'production_year', + 'purchase_date', + 'image', + 'image_thumbnail', + 'notes') + }), + ('Audit', { + 'classes': ('collapse',), + 'fields': ('creation_time', 'updated_time',) + }), + ) + + +admin.site.register(Decoder) +admin.site.register(Manufacturer) diff --git a/dcc/roster/apps.py b/dcc/roster/apps.py new file mode 100644 index 0000000..39f52e7 --- /dev/null +++ b/dcc/roster/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class RosterConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'roster' diff --git a/dcc/roster/migrations/0001_initial.py b/dcc/roster/migrations/0001_initial.py new file mode 100644 index 0000000..fba407c --- /dev/null +++ b/dcc/roster/migrations/0001_initial.py @@ -0,0 +1,37 @@ +# Generated by Django 4.0 on 2021-12-15 22:16 + +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Manufacturer', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=128, unique=True)), + ], + ), + migrations.CreateModel( + name='Cab', + fields=[ + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('identifier', models.CharField(max_length=128)), + ('address', models.SmallIntegerField(default=3)), + ('creation_time', models.DateTimeField(auto_now_add=True)), + ('updated_time', models.DateTimeField(auto_now=True)), + ('manufacturer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer')), + ], + options={ + 'ordering': ['address', 'identifier'], + }, + ), + ] diff --git a/dcc/roster/migrations/0002_cab_notes_cab_production_date_cab_production_year.py b/dcc/roster/migrations/0002_cab_notes_cab_production_date_cab_production_year.py new file mode 100644 index 0000000..35aa44b --- /dev/null +++ b/dcc/roster/migrations/0002_cab_notes_cab_production_date_cab_production_year.py @@ -0,0 +1,28 @@ +# Generated by Django 4.0 on 2021-12-15 22:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='cab', + name='notes', + field=models.TextField(blank=True), + ), + migrations.AddField( + model_name='cab', + name='production_date', + field=models.SmallIntegerField(null=True), + ), + migrations.AddField( + model_name='cab', + name='production_year', + field=models.SmallIntegerField(null=True), + ), + ] diff --git a/dcc/roster/migrations/0003_remove_cab_production_date_cab_purchase_date.py b/dcc/roster/migrations/0003_remove_cab_production_date_cab_purchase_date.py new file mode 100644 index 0000000..95b2471 --- /dev/null +++ b/dcc/roster/migrations/0003_remove_cab_production_date_cab_purchase_date.py @@ -0,0 +1,22 @@ +# Generated by Django 4.0 on 2021-12-15 22:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0002_cab_notes_cab_production_date_cab_production_year'), + ] + + operations = [ + migrations.RemoveField( + model_name='cab', + name='production_date', + ), + migrations.AddField( + model_name='cab', + name='purchase_date', + field=models.DateField(null=True), + ), + ] diff --git a/dcc/roster/migrations/0004_alter_cab_manufacturer_alter_cab_production_year_and_more.py b/dcc/roster/migrations/0004_alter_cab_manufacturer_alter_cab_production_year_and_more.py new file mode 100644 index 0000000..100e04c --- /dev/null +++ b/dcc/roster/migrations/0004_alter_cab_manufacturer_alter_cab_production_year_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0 on 2021-12-15 22:28 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0003_remove_cab_production_date_cab_purchase_date'), + ] + + operations = [ + migrations.AlterField( + model_name='cab', + name='manufacturer', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer'), + ), + migrations.AlterField( + model_name='cab', + name='production_year', + field=models.SmallIntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name='cab', + name='purchase_date', + field=models.DateField(blank=True, null=True), + ), + ] diff --git a/dcc/roster/migrations/0005_alter_cab_manufacturer.py b/dcc/roster/migrations/0005_alter_cab_manufacturer.py new file mode 100644 index 0000000..f347d2a --- /dev/null +++ b/dcc/roster/migrations/0005_alter_cab_manufacturer.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0 on 2021-12-15 22:29 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0004_alter_cab_manufacturer_alter_cab_production_year_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='cab', + name='manufacturer', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer'), + ), + ] diff --git a/dcc/roster/migrations/0006_cab_image.py b/dcc/roster/migrations/0006_cab_image.py new file mode 100644 index 0000000..a8f744e --- /dev/null +++ b/dcc/roster/migrations/0006_cab_image.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0 on 2021-12-15 22:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0005_alter_cab_manufacturer'), + ] + + operations = [ + migrations.AddField( + model_name='cab', + name='image', + field=models.ImageField(blank=True, upload_to=''), + ), + ] diff --git a/dcc/roster/migrations/0007_alter_cab_image.py b/dcc/roster/migrations/0007_alter_cab_image.py new file mode 100644 index 0000000..dde5ee7 --- /dev/null +++ b/dcc/roster/migrations/0007_alter_cab_image.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0 on 2021-12-15 22:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0006_cab_image'), + ] + + operations = [ + migrations.AlterField( + model_name='cab', + name='image', + field=models.ImageField(blank=True, null=True, upload_to='images/'), + ), + ] diff --git a/dcc/roster/migrations/0008_cab_epoch.py b/dcc/roster/migrations/0008_cab_epoch.py new file mode 100644 index 0000000..d9a05d7 --- /dev/null +++ b/dcc/roster/migrations/0008_cab_epoch.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0 on 2021-12-15 23:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0007_alter_cab_image'), + ] + + operations = [ + migrations.AddField( + model_name='cab', + name='epoch', + field=models.CharField(blank=True, max_length=32), + ), + ] diff --git a/dcc/roster/migrations/0009_cab_decoder_manufacturer_cab_decoder_model_and_more.py b/dcc/roster/migrations/0009_cab_decoder_manufacturer_cab_decoder_model_and_more.py new file mode 100644 index 0000000..a9ee418 --- /dev/null +++ b/dcc/roster/migrations/0009_cab_decoder_manufacturer_cab_decoder_model_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0 on 2021-12-16 09:11 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0008_cab_epoch'), + ] + + operations = [ + migrations.AddField( + model_name='cab', + name='decoder_manufacturer', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_decoder', to='roster.manufacturer'), + ), + migrations.AddField( + model_name='cab', + name='decoder_model', + field=models.CharField(blank=True, max_length=128), + ), + migrations.AlterField( + model_name='cab', + name='manufacturer', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_manufacturer', to='roster.manufacturer'), + ), + ] diff --git a/dcc/roster/migrations/0010_remove_cab_decoder_manufacturer_and_more.py b/dcc/roster/migrations/0010_remove_cab_decoder_manufacturer_and_more.py new file mode 100644 index 0000000..3dab61a --- /dev/null +++ b/dcc/roster/migrations/0010_remove_cab_decoder_manufacturer_and_more.py @@ -0,0 +1,31 @@ +# Generated by Django 4.0 on 2021-12-16 09:15 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0009_cab_decoder_manufacturer_cab_decoder_model_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='cab', + name='decoder_manufacturer', + ), + migrations.AlterField( + model_name='cab', + name='manufacturer', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer'), + ), + migrations.CreateModel( + name='Decoder', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=128, unique=True)), + ('manufacturer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer')), + ], + ), + ] diff --git a/dcc/roster/migrations/0011_remove_cab_decoder_model_cab_decoder.py b/dcc/roster/migrations/0011_remove_cab_decoder_model_cab_decoder.py new file mode 100644 index 0000000..44d0fa5 --- /dev/null +++ b/dcc/roster/migrations/0011_remove_cab_decoder_model_cab_decoder.py @@ -0,0 +1,23 @@ +# Generated by Django 4.0 on 2021-12-16 09:18 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0010_remove_cab_decoder_manufacturer_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='cab', + name='decoder_model', + ), + migrations.AddField( + model_name='cab', + name='decoder', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='roster.decoder'), + ), + ] diff --git a/dcc/roster/migrations/__init__.py b/dcc/roster/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dcc/roster/models.py b/dcc/roster/models.py new file mode 100644 index 0000000..7129984 --- /dev/null +++ b/dcc/roster/models.py @@ -0,0 +1,82 @@ +from uuid import uuid4 +from django.db import models +# from django.core.files.storage import FileSystemStorage +# from django.dispatch import receiver + +from dcc.utils import get_image_preview + + +# class OverwriteMixin(FileSystemStorage): +# def get_available_name(self, name, max_length): +# self.delete(name) +# return name + + +class Manufacturer(models.Model): + name = models.CharField(max_length=128, unique=True) + + def __str__(self): + return self.name + + +class Company(models.Model): + name = models.CharField(max_length=128, unique=True) + country = models.CharField(max_length=128, unique=True) + + def __str__(self): + return self.name + + + +class Decoder(models.Model): + name = models.CharField(max_length=128, unique=True) + manufacturer = models.ForeignKey( + Manufacturer, + on_delete=models.CASCADE) + + def __str__(self): + return "{0} - {1}".format(self.manufacturer, self.name) + + +class Cab(models.Model): + uuid = models.UUIDField( + primary_key=True, default=uuid4, + editable=False) + identifier = models.CharField(max_length=128, unique=False) + address = models.SmallIntegerField(default=3) + manufacturer = models.ForeignKey( + Manufacturer, on_delete=models.CASCADE, + null=True, blank=True) + decoder = models.ForeignKey( + Decoder, on_delete=models.CASCADE, + null=True, blank=True) + epoch = models.CharField(max_length=32, blank=True) + production_year = models.SmallIntegerField(null=True, blank=True) + purchase_date = models.DateField(null=True, blank=True) + + image = models.ImageField( + upload_to='images/', + null=True, + blank=True) + notes = models.TextField(blank=True) + + creation_time = models.DateTimeField(auto_now_add=True) + updated_time = models.DateTimeField(auto_now=True) + + class Meta: + ordering = ['address', 'identifier'] + + def __str__(self): + return "{0} {1}".format(self.manufacturer, self.identifier) + + def image_thumbnail(self): + return get_image_preview(self.image.url) + image_thumbnail.short_description = "Preview" + + +# @receiver(models.signals.post_delete, sender=Cab) +# def post_save_image(sender, instance, *args, **kwargs): +# try: +# instance.image.delete(save=False) +# except Exception: +# pass diff --git a/dcc/roster/tests.py b/dcc/roster/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/dcc/roster/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/dcc/roster/views.py b/dcc/roster/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/dcc/roster/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..f37be1f --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,6 @@ +pip-review +pdbpp +ipython +flake8 +pyinstrument +django-debug-toolbar diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..39e256b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +pytz +Django +djangorestframework +django-health-check +# psycopg2-binary +paho-mqtt +# asyncio-mqtt +# PyYAML