Merge pull request #3860 from FinnStutzenstein/fixed-config-variables

Moved the collection of config variables before the generation of ang…
This commit is contained in:
Finn Stutzenstein 2018-09-18 07:56:12 +02:00 committed by GitHub
commit 582c2603a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 57 additions and 22 deletions

View File

@ -3,6 +3,7 @@ import { TranslateService } from '@ngx-translate/core';
import { OperatorService } from './core/services/operator.service'; import { OperatorService } from './core/services/operator.service';
import { LoginDataService } from './core/services/login-data.service'; import { LoginDataService } from './core/services/login-data.service';
import { ConfigService } from './core/services/config.service'; import { ConfigService } from './core/services/config.service';
import { ConstantsService } from './core/services/constants.service';
/** /**
* Angular's global App Component * Angular's global App Component
@ -23,7 +24,8 @@ export class AppComponent {
translate: TranslateService, translate: TranslateService,
operator: OperatorService, operator: OperatorService,
configService: ConfigService, 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 // manually add the supported languages
translate.addLangs(['en', 'de', 'fr']); translate.addLangs(['en', 'de', 'fr']);

View File

@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser'; import { Title } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { BaseComponent } from '../../../base.component'; import { BaseComponent } from '../../../base.component';
import { ConstantsService } from '../../../core/services/constants.service';
/** /**
* List view for the global settings * List view for the global settings
@ -19,7 +20,11 @@ export class SettingsListComponent extends BaseComponent implements OnInit {
* @param titleService * @param titleService
* @param translate * @param translate
*/ */
public constructor(titleService: Title, protected translate: TranslateService) { public constructor(
titleService: Title,
protected translate: TranslateService,
private constantsService: ConstantsService
) {
super(titleService, translate); super(titleService, translate);
} }
@ -28,5 +33,9 @@ export class SettingsListComponent extends BaseComponent implements OnInit {
*/ */
public ngOnInit(): void { public ngOnInit(): void {
super.setTitle('Settings'); super.setTitle('Settings');
this.constantsService.get('OpenSlidesConfigVariables').subscribe(data => {
console.log(data);
});
} }
} }

View File

@ -9,6 +9,7 @@ from django.core.management import call_command, execute_from_command_line
import openslides import openslides
from openslides.utils.arguments import arguments from openslides.utils.arguments import arguments
from openslides.utils.exceptions import OpenSlidesError
from openslides.utils.main import ( from openslides.utils.main import (
ExceptionArgumentParser, ExceptionArgumentParser,
UnknownCommand, UnknownCommand,
@ -187,6 +188,8 @@ def start(args):
""" """
Starts OpenSlides: Runs migrations and runs runserver. 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_dir = args.settings_dir
settings_filename = args.settings_filename settings_filename = args.settings_filename
local_installation = is_local_installation() local_installation = is_local_installation()

View File

@ -12,10 +12,8 @@ class AgendaAppConfig(AppConfig):
def ready(self): def ready(self):
# Import all required stuff. # Import all required stuff.
from django.db.models.signals import pre_delete, post_save 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 ..core.signals import permission_change, user_data_required
from ..utils.rest_api import router from ..utils.rest_api import router
from .config_variables import get_config_variables
from .projector import get_projector_elements from .projector import get_projector_elements
from .signals import ( from .signals import (
get_permission_change_data, get_permission_change_data,
@ -24,8 +22,7 @@ class AgendaAppConfig(AppConfig):
required_users) required_users)
from .views import ItemViewSet from .views import ItemViewSet
# Define config variables and projector elements. # Define projector elements.
config.update_config_variables(get_config_variables())
register_projector_elements(get_projector_elements()) register_projector_elements(get_projector_elements())
# Connect signals. # Connect signals.
@ -45,6 +42,10 @@ class AgendaAppConfig(AppConfig):
# Register viewsets. # Register viewsets.
router.register(self.get_model('Item').get_collection_string(), ItemViewSet) 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): def get_startup_elements(self):
""" """
Yields all Cachables required on startup i. e. opening the websocket Yields all Cachables required on startup i. e. opening the websocket

View File

@ -14,16 +14,13 @@ class AssignmentsAppConfig(AppConfig):
def ready(self): def ready(self):
# Import all required stuff. # Import all required stuff.
from ..core.config import config
from ..core.signals import permission_change, user_data_required from ..core.signals import permission_change, user_data_required
from ..utils.rest_api import router from ..utils.rest_api import router
from .config_variables import get_config_variables
from .projector import get_projector_elements from .projector import get_projector_elements
from .signals import get_permission_change_data, required_users from .signals import get_permission_change_data, required_users
from .views import AssignmentViewSet, AssignmentPollViewSet from .views import AssignmentViewSet, AssignmentPollViewSet
# Define config variables and projector elements. # Define projector elements.
config.update_config_variables(get_config_variables())
register_projector_elements(get_projector_elements()) register_projector_elements(get_projector_elements())
# Connect signals. # Connect signals.
@ -38,6 +35,10 @@ class AssignmentsAppConfig(AppConfig):
router.register(self.get_model('Assignment').get_collection_string(), AssignmentViewSet) router.register(self.get_model('Assignment').get_collection_string(), AssignmentViewSet)
router.register('assignments/poll', AssignmentPollViewSet) 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): def get_startup_elements(self):
""" """
Yields all Cachables required on startup i. e. opening the websocket Yields all Cachables required on startup i. e. opening the websocket

View File

