Moved the collection of config variables before the generation of angular constants
This commit is contained in:
parent
9d59da1352
commit
180dedfc38
@ -3,6 +3,7 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
import { OperatorService } from './core/services/operator.service';
|
||||
import { LoginDataService } from './core/services/login-data.service';
|
||||
import { ConfigService } from './core/services/config.service';
|
||||
import { ConstantsService } from './core/services/constants.service';
|
||||
|
||||
/**
|
||||
* Angular's global App Component
|
||||
@ -23,7 +24,8 @@ export class AppComponent {
|
||||
translate: TranslateService,
|
||||
operator: OperatorService,
|
||||
configService: ConfigService,
|
||||
loginDataService: LoginDataService
|
||||
loginDataService: LoginDataService,
|
||||
constantsService: ConstantsService // Needs to be started, so it can register itself to the WebsocketService
|
||||
) {
|
||||
// manually add the supported languages
|
||||
translate.addLangs(['en', 'de', 'fr']);
|
||||
|
@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { BaseComponent } from '../../../base.component';
|
||||
import { ConstantsService } from '../../../core/services/constants.service';
|
||||
|
||||
/**
|
||||
* List view for the global settings
|
||||
@ -19,7 +20,11 @@ export class SettingsListComponent extends BaseComponent implements OnInit {
|
||||
* @param titleService
|
||||
* @param translate
|
||||
*/
|
||||
public constructor(titleService: Title, protected translate: TranslateService) {
|
||||
public constructor(
|
||||
titleService: Title,
|
||||
protected translate: TranslateService,
|
||||
private constantsService: ConstantsService
|
||||
) {
|
||||
super(titleService, translate);
|
||||
}
|
||||
|
||||
@ -28,5 +33,9 @@ export class SettingsListComponent extends BaseComponent implements OnInit {
|
||||
*/
|
||||
public ngOnInit(): void {
|
||||
super.setTitle('Settings');
|
||||
|
||||
this.constantsService.get('OpenSlidesConfigVariables').subscribe(data => {
|
||||
console.log(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ from django.core.management import call_command, execute_from_command_line
|
||||
|
||||
import openslides
|
||||
from openslides.utils.arguments import arguments
|
||||
from openslides.utils.exceptions import OpenSlidesError
|
||||
from openslides.utils.main import (
|
||||
ExceptionArgumentParser,
|
||||
UnknownCommand,
|
||||
@ -187,6 +188,8 @@ def start(args):
|
||||
"""
|
||||
Starts OpenSlides: Runs migrations and runs runserver.
|
||||
"""
|
||||
raise OpenSlidesError('The start command does not work anymore. ' +
|
||||
'Please use `createsettings`, `migrate` and `runserver`.')
|
||||
settings_dir = args.settings_dir
|
||||
settings_filename = args.settings_filename
|
||||
local_installation = is_local_installation()
|
||||
|
@ -12,10 +12,8 @@ class AgendaAppConfig(AppConfig):
|
||||
def ready(self):
|
||||
# Import all required stuff.
|
||||
from django.db.models.signals import pre_delete, post_save
|
||||
from ..core.config import config
|
||||
from ..core.signals import permission_change, user_data_required
|
||||
from ..utils.rest_api import router
|
||||
from .config_variables import get_config_variables
|
||||
from .projector import get_projector_elements
|
||||
from .signals import (
|
||||
get_permission_change_data,
|
||||
@ -24,8 +22,7 @@ class AgendaAppConfig(AppConfig):
|
||||
required_users)
|
||||
from .views import ItemViewSet
|
||||
|
||||
# Define config variables and projector elements.
|
||||
config.update_config_variables(get_config_variables())
|
||||
# Define projector elements.
|
||||
register_projector_elements(get_projector_elements())
|
||||
|
||||
# Connect signals.
|
||||
@ -45,6 +42,10 @@ class AgendaAppConfig(AppConfig):
|
||||
# Register viewsets.
|
||||
router.register(self.get_model('Item').get_collection_string(), ItemViewSet)
|
||||
|
||||
def get_config_variables(self):
|
||||
from .config_variables import get_config_variables
|
||||
return get_config_variables()
|
||||
|
||||
def get_startup_elements(self):
|
||||
"""
|
||||
Yields all Cachables required on startup i. e. opening the websocket
|
||||
|
@ -14,16 +14,13 @@ class AssignmentsAppConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
# Import all required stuff.
|
||||
from ..core.config import config
|
||||
from ..core.signals import permission_change, user_data_required
|
||||
from ..utils.rest_api import router
|
||||
from .config_variables import get_config_variables
|
||||
from .projector import get_projector_elements
|
||||
from .signals import get_permission_change_data, required_users
|
||||
from .views import AssignmentViewSet, AssignmentPollViewSet
|
||||
|
||||
# Define config variables and projector elements.
|
||||
config.update_config_variables(get_config_variables())
|
||||
# Define projector elements.
|
||||
register_projector_elements(get_projector_elements())
|
||||
|
||||
# Connect signals.
|
||||
@ -38,6 +35,10 @@ class AssignmentsAppConfig(AppConfig):
|
||||
router.register(self.get_model('Assignment').get_collection_string(), AssignmentViewSet)
|
||||
router.register('assignments/poll', AssignmentPollViewSet)
|
||||
|
||||
def get_config_variables(self):
|
||||
from .config_variables import get_config_variables
|
||||
return get_config_variables()
|
||||
|
||||
def get_startup_elements(self):
|
||||
"""
|
||||
Yields all Cachables required on startup i. e. opening the websocket
|
||||
|
@ -21,7 +21,6 @@ class CoreAppConfig(AppConfig):
|
||||
# Import all required stuff.
|
||||
from .config import config
|
||||
from ..utils.rest_api import router
|
||||
from .config_variables import get_config_variables
|
||||
from .projector import get_projector_elements
|
||||
from .signals import (
|
||||
delete_django_app_permissions,
|
||||
@ -41,6 +40,9 @@ class CoreAppConfig(AppConfig):
|
||||
)
|
||||
from ..utils.constants import set_constants, get_constants_from_apps
|
||||
|
||||
# Collect all config variables before getting the constants.
|
||||
config.collect_config_variables_from_apps()
|
||||
|
||||
# Set constants
|
||||
try:
|
||||
set_constants(get_constants_from_apps())
|
||||
@ -48,8 +50,7 @@ class CoreAppConfig(AppConfig):
|
||||
# Database is not loaded. This happens in tests and migrations.
|
||||
pass
|
||||
|
||||
# Define config variables and projector elements.
|
||||
config.update_config_variables(get_config_variables())
|
||||
# Define projector elements.
|
||||
register_projector_elements(get_projector_elements())
|
||||
|
||||
# Connect signals.
|
||||
@ -73,6 +74,10 @@ class CoreAppConfig(AppConfig):
|
||||
router.register(self.get_model('ProjectorMessage').get_collection_string(), ProjectorMessageViewSet)
|
||||
router.register(self.get_model('Countdown').get_collection_string(), CountdownViewSet)
|
||||
|
||||
def get_config_variables(self):
|
||||
from .config_variables import get_config_variables
|
||||
return get_config_variables()
|
||||
|
||||
def get_startup_elements(self):
|
||||
"""
|
||||
Yields all Cachables required on startup i. e. opening the websocket
|
||||
|
@ -10,6 +10,7 @@ from typing import (
|
||||
)
|
||||
|
||||
from asgiref.sync import async_to_sync
|
||||
from django.apps import apps
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.utils.translation import ugettext as _
|
||||
from mypy_extensions import TypedDict
|
||||
@ -170,6 +171,17 @@ class ConfigHandler:
|
||||
if config_variable.on_change:
|
||||
config_variable.on_change()
|
||||
|
||||
def collect_config_variables_from_apps(self) -> None:
|
||||
for app in apps.get_app_configs():
|
||||
try:
|
||||
# Each app can deliver config variables when implementing the
|
||||
# get_config_variables method.
|
||||
get_config_variables = app.get_config_variables
|
||||
except AttributeError:
|
||||
# The app doesn't have this method. Continue to next app.
|
||||
continue
|
||||
self.update_config_variables(get_config_variables())
|
||||
|
||||
def update_config_variables(self, items: Iterable['ConfigVariable']) -> None:
|
||||
"""
|
||||
Updates the config_variables dict.
|
||||
|
@ -12,10 +12,8 @@ class MotionsAppConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
# Import all required stuff.
|
||||
from openslides.core.config import config
|
||||
from openslides.core.signals import permission_change, user_data_required
|
||||
from openslides.utils.rest_api import router
|
||||
from .config_variables import get_config_variables
|
||||
from .projector import get_projector_elements
|
||||
from .signals import (
|
||||
create_builtin_workflows,
|
||||
@ -33,8 +31,7 @@ class MotionsAppConfig(AppConfig):
|
||||
WorkflowViewSet,
|
||||
)
|
||||
|
||||
# Define config variables and projector elements.
|
||||
config.update_config_variables(get_config_variables())
|
||||
# Define projector elements.
|
||||
register_projector_elements(get_projector_elements())
|
||||
|
||||
# Connect signals.
|
||||
@ -59,6 +56,10 @@ class MotionsAppConfig(AppConfig):
|
||||
router.register(self.get_model('MotionPoll').get_collection_string(), MotionPollViewSet)
|
||||
router.register(self.get_model('State').get_collection_string(), StateViewSet)
|
||||
|
||||
def get_config_variables(self):
|
||||
from .config_variables import get_config_variables
|
||||
return get_config_variables()
|
||||
|
||||
def get_startup_elements(self):
|
||||
"""
|
||||
Yields all Cachables required on startup i. e. opening the websocket
|
||||
|
@ -13,16 +13,13 @@ class UsersAppConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
# Import all required stuff.
|
||||
from ..core.config import config
|
||||
from ..core.signals import post_permission_creation, permission_change
|
||||
from ..utils.rest_api import router
|
||||
from .config_variables import get_config_variables
|
||||
from .projector import get_projector_elements
|
||||
from .signals import create_builtin_groups_and_admin, get_permission_change_data
|
||||
from .views import GroupViewSet, PersonalNoteViewSet, UserViewSet
|
||||
|
||||
# Define config variables and projector elements.
|
||||
config.update_config_variables(get_config_variables())
|
||||
# Define projector elements.
|
||||
register_projector_elements(get_projector_elements())
|
||||
|
||||
# Connect signals.
|
||||
@ -42,6 +39,10 @@ class UsersAppConfig(AppConfig):
|
||||
router.register(self.get_model('Group').get_collection_string(), GroupViewSet)
|
||||
router.register(self.get_model('PersonalNote').get_collection_string(), PersonalNoteViewSet)
|
||||
|
||||
def get_config_variables(self):
|
||||
from .config_variables import get_config_variables
|
||||
return get_config_variables()
|
||||
|
||||
def get_startup_elements(self):
|
||||
"""
|
||||
Yields all Cachables required on startup i. e. opening the websocket
|
||||
|
@ -3,7 +3,7 @@ coverage
|
||||
# Use master of flake8 until flake8 3.6 is released that supports python3.7
|
||||
git+https://gitlab.com/pycqa/flake8.git
|
||||
isort
|
||||
mypy
|
||||
mypy<=0.620
|
||||
pytest>=3.6,<3.7
|
||||
pytest-django
|
||||
pytest-asyncio
|
||||
|
Loading…
Reference in New Issue
Block a user