Refactoring of the settings module to be more modular and extensible

Pull request for issue 20040 (https://code.djangoproject.com/ticket/20040)