def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) CRED_REGULAR = CremeAppConfig.CRED_REGULAR allowed_apps_f = self.fields['allowed_apps'] allowed_apps_f.choices = self.app_choices( app for app in creme_app_configs() if app.credentials & CRED_REGULAR) allowed_apps_f.initial = self.instance.allowed_apps
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) CRED_ADMIN = CremeAppConfig.CRED_ADMIN labels = self.instance.allowed_apps admin_4_apps_f = self.fields['admin_4_apps'] admin_4_apps_f.choices = self.app_choices( app for app in creme_app_configs() if app.label in labels and app.credentials & CRED_ADMIN) admin_4_apps_f.initial = self.instance.admin_4_apps
def populate_config_registry(self, config_registry): from creme.creme_core.apps import creme_app_configs for app_config in creme_app_configs(): config_registry.get_app_registry(app_config.label, create=True) register_creme_config = getattr(app_config, 'register_creme_config', None) if register_creme_config is not None: register_creme_config(config_registry)
r'^creme_login[/]?$', auth_views.LoginView.as_view(template_name='authent/creme_login.html'), name='creme_login'), re_path(r'^creme_logout[/]?$', auth_views.logout_then_login, name='creme_logout'), re_path(r'^creme_about[/]?$', render, {'template_name': 'about/about.html'}, name='creme_about'), re_path(r'^site_media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}), # NB: in production, configure your web server to statically serve the files in the 'media/static/' dir # (and so comment the following line) re_path(r'^static_media/(?P<path>.*)$', serve, {'document_root': settings.GENERATED_MEDIA_DIR}), ] for app_config in creme_app_configs(): app_name = app_config.name try: included = include(app_name + '.urls') except ImportError as e: if e.args and 'urls' in e.args[0]: logger.warning( 'The app "{}" has no "urls" module.'.format(app_name)) else: # It seems a annoying ImportError make the existing 'urls' module to be imported. raise else: urlpatterns.append(re_path(r'^' + app_config.url_root, included))
def populate_config_registry(self, config_registry): from creme.creme_core.apps import creme_app_configs for app_config in creme_app_configs(): config_registry.get_app_registry(app_config.label, create=True) register_creme_config = getattr(app_config, 'register_creme_config', None) if register_creme_config is not None: register_creme_config(config_registry) else: app_name = app_config.name try: config_registry_mod = import_module('{}.{}'.format( app_name, 'creme_config_register')) except ImportError: continue warnings.warn( 'The app "{}" still uses a module "creme_config_register", ' 'which is deprecated ; add a method "register_creme_config()" ' 'in the AppConfig instead.'.format(app_name), DeprecationWarning) from django.core import checks from .registry import NotRegisteredInConfig for model, model_name, *forms in getattr( config_registry_mod, 'to_register', ()): model_conf = config_registry.register_model( model, model_name) if forms: form = forms[0] model_conf.creation(form_class=form).edition( form_class=form) for model in getattr(config_registry_mod, 'to_unregister', ()): app_reg = config_registry.get_app_registry( model._meta.app_label, create=True) try: app_reg.get_model_conf(model) except NotRegisteredInConfig: @checks.register(checks.Tags.compatibility) def check_deps(app_name=app_name, model=model, **kwargs): return [ checks.Error( 'The app "{}" uses the out-of-order capability when ' 'un-registering the model {} ; this capability has ' 'been removed.'.format(app_name, model), hint= 'Fix the order of apps in the setting INSTALLED_CREME_APPS ' 'in your local_settings.py/project_settings.py (ie: the ' 'un-registered model must be registered _before_). ' 'Then, you should use the new registration system & call ' 'the method unregister_models() on the registry.', obj=app_name, id='creme_config.E001', ), ] else: app_reg._unregister_model(model) for app_label, brick_cls in getattr(config_registry_mod, 'blocks_to_register', ()): config_registry.register_app_bricks(app_label, brick_cls) config_registry.register_user_bricks(*getattr( config_registry_mod, 'userblocks_to_register', ())) config_registry.register_portal_bricks(*getattr( config_registry_mod, 'portalbricks_to_register', ()))
def handle(self, *app_labels, **options): verbosity = options.get('verbosity') # eg: 'persons', 'creme_core'... all_apps = OrderedSet(app_config.label for app_config in creme_app_configs()) apps_2_populate = all_apps if not app_labels else \ [_checked_app_label(app, all_apps) for app in app_labels] # ---------------------------------------------------------------------- populators = [] populators_names = set() # Names of populators that will be run total_deps = set( ) # Populators names that are needed by our populators total_missing_deps = set() # All populators names that are added by # this script because of dependencies while True: changed = False for app_label in apps_2_populate: populator = self._get_populator(app_label=app_label, verbosity=verbosity, all_apps=all_apps, options=options) if populator is not None: populators.append(populator) populators_names.add(app_label) total_deps.update(populator.dependencies) changed = True if not changed: break apps_2_populate = total_deps - populators_names total_missing_deps |= apps_2_populate if total_missing_deps and verbosity >= 1: self.stdout.write( 'Additional dependencies will be populated: {}'.format( ', '.join(total_missing_deps)), self.style.NOTICE) # Clean the dependencies (avoid dependencies that do not exist in # 'populators', which would cause Exception raising) for populator in populators: populator.build_dependencies(populators_names) populators = dependence_sort( populators, BasePopulator.get_app, BasePopulator.get_dependencies, ) # ---------------------------------------------------------------------- self.models = set() dispatch_uid = 'creme_core-populate_command' pre_save.connect(self._signal_handler, dispatch_uid=dispatch_uid) for populator in populators: if verbosity >= 1: self.stdout.write('Populate "{}" ...'.format(populator.app), ending='') self.stdout.flush() try: populator.populate() except Exception as e: self.stderr.write(' Populate "{}" failed ({})'.format( populator.app, e)) if verbosity >= 1: exc_type, exc_value, exc_traceback = sys.exc_info() self.stderr.write(''.join( format_exception(exc_type, exc_value, exc_traceback))) if verbosity >= 1: self.stdout.write(' OK', self.style.SUCCESS) pre_save.disconnect(dispatch_uid=dispatch_uid) # ---------------------------------------------------------------------- if self.models: if verbosity >= 1: self.stdout.write( 'Update sequences for models : {}'.format( [model.__name__ for model in self.models]), ending='', ) self.stdout.flush() connection = connections[options.get('database', DEFAULT_DB_ALIAS)] cursor = connection.cursor() for line in connection.ops.sequence_reset_sql( no_style(), self.models): cursor.execute(line) # connection.close() #seems useless (& does not work with mysql) if verbosity >= 1: self.stdout.write(self.style.SUCCESS(' OK')) elif verbosity >= 1: self.stdout.write('No sequence to update.') if verbosity >= 1: self.stdout.write(self.style.SUCCESS('Populate is OK.'))