From c1abc5a09fbf9db58665eb0268c4ec18de379d8a Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 8 Jun 2020 16:56:45 +0200 Subject: [PATCH 1/4] extend the device manufacturer model --- devices/models/device.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devices/models/device.py b/devices/models/device.py index 4e916dd..913a5ac 100644 --- a/devices/models/device.py +++ b/devices/models/device.py @@ -1,3 +1,4 @@ +from django.core.validators import RegexValidator from django.db import models from core.models import Category, Company from customers.models import Customer, Owner, Location @@ -6,6 +7,13 @@ from nets.models import Net, IpStatus class DeviceManufacturer(Company): + phone_regex = RegexValidator( + regex=r'^\+?1?\d{9,15}$', + message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.") + phone_number = models.CharField(validators=[phone_regex], max_length=17, + blank=True, null=True) + email_address = models.EmailField(null=True, blank=True) + website = models.URLField(null=True, blank=True) class Meta: verbose_name_plural = "Device Manufacturers" From b99aedce543f819d342a34f2a589747ca79fd9da Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 8 Jun 2020 17:00:16 +0200 Subject: [PATCH 2/4] set the settings variable before starting the docker container When you first set the variable for the local settings file it will overwrite the settings required for the docker container. Therefore I'm setting them explicitly in the Makefile. Shouldn't be a problem on a production system. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index a393969..ded10d0 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SHELL=/bin/bash .PHONY: docker docker: + export DJANGO_SETTINGS_MODULE=network_inventory.settings.docker; \ docker-compose up test: From 71c84c51d2d7e89c9c6889e32995a8364445137f Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 8 Jun 2020 17:01:55 +0200 Subject: [PATCH 3/4] clean out the docker-compose file --- docker-compose.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 91e76be..93b9b96 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,8 +7,8 @@ services: db: image: postgres environment: - - "POSTGRES_DB=${POSTGRES_DB}" - - "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}" + - POSTGRES_DB + - POSTGRES_PASSWORD volumes: - db_data:/var/lib/postgresql/data/ @@ -20,9 +20,9 @@ services: ports: - 8000:8000 environment: - - "DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}" - - "DJANGO_DEBUG=${DJANGO_DEBUG}" - - "DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}" + - DJANGO_SETTINGS_MODULE + - DJANGO_DEBUG + - DJANGO_SECRET_KEY depends_on: - db From e79eba2828ec51effd4adbfaf622d47f0b3c5161 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 8 Jun 2020 17:02:15 +0200 Subject: [PATCH 4/4] show all models in the admin interface Since we decided to create many forms in the frontend the admin interface should really be a way to access all models even the ones which aren't accessible from the front end. --- backups/admin.py | 40 ++--------------- computers/admin.py | 106 ++++----------------------------------------- devices/admin.py | 40 ++--------------- licenses/admin.py | 18 +------- nets/admin.py | 10 +---- softwares/admin.py | 30 ++----------- users/admin.py | 30 ++----------- 7 files changed, 25 insertions(+), 249 deletions(-) diff --git a/backups/admin.py b/backups/admin.py index 27654b1..8c012ca 100644 --- a/backups/admin.py +++ b/backups/admin.py @@ -10,30 +10,6 @@ from .models import ( ) -class BackupMethodAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class NotificationTypeAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class NotificationAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - class TargetDeviceInLine(admin.StackedInline): model = TargetDevice extra = 0 @@ -50,16 +26,8 @@ class BackupAdmin(admin.ModelAdmin): inlines = (TargetDeviceInLine, NotificationForBackupInLine) -class TargetDeviceAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - admin.site.register(Backup, BackupAdmin) -admin.site.register(BackupMethod, BackupMethodAdmin) -admin.site.register(Notification, NotificationAdmin) -admin.site.register(NotificationType, NotificationTypeAdmin) -admin.site.register(TargetDevice, TargetDeviceAdmin) +admin.site.register(BackupMethod) +admin.site.register(Notification) +admin.site.register(NotificationType) +admin.site.register(TargetDevice) diff --git a/computers/admin.py b/computers/admin.py index 9167c4e..96559ae 100644 --- a/computers/admin.py +++ b/computers/admin.py @@ -26,94 +26,6 @@ from .models import ( ) -class CpuAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class CpuArchitectureAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class CpuManufacturerAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class GpuAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class GpuManufacturerAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class IpStatusAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class RamModuleAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class RaidTypeAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class DiskTypeAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class RamTypeAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class DiskInRaidAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - class SoftwareInLine(nested_admin.NestedStackedInline): model = ComputerSoftwareRelation extra = 0 @@ -176,13 +88,13 @@ class ComputerAdmin(nested_admin.NestedModelAdmin): admin.site.register(Computer, ComputerAdmin) -admin.site.register(Cpu, CpuAdmin) -admin.site.register(CpuArchitecture, CpuArchitectureAdmin) -admin.site.register(CpuManufacturer, CpuManufacturerAdmin) +admin.site.register(Cpu) +admin.site.register(CpuArchitecture) +admin.site.register(CpuManufacturer) admin.site.register(Disk) -admin.site.register(DiskType, DiskTypeAdmin) -admin.site.register(Gpu, GpuAdmin) -admin.site.register(GpuManufacturer, GpuManufacturerAdmin) -admin.site.register(RaidType, RaidTypeAdmin) -admin.site.register(Ram, RamModuleAdmin) -admin.site.register(RamType, RamTypeAdmin) +admin.site.register(DiskType) +admin.site.register(Gpu) +admin.site.register(GpuManufacturer) +admin.site.register(RaidType) +admin.site.register(Ram) +admin.site.register(RamType) diff --git a/devices/admin.py b/devices/admin.py index aad4a09..12f2b17 100644 --- a/devices/admin.py +++ b/devices/admin.py @@ -12,52 +12,20 @@ from .models import ( ) -class DeviceCategoryAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class DeviceManufacturerAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class HardwareModelAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - class DeviceInNetInline(nested_admin.NestedStackedInline): model = DeviceInNet extra = 0 verbose_name_plural = 'Nets' -class WarrantyTypeAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - class DeviceAdmin(nested_admin.NestedModelAdmin): inlines = (DeviceInNetInline, ) admin.site.register(Device, DeviceAdmin) -admin.site.register(DeviceCategory, DeviceCategoryAdmin) +admin.site.register(DeviceCategory) admin.site.register(DeviceInNet) -admin.site.register(DeviceManufacturer, DeviceManufacturerAdmin) -admin.site.register(HardwareModel, HardwareModelAdmin) +admin.site.register(DeviceManufacturer) +admin.site.register(HardwareModel) admin.site.register(Warranty) -admin.site.register(WarrantyType, WarrantyTypeAdmin) +admin.site.register(WarrantyType) diff --git a/licenses/admin.py b/licenses/admin.py index 301e362..2637c84 100644 --- a/licenses/admin.py +++ b/licenses/admin.py @@ -9,22 +9,6 @@ from .models import ( ) -class LicenseWithComputerAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class LicenseWithUserAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - class UserLicenseAdmin(admin.ModelAdmin): model = UserLicense extra = 0 @@ -38,5 +22,5 @@ class ComputerLicenseAdmin(admin.ModelAdmin): admin.site.register(ComputerLicense, ComputerLicenseAdmin) -admin.site.register(LicenseWithComputer, LicenseWithComputerAdmin) +admin.site.register(LicenseWithComputer) admin.site.register(UserLicense, UserLicenseAdmin) diff --git a/nets/admin.py b/nets/admin.py index 13cac16..1caa123 100644 --- a/nets/admin.py +++ b/nets/admin.py @@ -7,13 +7,5 @@ from .models import ( ) -class IpStatusAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -admin.site.register(IpStatus, IpStatusAdmin) +admin.site.register(IpStatus) admin.site.register(Net) diff --git a/softwares/admin.py b/softwares/admin.py index ebf2ef2..71cee01 100644 --- a/softwares/admin.py +++ b/softwares/admin.py @@ -10,31 +10,7 @@ from .models import ( ) -class OperatingSystemAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class SoftwareArchitectureAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class SoftwareCategoryAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -admin.site.register(OperatingSystem, OperatingSystemAdmin) +admin.site.register(OperatingSystem) admin.site.register(Software) -admin.site.register(SoftwareArchitecture, SoftwareArchitectureAdmin) -admin.site.register(SoftwareCategory, SoftwareCategoryAdmin) +admin.site.register(SoftwareArchitecture) +admin.site.register(SoftwareCategory) diff --git a/users/admin.py b/users/admin.py index 216de81..16f13d2 100644 --- a/users/admin.py +++ b/users/admin.py @@ -12,30 +12,6 @@ from .models import ( ) -class MailAliasAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class UserInAdGroupAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - -class UserInMailGroupAdmin(admin.ModelAdmin): - def get_model_perms(self, request): - """ - Return empty perms dict thus hiding the model from admin index. - """ - return {} - - class LicenseWithUserInLine(admin.StackedInline): model = LicenseWithUser extra = 0 @@ -69,8 +45,8 @@ class UserAdmin(admin.ModelAdmin): admin.site.register(AdGroup) -admin.site.register(MailAlias, MailAliasAdmin) +admin.site.register(MailAlias) admin.site.register(MailGroup) admin.site.register(User, UserAdmin) -admin.site.register(UserInAdGroup, UserInAdGroupAdmin) -admin.site.register(UserInMailGroup, UserInMailGroupAdmin) +admin.site.register(UserInAdGroup) +admin.site.register(UserInMailGroup)