mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-30 19:24:31 +03:00
Refactor settings
This commit is contained in:
parent
417b618bb6
commit
f1e4e1ce58
|
@ -1,9 +1,8 @@
|
|||
"""Main package."""
|
||||
|
||||
from .containers import Container
|
||||
from . import settings
|
||||
|
||||
|
||||
container = Container()
|
||||
container.config.github.request_timeout.override(5)
|
||||
container.config.default.query.override('Dependency Injector')
|
||||
container.config.default.limit.override(5)
|
||||
container.config.from_dict(settings.__dict__)
|
||||
|
|
|
@ -12,8 +12,8 @@ class Container(containers.DeclarativeContainer):
|
|||
|
||||
github_client = providers.Factory(
|
||||
Github,
|
||||
login_or_token=config.github.auth_token,
|
||||
timeout=config.github.request_timeout,
|
||||
login_or_token=config.GITHUB_TOKEN,
|
||||
timeout=config.GITHUB_REQUEST_TIMEOUT,
|
||||
)
|
||||
|
||||
search_service = providers.Factory(
|
||||
|
|
|
@ -119,3 +119,11 @@ USE_TZ = True
|
|||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# Github client settings
|
||||
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
|
||||
GITHUB_REQUEST_TIMEOUT = 10
|
||||
|
||||
# Default search settings
|
||||
DEFAULT_LIMIT = 5
|
||||
DEFAULT_QUERY = 'Dependency Injector'
|
||||
|
|
|
@ -9,8 +9,8 @@ from githubnavigator.services import SearchService
|
|||
def index(
|
||||
request: HttpRequest,
|
||||
search_service: SearchService = Provide[Container.search_service],
|
||||
default_query: str = Provide[Container.config.default.query],
|
||||
default_limit: int = Provide[Container.config.default.limit.as_int()],
|
||||
default_query: str = Provide[Container.config.DEFAULT_QUERY],
|
||||
default_limit: int = Provide[Container.config.DEFAULT_LIMIT.as_int()],
|
||||
) -> HttpResponse:
|
||||
query = request.GET.get('query', default_query)
|
||||
limit = int(request.GET.get('limit', default_limit))
|
||||
|
|
Loading…
Reference in New Issue
Block a user