1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

refactor: settings are read through django.conf

instances/forms.py and instances/models.py imported values from the
webvirtcloud.settings module itself, which bypasses DJANGO_SETTINGS_MODULE
(settings-dev, test overrides) and runs the module a second time. They
now read django.conf.settings. webvirtcloud/urls.py also loses its
fallback that set REST_FRAMEWORK's schema class at import for settings.py
copies without it: the template sets it, and an older settings.py is
rebuilt from the template when updating.
This commit is contained in:
catborise 2026-11-06 11:01:51 +03:00
parent 2440c9eaf7
commit abe3b7ee63
3 changed files with 4 additions and 16 deletions

View file

@ -3,7 +3,6 @@ import re
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from webvirtcloud.settings import QEMU_CONSOLE_LISTENER_ADDRESSES, QEMU_KEYMAPS
from .models import CreateInstance, Flavor from .models import CreateInstance, Flavor
from .utils import nic_macs from .utils import nic_macs
@ -62,11 +61,11 @@ class ConsoleForm(forms.Form):
if "pty" in (instance.config_console_type, self.data.get("console_type")): if "pty" in (instance.config_console_type, self.data.get("console_type")):
del self.fields["password_action"], self.fields["password"] del self.fields["password_action"], self.fields["password"]
return return
keymap_choices = [("auto", _("Auto"))] + list((c, c) for c in QEMU_KEYMAPS) keymap_choices = [("auto", _("Auto"))] + list((c, c) for c in settings.QEMU_KEYMAPS)
# Only administrators choose the listen address: beyond localhost the # Only administrators choose the listen address: beyond localhost the
# console is reachable from the network. A disabled field ignores # console is reachable from the network. A disabled field ignores
# posted values. # posted values.
listeners = list(QEMU_CONSOLE_LISTENER_ADDRESSES) listeners = list(settings.QEMU_CONSOLE_LISTENER_ADDRESSES)
# an address set elsewhere (the XML editor) is offered, so a save keeps it # an address set elsewhere (the XML editor) is offered, so a save keeps it
if listener and listener not in dict(listeners): if listener and listener not in dict(listeners):
listeners.append((listener, listener)) listeners.append((listener, listener))

View file

@ -1,4 +1,5 @@
from computes.models import Compute from computes.models import Compute
from django.conf import settings
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from django.db import models from django.db import models
from django.utils.functional import cached_property from django.utils.functional import cached_property
@ -11,7 +12,6 @@ from libvirt import (
from operations import claims from operations import claims
from operations.models import Claim from operations.models import Claim
from vrtManager.instance import PERSISTENT_XML, wvmInstance from vrtManager.instance import PERSISTENT_XML, wvmInstance
from webvirtcloud.settings import QEMU_CONSOLE_LISTENER_ADDRESSES
class Flavor(models.Model): class Flavor(models.Model):
@ -466,7 +466,7 @@ class CreateInstance(models.Model):
max_length=16, error_messages={"required": _("Please select a video driver")} max_length=16, error_messages={"required": _("Please select a video driver")}
) )
listener_addr = models.CharField( listener_addr = models.CharField(
max_length=20, choices=QEMU_CONSOLE_LISTENER_ADDRESSES max_length=20, choices=settings.QEMU_CONSOLE_LISTENER_ADDRESSES
) )
class Meta: class Meta:

View file

@ -9,17 +9,6 @@ from appsettings.views import appsettings
from console.views import console from console.views import console
from instances.views import index from instances.views import index
# Fallback for existing installations where REST_FRAMEWORK.DEFAULT_SCHEMA_CLASS is not configured in settings.py
user_rf = getattr(settings, "REST_FRAMEWORK", None)
if not user_rf or "DEFAULT_SCHEMA_CLASS" not in user_rf:
try:
from rest_framework.settings import api_settings
from drf_spectacular.openapi import AutoSchema
api_settings.DEFAULT_SCHEMA_CLASS = AutoSchema
except (ImportError, AttributeError):
pass
urlpatterns = [ urlpatterns = [
path("", index, name="index"), path("", index, name="index"),
path("admin/", include(("admin.urls", "admin"), namespace="admin")), path("admin/", include(("admin.urls", "admin"), namespace="admin")),