mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +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:
parent
2440c9eaf7
commit
abe3b7ee63
3 changed files with 4 additions and 16 deletions
|
|
@ -3,7 +3,6 @@ import re
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from webvirtcloud.settings import QEMU_CONSOLE_LISTENER_ADDRESSES, QEMU_KEYMAPS
|
||||
|
||||
from .models import CreateInstance, Flavor
|
||||
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")):
|
||||
del self.fields["password_action"], self.fields["password"]
|
||||
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
|
||||
# console is reachable from the network. A disabled field ignores
|
||||
# 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
|
||||
if listener and listener not in dict(listeners):
|
||||
listeners.append((listener, listener))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from computes.models import Compute
|
||||
from django.conf import settings
|
||||
from django.core.validators import MinValueValidator
|
||||
from django.db import models
|
||||
from django.utils.functional import cached_property
|
||||
|
|
@ -11,7 +12,6 @@ from libvirt import (
|
|||
from operations import claims
|
||||
from operations.models import Claim
|
||||
from vrtManager.instance import PERSISTENT_XML, wvmInstance
|
||||
from webvirtcloud.settings import QEMU_CONSOLE_LISTENER_ADDRESSES
|
||||
|
||||
|
||||
class Flavor(models.Model):
|
||||
|
|
@ -466,7 +466,7 @@ class CreateInstance(models.Model):
|
|||
max_length=16, error_messages={"required": _("Please select a video driver")}
|
||||
)
|
||||
listener_addr = models.CharField(
|
||||
max_length=20, choices=QEMU_CONSOLE_LISTENER_ADDRESSES
|
||||
max_length=20, choices=settings.QEMU_CONSOLE_LISTENER_ADDRESSES
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -9,17 +9,6 @@ from appsettings.views import appsettings
|
|||
from console.views import console
|
||||
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 = [
|
||||
path("", index, name="index"),
|
||||
path("admin/", include(("admin.urls", "admin"), namespace="admin")),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue