base of proyect

This commit is contained in:
Cayo Puigdefabregas 2024-06-12 09:32:49 +02:00
commit 80668b3ec8
73 changed files with 1233 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
db.sqlite3
env/

0
action/__init__.py Normal file
View File

3
action/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
action/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ActionConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "action"

View File

3
action/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
action/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

1
action/urls.py Normal file
View File

@ -0,0 +1 @@
from django.urls import path, include

1
action/views.py Normal file
View File

@ -0,0 +1 @@
# from django.shortcuts import render

0
device/__init__.py Normal file
View File

3
device/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
device/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class DeviceConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "device"

View File

@ -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",
),
),
]

View File

160
device/models.py Normal file
View File

@ -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)

3
device/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
device/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

0
dhub/__init__.py Normal file
View File

16
dhub/asgi.py Normal file
View File

@ -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()

137
dhub/settings.py Normal file
View File

@ -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&#7!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'

24
dhub/urls.py Normal file
View File

@ -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')),
]

16
dhub/wsgi.py Normal file
View File

@ -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()

0
documents/__init__.py Normal file
View File

3
documents/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
documents/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class DocumentsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "documents"

View File

3
documents/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
documents/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
documents/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

0
inventory/__init__.py Normal file
View File

3
inventory/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
inventory/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class InventoryConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "inventory"

View File

3
inventory/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
inventory/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
inventory/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

0
lot/__init__.py Normal file
View File

3
lot/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
lot/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class LotConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "lot"

View File

3
lot/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
lot/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
lot/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

22
manage.py Executable file
View File

@ -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()

23
prevision.txt Normal file
View File

@ -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

5
requirements.txt Normal file
View File

@ -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

0
snapshot/__init__.py Normal file
View File

3
snapshot/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
snapshot/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ActionConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "snapshot"

View File

@ -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,
),
),
],
),
]

View File

31
snapshot/models.py Normal file
View File

@ -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)

8
snapshot/serializers.py Normal file
View File

@ -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']

3
snapshot/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

10
snapshot/urls.py Normal file
View File

@ -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)),
]

11
snapshot/views.py Normal file
View File

@ -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

0
tag/__init__.py Normal file
View File

3
tag/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
tag/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class TagConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "tag"

View File

3
tag/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
tag/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
tag/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

0
user/__init__.py Normal file
View File

10
user/admin.py Normal file
View File

@ -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)

6
user/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class AuthConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "user"

View File

@ -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,
},
),
]

View File

80
user/models.py Normal file
View File

@ -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

3
user/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
user/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

0
utils/__init__.py Normal file
View File

7
utils/constants.py Normal file
View File

@ -0,0 +1,7 @@
# constants declarated for all proyect
STR_XSM_SIZE = 16
STR_SM_SIZE = 32
STR_SIZE = 64
STR_BIG_SIZE = 128