Coverage for sample_project/settings.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-02-19 16:54 +0000

1import os 

2 

3from django.core.management.utils import get_random_secret_key 

4 

5SECRET_KEY = os.environ.get("SECRET_KEY", get_random_secret_key()) 

6DEBUG = True 

7 

8# we look for values in the environment and fallback to the 

9# Django defaults if there are none set 

10env_ah = os.environ.get("DJANGO_ALLOWED_HOSTS", "").split(",") 

11ALLOWED_HOSTS = list(filter(None, env_ah)) 

12env_csrf = os.environ.get("DJANGO_CSRF_TRUSTED_ORIGINS", "").split(",") 

13CSRF_TRUSTED_ORIGINS = list(filter(None, env_csrf)) 

14 

15 

16# Application definition 

17 

18INSTALLED_APPS = [ 

19 # our main app, containing the ontology (in the `models.py`) 

20 # and our customizations 

21 "sample_project", 

22 "django.contrib.admin", 

23 "django.contrib.auth", 

24 "django.contrib.contenttypes", 

25 "django.contrib.sessions", 

26 "django.contrib.messages", 

27 "django.contrib.staticfiles", 

28 # ui stuff used by APIS 

29 "crispy_forms", 

30 "crispy_bootstrap4", 

31 "crispy_bootstrap5", 

32 "django_filters", 

33 "django_tables2", 

34 "dal", 

35 "dal_select2", 

36 # REST API 

37 "rest_framework", 

38 # swagger ui generation 

39 "drf_spectacular", 

40 # The APIS apps 

41 # APIS collections provide a collection model similar to 

42 # SKOS collections and allow tagging of content 

43 "apis_core.collections", 

44 "apis_core.apis_metainfo", 

45 "apis_core.relations", 

46 "apis_core.apis_entities", 

47 # apis_vocabularies is deprecated, but there are 

48 # still migrations depending on it - it will be dropped 

49 # at some point 

50 "apis_core.apis_vocabularies", 

51 # APIS history modules tracks changes of instances over 

52 # time and lets you revert changes 

53 "apis_core.history", 

54 # The core APIS apps come last, so other apps can override 

55 # and extend their templates 

56 "apis_core.generic", 

57 "apis_core.core", 

58 "apis_core.documentation", 

59] 

60 

61MIDDLEWARE = [ 

62 "django.middleware.security.SecurityMiddleware", 

63 "django.contrib.sessions.middleware.SessionMiddleware", 

64 "django.middleware.common.CommonMiddleware", 

65 "django.middleware.csrf.CsrfViewMiddleware", 

66 "django.contrib.auth.middleware.AuthenticationMiddleware", 

67 "django.contrib.messages.middleware.MessageMiddleware", 

68 "django.middleware.clickjacking.XFrameOptionsMiddleware", 

69 "crum.CurrentRequestUserMiddleware", 

70 "simple_history.middleware.HistoryRequestMiddleware", 

71] 

72 

73# ROOT_URLCONF = "apis_core.urls" 

74ROOT_URLCONF = "sample_project.urls" 

75 

76TEMPLATES = [ 

77 { 

78 "BACKEND": "django.template.backends.django.DjangoTemplates", 

79 "DIRS": [], 

80 "APP_DIRS": True, 

81 "OPTIONS": { 

82 "context_processors": [ 

83 "django.template.context_processors.debug", 

84 "django.template.context_processors.request", 

85 "django.contrib.auth.context_processors.auth", 

86 "django.contrib.messages.context_processors.messages", 

87 ], 

88 }, 

89 }, 

90] 

91 

92STATIC_URL = "/static/" 

93STATIC_ROOT = "/tmp/staticfiles" 

94 

95DATABASES = { 

96 "default": { 

97 "ENGINE": "django.db.backends.sqlite3", 

98 "NAME": "/tmp/db.sqlite3", 

99 }, 

100} 

101 

102CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" 

103CRISPY_TEMPLATE_PACK = "bootstrap5" 

104DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html" 

105 

106# for django spectacular to be able to generate the schema, we have to use its view inspector 

107REST_FRAMEWORK = {"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema"} 

108# we use our custom schema generator to make it pick up our custom routes 

109SPECTACULAR_SETTINGS = { 

110 "DEFAULT_GENERATOR_CLASS": "apis_core.generic.generators.CustomSchemaGenerator" 

111} 

112 

113LOGGING = { 

114 "version": 1, 

115 "disable_existing_loggers": False, 

116 "formatters": { 

117 "verbose": { 

118 "format": "%(asctime)s %(name)-6s %(levelname)-8s %(message)s", 

119 }, 

120 }, 

121 "handlers": { 

122 "console": { 

123 "class": "logging.StreamHandler", 

124 "formatter": "verbose", 

125 }, 

126 }, 

127 "root": { 

128 "handlers": ["console"], 

129 "level": "DEBUG", 

130 }, 

131}