Refactor settings

This commit is contained in:
Roman Mogylatov 2020-10-04 14:00:02 -04:00
parent 417b618bb6
commit f1e4e1ce58
4 changed files with 14 additions and 7 deletions

View File

@ -1,9 +1,8 @@
"""Main package.""" """Main package."""
from .containers import Container from .containers import Container
from . import settings
container = Container() container = Container()
container.config.github.request_timeout.override(5) container.config.from_dict(settings.__dict__)
container.config.default.query.override('Dependency Injector')
container.config.default.limit.override(5)

View File

@ -12,8 +12,8 @@ class Container(containers.DeclarativeContainer):
github_client = providers.Factory( github_client = providers.Factory(
Github, Github,
login_or_token=config.github.auth_token, login_or_token=config.GITHUB_TOKEN,
timeout=config.github.request_timeout, timeout=config.GITHUB_REQUEST_TIMEOUT,
) )
search_service = providers.Factory( search_service = providers.Factory(

View File

@ -119,3 +119,11 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.0/howto/static-files/ # https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/' 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'

View File

@ -9,8 +9,8 @@ from githubnavigator.services import SearchService
def index( def index(
request: HttpRequest, request: HttpRequest,
search_service: SearchService = Provide[Container.search_service], search_service: SearchService = Provide[Container.search_service],
default_query: str = Provide[Container.config.default.query], default_query: str = Provide[Container.config.DEFAULT_QUERY],
default_limit: int = Provide[Container.config.default.limit.as_int()], default_limit: int = Provide[Container.config.DEFAULT_LIMIT.as_int()],
) -> HttpResponse: ) -> HttpResponse:
query = request.GET.get('query', default_query) query = request.GET.get('query', default_query)
limit = int(request.GET.get('limit', default_limit)) limit = int(request.GET.get('limit', default_limit))