def migrate_settings(siteconfig): """ Migrates any settings we want in the database from the settings file. """ # Convert everything in the table. for siteconfig_key, setting_data in migration_table.iteritems(): if isinstance(setting_data, dict): setting_key = setting_data['key'] serialize_func = setting_data.get('serialize_func', None) else: setting_key = setting_data serialize_func = None default = defaults.get(siteconfig_key, None) value = getattr(settings, setting_key, default) if serialize_func and callable(serialize_func): value = serialize_func(value) siteconfig.set(siteconfig_key, value) # This may be a tuple in a tuple, or it may just be a tuple. if type(settings.ADMINS[0]) == tuple: admin = settings.ADMINS[0] else: admin = settings.ADMINS siteconfig.set('site_admin_name', admin[0]) siteconfig.set('site_admin_email', admin[1]) # Try to transform the authentication backend remaining_backends = [] known_backends = [] for auth_backend in settings.AUTHENTICATION_BACKENDS: if auth_backend in auth_backend_map: known_backends.append(auth_backend) else: remaining_backends.append(auth_backend) if remaining_backends or len(known_backends) > 1: # The user has some custom backend set. Just set the entire list siteconfig.set('auth_backend', 'custom') siteconfig.set('auth_custom_backends', settings.AUTHENTICATION_BACKENDS) elif len(known_backends) == 1: siteconfig.set('auth_backend', auth_backend_map[known_backends[0]]) else: siteconfig.set('auth_backend', 'builtin')