commit 80668b3ec86660aad7b8d2e8069dc31ad847fa71 Author: Cayo Puigdefabregas Date: Wed Jun 12 09:32:49 2024 +0200 base of proyect diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..65692c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +db.sqlite3 +env/ diff --git a/action/__init__.py b/action/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/action/admin.py b/action/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/action/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/action/apps.py b/action/apps.py new file mode 100644 index 0000000..0b4e325 --- /dev/null +++ b/action/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ActionConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "action" diff --git a/action/migrations/__init__.py b/action/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/action/models.py b/action/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/action/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/action/tests.py b/action/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/action/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/action/urls.py b/action/urls.py new file mode 100644 index 0000000..9373af6 --- /dev/null +++ b/action/urls.py @@ -0,0 +1 @@ +from django.urls import path, include diff --git a/action/views.py b/action/views.py new file mode 100644 index 0000000..5d608b0 --- /dev/null +++ b/action/views.py @@ -0,0 +1 @@ +# from django.shortcuts import render diff --git a/device/__init__.py b/device/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/device/admin.py b/device/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/device/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/device/apps.py b/device/apps.py new file mode 100644 index 0000000..7b74161 --- /dev/null +++ b/device/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class DeviceConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "device" diff --git a/device/migrations/0001_initial.py b/device/migrations/0001_initial.py new file mode 100644 index 0000000..22d9017 --- /dev/null +++ b/device/migrations/0001_initial.py @@ -0,0 +1,404 @@ +# Generated by Django 5.0.6 on 2024-06-11 09:20 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="Device", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created", models.DateTimeField(auto_now_add=True)), + ("updated", models.DateTimeField(auto_now=True)), + ("type", models.CharField(max_length=32)), + ("model", models.CharField(blank=True, max_length=64, null=True)), + ( + "manufacturer", + models.CharField(blank=True, max_length=64, null=True), + ), + ( + "serial_number", + models.CharField(blank=True, max_length=64, null=True), + ), + ("part_number", models.CharField(blank=True, max_length=64, null=True)), + ("brand", models.TextField(blank=True, null=True)), + ("generation", models.SmallIntegerField(blank=True, null=True)), + ("version", models.TextField(blank=True, null=True)), + ("production_date", models.DateTimeField(blank=True, null=True)), + ("variant", models.TextField(blank=True, null=True)), + ("devicehub_id", models.TextField(blank=True, null=True, unique=True)), + ("dhid_bk", models.CharField(blank=True, max_length=64, null=True)), + ("phid_bk", models.CharField(blank=True, max_length=64, null=True)), + ("family", models.CharField(blank=True, max_length=64, null=True)), + ("hid", models.CharField(blank=True, max_length=64, null=True)), + ("chid", models.CharField(blank=True, max_length=64, null=True)), + ("active", models.BooleanField(default=True)), + ( + "owner", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + migrations.CreateModel( + name="Component", + fields=[ + ( + "device", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + primary_key=True, + serialize=False, + to="device.device", + ), + ), + ( + "type", + models.CharField( + choices=[ + ("GraphicCard", "Graphiccard"), + ("DataStorage", "Datastorage"), + ("Motherboard", "Motherboard"), + ("NetworkAdapter", "Networkadapter"), + ("Processor", "Processor"), + ("RamModule", "Rammodule"), + ("SoundCard", "Soundcard"), + ("Display", "Display"), + ("Battery", "Battery"), + ("Camera", "Camera"), + ], + max_length=32, + ), + ), + ], + ), + migrations.CreateModel( + name="Computer", + fields=[ + ( + "device", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + primary_key=True, + serialize=False, + to="device.device", + ), + ), + ("chassis", models.TextField(blank=True, null=True)), + ("system_uuid", models.UUIDField()), + ("sku", models.TextField(blank=True, null=True)), + ( + "type", + models.CharField( + choices=[ + ("Desktop", "Desktop"), + ("Laptop", "Laptop"), + ("Server", "Server"), + ], + default="Laptop", + max_length=32, + ), + ), + ], + ), + migrations.CreateModel( + name="PhysicalProperties", + fields=[ + ( + "device", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + primary_key=True, + serialize=False, + to="device.device", + ), + ), + ("weight", models.FloatField(blank=True, null=True)), + ("width", models.FloatField(blank=True, null=True)), + ("height", models.FloatField(blank=True, null=True)), + ("depth", models.FloatField(blank=True, null=True)), + ("color", models.CharField(blank=True, max_length=20, null=True)), + ("image", models.CharField(blank=True, max_length=64, null=True)), + ], + ), + migrations.CreateModel( + name="SoundCard", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.CreateModel( + name="RamModule", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("size", models.IntegerField(blank=True, null=True)), + ("speed", models.SmallIntegerField(blank=True, null=True)), + ( + "interface", + models.CharField( + choices=[ + ("SDRAM", "Sdram"), + ("DDR SDRAM", "Ddr"), + ("DDR2 SDRAM", "Ddr2"), + ("DDR3 SDRAM", "Ddr3"), + ("DDR4 SDRAM", "Ddr4"), + ("DDR5 SDRAM", "Ddr5"), + ("DDR6 SDRAM", "Ddr6"), + ("LPDDR3", "Lpddr3"), + ], + max_length=32, + ), + ), + ( + "format", + models.CharField( + choices=[("DIMM", "Dimm"), ("SODIMM", "Sodimm")], max_length=32 + ), + ), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.CreateModel( + name="Processor", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("speed", models.FloatField(blank=True, null=True)), + ("cores", models.SmallIntegerField(blank=True, null=True)), + ("threads", models.SmallIntegerField(blank=True, null=True)), + ("address", models.SmallIntegerField(blank=True, null=True)), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.CreateModel( + name="NetworkAdapter", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("speed", models.IntegerField(blank=True, null=True)), + ("wireless", models.BooleanField(default=False)), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.CreateModel( + name="Motherboard", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("slots", models.SmallIntegerField(blank=True, null=True)), + ("usb", models.SmallIntegerField(blank=True, null=True)), + ("firewire", models.SmallIntegerField(blank=True, null=True)), + ("serial", models.SmallIntegerField(blank=True, null=True)), + ("pcmcia", models.SmallIntegerField(blank=True, null=True)), + ("bios_date", models.DateTimeField()), + ("ram_slots", models.SmallIntegerField(blank=True, null=True)), + ("ram_max_size", models.IntegerField(blank=True, null=True)), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.CreateModel( + name="GraphicCard", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("memory", models.IntegerField(blank=True, null=True)), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.CreateModel( + name="Display", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.CreateModel( + name="DataStorage", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("size", models.IntegerField(blank=True, null=True)), + ( + "interface", + models.CharField( + choices=[ + ("ATA", "Ata"), + ("USB", "Usb"), + ("PCI", "Pci"), + ("NVME", "Nvme"), + ], + max_length=32, + ), + ), + ( + "type", + models.CharField( + choices=[ + ("HardDrive", "Harddrive"), + ("SolidStateDrive", "Solidstatedrive"), + ], + max_length=32, + ), + ), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.CreateModel( + name="Battery", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "component", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="device.component", + ), + ), + ], + ), + migrations.AddField( + model_name="component", + name="computer", + field=models.OneToOneField( + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="device.computer", + ), + ), + ] diff --git a/device/migrations/__init__.py b/device/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/device/models.py b/device/models.py new file mode 100644 index 0000000..852ed73 --- /dev/null +++ b/device/models.py @@ -0,0 +1,160 @@ +from django.db import models +from user.models import User +from utils.constants import STR_SM_SIZE, STR_SIZE + + +# Create your models here. + + +class Device(models.Model): + created = models.DateTimeField(auto_now_add=True) + updated = models.DateTimeField(auto_now=True) + type = models.CharField(max_length=STR_SM_SIZE) + model = models.CharField(max_length=STR_SIZE, blank=True, null=True) + manufacturer = models.CharField(max_length=STR_SIZE, blank=True, null=True) + serial_number = models.CharField(max_length=STR_SIZE, blank=True, null=True) + part_number = models.CharField(max_length=STR_SIZE, blank=True, null=True) + brand = models.TextField(blank=True, null=True) + generation = models.SmallIntegerField(blank=True, null=True) + version = models.TextField(blank=True, null=True) + production_date = models.DateTimeField(blank=True, null=True) + variant = models.TextField(blank=True, null=True) + devicehub_id = models.TextField(unique=True, blank=True, null=True) + dhid_bk = models.CharField(max_length=STR_SIZE, blank=True, null=True) + phid_bk = models.CharField(max_length=STR_SIZE, blank=True, null=True) + family = models.CharField(max_length=STR_SIZE, blank=True, null=True) + hid = models.CharField(max_length=STR_SIZE, blank=True, null=True) + chid = models.CharField(max_length=STR_SIZE, blank=True, null=True) + active = models.BooleanField(default=True) + owner = models.ForeignKey(User, on_delete=models.CASCADE) + + +class PhysicalProperties(models.Model): + device = models.OneToOneField(Device, models.CASCADE, primary_key=True) + weight = models.FloatField(blank=True, null=True) + width = models.FloatField(blank=True, null=True) + height = models.FloatField(blank=True, null=True) + depth = models.FloatField(blank=True, null=True) + color = models.CharField(max_length=20, blank=True, null=True) + image = models.CharField(max_length=STR_SIZE, blank=True, null=True) + + +class Computer(models.Model): + class Types(models.TextChoices): + DESKTOP = "Desktop" + LAPTOP = "Laptop" + SERVER = "Server" + + device = models.OneToOneField(Device, models.CASCADE, primary_key=True) + chassis = models.TextField(blank=True, null=True) + system_uuid = models.UUIDField() + sku = models.TextField(blank=True, null=True) + type = models.CharField(max_length=STR_SM_SIZE, choices=Types, default=Types.LAPTOP) + + +class Component(models.Model): + class Types(models.TextChoices): + GRAPHICCARD = "GraphicCard" + DATASTORAGE = "DataStorage" + MOTHERBOARD = "Motherboard" + NETWORKADAPTER = "NetworkAdapter" + PROCESSOR = "Processor" + RAMMODULE = "RamModule" + SOUNDCARD = "SoundCard" + DISPLAY = "Display" + BATTERY = "Battery" + CAMERA = "Camera" + + device = models.OneToOneField(Device, models.CASCADE, primary_key=True) + type = models.CharField(max_length=STR_SM_SIZE, choices=Types) + computer = models.OneToOneField(Computer, models.CASCADE, null=True) + + +class GraphicCard(models.Model): + component = models.OneToOneField(Component, models.CASCADE) + memory = models.IntegerField(blank=True, null=True) + + +class DataStorage(models.Model): + class Interface(models.TextChoices): + ATA = 'ATA' + USB = 'USB' + PCI = 'PCI' + NVME = 'NVME' + + class Type(models.TextChoices): + HARDDRIVE = "HardDrive" + SOLIDSTATEDRIVE = "SolidStateDrive" + + component = models.OneToOneField(Component, models.CASCADE) + size = models.IntegerField(blank=True, null=True) + interface = models.CharField(max_length=STR_SM_SIZE, choices=Interface) + type = models.CharField(max_length=STR_SM_SIZE, choices=Type) + + +class Motherboard(models.Model): + component = models.OneToOneField(Component, models.CASCADE) + slots = models.SmallIntegerField(blank=True, null=True) + usb = models.SmallIntegerField(blank=True, null=True) + firewire = models.SmallIntegerField(blank=True, null=True) + serial = models.SmallIntegerField(blank=True, null=True) + pcmcia = models.SmallIntegerField(blank=True, null=True) + bios_date = models.DateTimeField() + ram_slots = models.SmallIntegerField(blank=True, null=True) + ram_max_size = models.IntegerField(blank=True, null=True) + + +class NetworkAdapter(models.Model): + component = models.OneToOneField(Component, models.CASCADE) + speed = models.IntegerField(blank=True, null=True) + wireless = models.BooleanField(default=False) + + def __format__(self, format_spec): + v = super().__format__(format_spec) + if 's' in format_spec: + v += ' – {} Mbps'.format(self.speed) + return v + + +class Processor(models.Model): + component = models.OneToOneField(Component, models.CASCADE) + speed = models.FloatField(blank=True, null=True) + cores = models.SmallIntegerField(blank=True, null=True) + threads = models.SmallIntegerField(blank=True, null=True) + address = models.SmallIntegerField(blank=True, null=True) + + +class RamModule(models.Model): + class Interface(models.TextChoices): + SDRAM = 'SDRAM' + DDR = 'DDR SDRAM' + DDR2 = 'DDR2 SDRAM' + DDR3 = 'DDR3 SDRAM' + DDR4 = 'DDR4 SDRAM' + DDR5 = 'DDR5 SDRAM' + DDR6 = 'DDR6 SDRAM' + LPDDR3 = 'LPDDR3' + + class Format(models.TextChoices): + DIMM = 'DIMM' + SODIMM = 'SODIMM' + + component = models.OneToOneField(Component, models.CASCADE) + size = models.IntegerField(blank=True, null=True) + interface = models.CharField(max_length=STR_SM_SIZE, choices=Interface) + speed = models.SmallIntegerField(blank=True, null=True) + interface = models.CharField(max_length=STR_SM_SIZE, choices=Interface) + format = models.CharField(max_length=STR_SM_SIZE, choices=Format) + + +class SoundCard(models.Model): + component = models.OneToOneField(Component, models.CASCADE) + + +class Display(models.Model): + component = models.OneToOneField(Component, models.CASCADE) + + +class Battery(models.Model): + component = models.OneToOneField(Component, models.CASCADE) + diff --git a/device/tests.py b/device/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/device/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/device/views.py b/device/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/device/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/dhub/__init__.py b/dhub/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dhub/asgi.py b/dhub/asgi.py new file mode 100644 index 0000000..b57efa7 --- /dev/null +++ b/dhub/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for dhub 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/5.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dhub.settings") + +application = get_asgi_application() diff --git a/dhub/settings.py b/dhub/settings.py new file mode 100644 index 0000000..ec38755 --- /dev/null +++ b/dhub/settings.py @@ -0,0 +1,137 @@ +""" +Django settings for dhub project. + +Generated by 'django-admin startproject' using Django 5.0.6. + +For more information on this file, see +https://docs.djangoproject.com/en/5.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.0/ref/settings/ +""" + +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/5.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-1p8rs@qf$$l^!vsbetagojw23kw@1ez(qi8^(s0t!wyh!l3" + +# 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", + 'django_extensions', + 'django_bootstrap5', + "rest_framework", + "user", + "device", + "snapshot", + "action", + "tag", + "lot", + "documents", + "inventory", +] + + +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 = "dhub.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 = "dhub.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/5.0/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.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/5.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/5.0/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +AUTH_USER_MODEL = 'user.User' diff --git a/dhub/urls.py b/dhub/urls.py new file mode 100644 index 0000000..65ac492 --- /dev/null +++ b/dhub/urls.py @@ -0,0 +1,24 @@ +""" +URL configuration for dhub project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.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.contrib import admin +from django.urls import path, include + +urlpatterns = [ + # path("admin/", admin.site.urls), + path('api/', include('snapshot.urls')), +] diff --git a/dhub/wsgi.py b/dhub/wsgi.py new file mode 100644 index 0000000..9dfe1d6 --- /dev/null +++ b/dhub/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for dhub 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/5.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dhub.settings") + +application = get_wsgi_application() diff --git a/documents/__init__.py b/documents/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/documents/admin.py b/documents/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/documents/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/documents/apps.py b/documents/apps.py new file mode 100644 index 0000000..37ce729 --- /dev/null +++ b/documents/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class DocumentsConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "documents" diff --git a/documents/migrations/__init__.py b/documents/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/documents/models.py b/documents/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/documents/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/documents/tests.py b/documents/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/documents/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/documents/views.py b/documents/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/documents/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/inventory/__init__.py b/inventory/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/inventory/admin.py b/inventory/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/inventory/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/inventory/apps.py b/inventory/apps.py new file mode 100644 index 0000000..7bd447f --- /dev/null +++ b/inventory/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class InventoryConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "inventory" diff --git a/inventory/migrations/__init__.py b/inventory/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/inventory/models.py b/inventory/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/inventory/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/inventory/tests.py b/inventory/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/inventory/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/inventory/views.py b/inventory/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/inventory/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/lot/__init__.py b/lot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lot/admin.py b/lot/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/lot/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/lot/apps.py b/lot/apps.py new file mode 100644 index 0000000..65db99c --- /dev/null +++ b/lot/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class LotConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "lot" diff --git a/lot/migrations/__init__.py b/lot/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lot/models.py b/lot/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/lot/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/lot/tests.py b/lot/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/lot/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/lot/views.py b/lot/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/lot/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..d9863e4 --- /dev/null +++ b/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", "dhub.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/prevision.txt b/prevision.txt new file mode 100644 index 0000000..b1ad84d --- /dev/null +++ b/prevision.txt @@ -0,0 +1,23 @@ +4 login +8 device models +4 inventory template +4 upload snapshots +16 parse snapshots +16 build devices +8 action models +8 view actions +8 lot models +16 view lots +8 edit device +16 documents +8 tag +8 print label +4 server erase +4 profile +8 erase views +8 erase certificate +4 inventory snapshots +8 search +join split devices + +168 horas => 21 dias diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6221585 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +black==24.4.2 +Django==5.0.6 +django-bootstrap5==24.2 +django-extensions==3.2.3 +djangorestframework==3.15.1 diff --git a/snapshot/__init__.py b/snapshot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/snapshot/admin.py b/snapshot/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/snapshot/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/snapshot/apps.py b/snapshot/apps.py new file mode 100644 index 0000000..5e9983e --- /dev/null +++ b/snapshot/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ActionConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "snapshot" diff --git a/snapshot/migrations/0001_initial.py b/snapshot/migrations/0001_initial.py new file mode 100644 index 0000000..8fce7e2 --- /dev/null +++ b/snapshot/migrations/0001_initial.py @@ -0,0 +1,75 @@ +# Generated by Django 5.0.6 on 2024-06-11 09:20 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("device", "0001_initial"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="Snapshot", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created", models.DateTimeField(auto_now_add=True)), + ( + "software", + models.CharField( + choices=[("Workbench", "Workbench")], + default="Workbench", + max_length=32, + ), + ), + ("uuid", models.UUIDField()), + ("version", models.CharField(max_length=32)), + ("sid", models.CharField(max_length=32)), + ("settings_version", models.CharField(max_length=32)), + ("is_server_erase", models.BooleanField(default=False)), + ( + "severity", + models.SmallIntegerField( + choices=[ + (0, "Info"), + (1, "Notice"), + (2, "Warning"), + (3, "Error"), + ], + default=0, + ), + ), + ("start_time", models.DateTimeField()), + ("end_time", models.DateTimeField()), + ("components", models.ManyToManyField(to="device.component")), + ( + "computer", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="device.computer", + ), + ), + ( + "owner", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + ] diff --git a/snapshot/migrations/__init__.py b/snapshot/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/snapshot/models.py b/snapshot/models.py new file mode 100644 index 0000000..6bb81ce --- /dev/null +++ b/snapshot/models.py @@ -0,0 +1,31 @@ +from django.db import models +from utils.constants import STR_SM_SIZE +from user.models import User +from device.models import Computer, Component + +# Create your models here. + + +class Snapshot(models.Model): + class SoftWare(models.TextChoices): + WORKBENCH= "Workbench" + + class Severity(models.IntegerChoices): + Info = 0, "Info" + Notice = 1, "Notice" + Warning = 2, "Warning" + Error = 3, "Error" + + created = models.DateTimeField(auto_now_add=True) + software = models.CharField(max_length=STR_SM_SIZE, choices=SoftWare, default=SoftWare.WORKBENCH) + uuid = models.UUIDField() + version = models.CharField(max_length=STR_SM_SIZE) + sid = models.CharField(max_length=STR_SM_SIZE) + settings_version = models.CharField(max_length=STR_SM_SIZE) + is_server_erase = models.BooleanField(default=False) + severity = models.SmallIntegerField(choices=Severity, default=Severity.Info) + start_time = models.DateTimeField() + end_time = models.DateTimeField() + owner = models.ForeignKey(User, on_delete=models.CASCADE) + computer = models.ForeignKey(Computer, on_delete=models.CASCADE) + components = models.ManyToManyField(Component) diff --git a/snapshot/serializers.py b/snapshot/serializers.py new file mode 100644 index 0000000..222ae25 --- /dev/null +++ b/snapshot/serializers.py @@ -0,0 +1,8 @@ +from rest_framework import serializers +from snapshot.models import Snapshot + +class SnapshotSerializer(serializers.ModelSerializer): + class Meta: + model = Snapshot + fields = ['id', 'title', 'content'] + diff --git a/snapshot/tests.py b/snapshot/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/snapshot/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/snapshot/urls.py b/snapshot/urls.py new file mode 100644 index 0000000..784f557 --- /dev/null +++ b/snapshot/urls.py @@ -0,0 +1,10 @@ +from django.urls import path, include +from rest_framework.routers import DefaultRouter +from snapshot.views import SnapshotViewSet + +router = DefaultRouter() +router.register(r'snapshots', SnapshotViewSet) + +urlpatterns = [ + path('', include(router.urls)), +] diff --git a/snapshot/views.py b/snapshot/views.py new file mode 100644 index 0000000..c8d9bc4 --- /dev/null +++ b/snapshot/views.py @@ -0,0 +1,11 @@ +# from django.shortcuts import render +from rest_framework import viewsets +from snapshot.models import Snapshot +from snapshot.serializers import SnapshotSerializer + + +class SnapshotViewSet(viewsets.ModelViewSet): + queryset = Snapshot.objects.all() + serializer_class = SnapshotSerializer + + diff --git a/tag/__init__.py b/tag/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tag/admin.py b/tag/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/tag/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/tag/apps.py b/tag/apps.py new file mode 100644 index 0000000..8a3c701 --- /dev/null +++ b/tag/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TagConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "tag" diff --git a/tag/migrations/__init__.py b/tag/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tag/models.py b/tag/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/tag/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/tag/tests.py b/tag/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/tag/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/tag/views.py b/tag/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/tag/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/user/__init__.py b/user/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user/admin.py b/user/admin.py new file mode 100644 index 0000000..d954eb1 --- /dev/null +++ b/user/admin.py @@ -0,0 +1,10 @@ +from django.contrib import admin +from django.contrib.auth import get_user_model + +# Register your models here. + + +User = get_user_model() + +admin.site.register(User) + diff --git a/user/apps.py b/user/apps.py new file mode 100644 index 0000000..0234992 --- /dev/null +++ b/user/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AuthConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "user" diff --git a/user/migrations/0001_initial.py b/user/migrations/0001_initial.py new file mode 100644 index 0000000..aa08fe8 --- /dev/null +++ b/user/migrations/0001_initial.py @@ -0,0 +1,64 @@ +# Generated by Django 5.0.6 on 2024-06-11 09:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="User", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("password", models.CharField(max_length=128, verbose_name="password")), + ( + "last_login", + models.DateTimeField( + blank=True, null=True, verbose_name="last login" + ), + ), + ( + "email", + models.EmailField( + max_length=255, unique=True, verbose_name="Email address" + ), + ), + ( + "is_active", + models.BooleanField(default=True, verbose_name="is active"), + ), + ( + "is_admin", + models.BooleanField(default=False, verbose_name="is admin"), + ), + ( + "first_name", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="First name" + ), + ), + ( + "last_name", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Last name" + ), + ), + ("accept_gdpr", models.BooleanField(default=False)), + ], + options={ + "abstract": False, + }, + ), + ] diff --git a/user/migrations/__init__.py b/user/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/user/models.py b/user/models.py new file mode 100644 index 0000000..1112d59 --- /dev/null +++ b/user/models.py @@ -0,0 +1,80 @@ +from django.db import models +from django.utils.translation import gettext_lazy as _ +from django.contrib.auth.models import BaseUserManager, AbstractBaseUser + +# Create your models here. + + +class UserManager(BaseUserManager): + def create_user(self, email, password=None): + """ + Creates and saves a User with the given email, date of + birth and password. + """ + if not email: + raise ValueError("Users must have an email address") + + user = self.model( + email=self.normalize_email(email), + ) + + user.set_password(password) + user.save(using=self._db) + return user + + def create_superuser(self, email, password=None): + """ + Creates and saves a superuser with the given email, date of + birth and password. + """ + user = self.create_user( + email, + password=password, + ) + user.is_admin = True + user.save(using=self._db) + return user + + +class User(AbstractBaseUser): + email = models.EmailField( + _('Email address'), + max_length=255, + unique=True, + ) + is_active = models.BooleanField(_("is active"), default=True) + is_admin = models.BooleanField(_("is admin"), default=False) + first_name = models.CharField(_("First name"), max_length=255, blank=True, null=True) + last_name = models.CharField(_("Last name"), max_length=255, blank=True, null=True) + accept_gdpr = models.BooleanField(default=False) + + objects = UserManager() + + USERNAME_FIELD = "email" + REQUIRED_FIELDS = [] + + def __str__(self): + return self.email + + def has_perm(self, perm, obj=None): + "Does the user have a specific permission?" + # Simplest possible answer: Yes, always + return True + + def has_module_perms(self, app_label): + "Does the user have permissions to view the app `app_label`?" + # Simplest possible answer: Yes, always + return True + + @property + def is_staff(self): + "Is the user a member of staff?" + # Simplest possible answer: All admins are staff + return self.is_admin + + @property + def username(self): + "Is the email of the user" + return self.email + + diff --git a/user/tests.py b/user/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/user/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/user/views.py b/user/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/user/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/constants.py b/utils/constants.py new file mode 100644 index 0000000..d51519d --- /dev/null +++ b/utils/constants.py @@ -0,0 +1,7 @@ +# constants declarated for all proyect + + +STR_XSM_SIZE = 16 +STR_SM_SIZE = 32 +STR_SIZE = 64 +STR_BIG_SIZE = 128