@ -21,7 +21,6 @@ class CoreAppConfig(AppConfig):
# Import all required stuff. # Import all required stuff.
from .config import config from .config import config
from ..utils.rest_api import router from ..utils.rest_api import router
from .config_variables import get_config_variables
from .projector import get_projector_elements from .projector import get_projector_elements
from .signals import ( from .signals import (
delete_django_app_permissions, delete_django_app_permissions,
@ -41,6 +40,9 @@ class CoreAppConfig(AppConfig):
) )
from ..utils.constants import set_constants, get_constants_from_apps 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 # Set constants
try: try:
set_constants(get_constants_from_apps()) set_constants(get_constants_from_apps())
@ -48,8 +50,7 @@ class CoreAppConfig(AppConfig):
# Database is not loaded. This happens in tests and migrations. # Database is not loaded. This happens in tests and migrations.
pass pass
# Define config variables and projector elements. # Define projector elements.
config.update_config_variables(get_config_variables())
register_projector_elements(get_projector_elements()) register_projector_elements(get_projector_elements())
# Connect signals. # Connect signals.
@ -73,6 +74,10 @@ class CoreAppConfig(AppConfig):
router.register(self.get_model('ProjectorMessage').get_collection_string(), ProjectorMessageViewSet) router.register(self.get_model('ProjectorMessage').get_collection_string(), ProjectorMessageViewSet)
router.register(self.get_model('Countdown').get_collection_string(), CountdownViewSet) 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): def get_startup_elements(self):
""" """
Yields all Cachables required on startup i. e. opening the websocket Yields all Cachables required on startup i. e. opening the websocket

View File

@ -10,6 +10,7 @@ from typing import (
) )
from asgiref.sync import async_to_sync from asgiref.sync import async_to_sync
from django.apps import apps
from django.core.exceptions import ValidationError as DjangoValidationError from django.core.exceptions import ValidationError as DjangoValidationError
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from mypy_extensions import TypedDict from mypy_extensions import TypedDict
@ -170,6 +171,17 @@ class ConfigHandler:
if config_variable.on_change: if config_variable.on_change:
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: def update_config_variables(self, items: Iterable['ConfigVariable']) -> None:
""" """
Updates the config_variables dict. Updates the config_variables dict.

View File

@ -12,10 +12,8 @@ class MotionsAppConfig(AppConfig):
def ready(self): def ready(self):
# Import all required stuff. # Import all required stuff.
from openslides.core.config import config
from openslides.core.signals import permission_change, user_data_required from openslides.core.signals import permission_change, user_data_required
from openslides.utils.rest_api import router from openslides.utils.rest_api import router
from .config_variables import get_config_variables
from .projector import get_projector_elements from .projector import get_projector_elements
from .signals import ( from .signals import (
create_builtin_workflows, create_builtin_workflows,
@ -33,8 +31,7 @@ class MotionsAppConfig(AppConfig):
WorkflowViewSet, WorkflowViewSet,
) )
# Define config variables and projector elements. # Define projector elements.
config.update_config_variables(get_config_variables())
register_projector_elements(get_projector_elements()) register_projector_elements(get_projector_elements())
# Connect signals. # Connect signals.
@ -59,6 +56,10 @@ class MotionsAppConfig(AppConfig):
router.register(self.get_model('MotionPoll').get_collection_string(), MotionPollViewSet) router.register(self.get_model('MotionPoll').get_collection_string(), MotionPollViewSet)
router.register(self.get_model('State').get_collection_string(), StateViewSet) 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): def get_startup_elements(self):
""" """
Yields all Cachables required on startup i. e. opening the websocket Yields all Cachables required on startup i. e. opening the websocket

View File

@ -13,16 +13,13 @@ class UsersAppConfig(AppConfig):
def ready(self): def ready(self):
# Import all required stuff. # Import all required stuff.
from ..core.config import config
from ..core.signals import post_permission_creation, permission_change from ..core.signals import post_permission_creation, permission_change
from ..utils.rest_api import router from ..utils.rest_api import router
from .config_variables import get_config_variables
from .projector import get_projector_elements from .projector import get_projector_elements
from .signals import create_builtin_groups_and_admin, get_permission_change_data from .signals import create_builtin_groups_and_admin, get_permission_change_data
from .views import GroupViewSet, PersonalNoteViewSet, UserViewSet from .views import GroupViewSet, PersonalNoteViewSet, UserViewSet
# Define config variables and projector elements. # Define projector elements.
config.update_config_variables(get_config_variables())
register_projector_elements(get_projector_elements()) register_projector_elements(get_projector_elements())
# Connect signals. # Connect signals.
@ -42,6 +39,10 @@ class UsersAppConfig(AppConfig):
router.register(self.get_model('Group').get_collection_string(), GroupViewSet) router.register(self.get_model('Group').get_collection_string(), GroupViewSet)
router.register(self.get_model('PersonalNote').get_collection_string(), PersonalNoteViewSet) 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): def get_startup_elements(self):
""" """
Yields all Cachables required on startup i. e. opening the websocket Yields all Cachables required on startup i. e. opening the websocket

View File

@ -3,7 +3,7 @@ coverage
# Use master of flake8 until flake8 3.6 is released that supports python3.7 # Use master of flake8 until flake8 3.6 is released that supports python3.7
git+https://gitlab.com/pycqa/flake8.git git+https://gitlab.com/pycqa/flake8.git
isort isort
mypy mypy<=0.620
pytest>=3.6,<3.7 pytest>=3.6,<3.7
pytest-django pytest-django
pytest-asyncio pytest-asyncio