settings.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. import os
  2. from pathlib import Path
  3. from django.contrib.messages import constants as message_constants
  4. from django.utils.translation import gettext_lazy as _
  5. import core.settings_vars as sv
  6. ########
  7. #
  8. # Django
  9. #
  10. ########
  11. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  12. BASE_DIR = Path(__file__).resolve().parent.parent
  13. # SECURITY WARNING: keep the secret key used in production secret!
  14. SECRET_KEY = sv.SECRET_KEY
  15. # SECURITY WARNING: don't run with debug turned on in production!
  16. DEBUG = sv.DEBUG
  17. CSRF_TRUSTED_ORIGINS = sv.CSRF_TRUSTED_ORIGINS
  18. ALLOWED_HOSTS = sv.ALLOWED_HOSTS
  19. INTERNAL_IPS = sv.INTERNAL_IPS
  20. # Application definition
  21. INSTALLED_APPS = [
  22. 'design_template',
  23. 'jazzmin',
  24. 'django.contrib.admin',
  25. 'django.contrib.auth',
  26. 'django.contrib.contenttypes',
  27. 'django.contrib.sessions',
  28. 'django.contrib.messages',
  29. 'django.contrib.staticfiles',
  30. 'user.apps.UserConfig',
  31. 'SharixAdmin.apps.SharixadminConfig',
  32. 'tickets.apps.TicketsConfig',
  33. 'dbsynce.apps.DbsyncedConfig',
  34. 'webservice_running.apps.WebserviceRunningConfig',
  35. 'django_tables2',
  36. 'schema_graph',
  37. "django.contrib.sites",
  38. "django.contrib.flatpages",
  39. "django_extensions",
  40. 'rest_framework',
  41. 'rest_framework.authtoken',
  42. 'djoser',
  43. 'drf_yasg',
  44. 'django_spaghetti',
  45. 'debug_toolbar',
  46. 'ckeditor',
  47. 'landing.apps.LandingConfig',
  48. ]
  49. MIDDLEWARE = [
  50. 'django.middleware.security.SecurityMiddleware',
  51. 'django.contrib.sessions.middleware.SessionMiddleware',
  52. 'django.middleware.locale.LocaleMiddleware',
  53. 'django.middleware.common.CommonMiddleware',
  54. 'django.middleware.csrf.CsrfViewMiddleware',
  55. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  56. 'django.contrib.messages.middleware.MessageMiddleware',
  57. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  58. "debug_toolbar.middleware.DebugToolbarMiddleware",
  59. ]
  60. ROOT_URLCONF = "core.urls"
  61. SESSION_EXPIRE_AT_BROWSER_CLOSE = False
  62. SESSION_SECURITY_WARN_AFTER = 5
  63. SESSION_SECURITY_EXPIRE_AFTER = 12
  64. TEMPLATES = [
  65. {
  66. "BACKEND": "django.template.backends.django.DjangoTemplates",
  67. "DIRS": [os.path.join(BASE_DIR, "templates")],
  68. "APP_DIRS": True,
  69. "OPTIONS": {
  70. "context_processors": [
  71. "django.template.context_processors.debug",
  72. "django.template.context_processors.request",
  73. "django.contrib.auth.context_processors.auth",
  74. "django.template.context_processors.i18n",
  75. "django.template.context_processors.media",
  76. "django.template.context_processors.static",
  77. "django.template.context_processors.tz",
  78. "design_template.context_processors.get_name_system",
  79. "django.contrib.messages.context_processors.messages",
  80. ],
  81. },
  82. }
  83. ]
  84. WSGI_APPLICATION = 'core.wsgi.application'
  85. # Database
  86. # https://docs.djangoproject.com/en/4.0/ref/settings/#databases
  87. if sv.DB_NAME:
  88. DATABASES = {
  89. 'default': {
  90. 'ENGINE': 'django.db.backends.postgresql',
  91. 'NAME': sv.DB_NAME,
  92. 'USER': sv.DB_USER,
  93. 'PASSWORD': sv.DB_PASSWORD,
  94. 'HOST': sv.DB_HOST,
  95. 'PORT': sv.DB_PORT,
  96. }
  97. }
  98. else:
  99. DATABASES = {
  100. 'default': {
  101. 'ENGINE': 'django.db.backends.sqlite3',
  102. 'NAME': BASE_DIR / 'db.sqlite3',
  103. }
  104. }
  105. # Password validation
  106. # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
  107. AUTH_PASSWORD_VALIDATORS = [
  108. {
  109. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  110. },
  111. {
  112. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  113. },
  114. {
  115. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  116. },
  117. {
  118. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  119. },
  120. ]
  121. # Internationalization
  122. # https://docs.djangoproject.com/en/4.0/topics/i18n/
  123. LANGUAGE_CODE = 'ru'
  124. USE_TZ = True
  125. TIME_ZONE = 'Europe/Moscow'
  126. SITE_ID = 1
  127. # If you set this to False, Django will make some optimizations so as not
  128. # to load the internationalization machinery.
  129. USE_I18N = True
  130. LANGUAGES = [
  131. ('ru', _('Russian')),
  132. ('en', _('English')),
  133. ]
  134. # Static files (CSS, JavaScript, Images)
  135. # https://docs.djangoproject.com/en/4.0/howto/static-files/
  136. STATIC_URL = "/static/"
  137. STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
  138. # Uploaded media
  139. MEDIA_URL = "/media/"
  140. MEDIA_ROOT = os.path.join(BASE_DIR, "media")
  141. # Without this, uploaded files > 4MB end up with perm 0600, unreadable by web server process
  142. FILE_UPLOAD_PERMISSIONS = 0o644
  143. # Override CSS class for the ERROR tag level to match Bootstrap class name
  144. MESSAGE_TAGS = {message_constants.ERROR: "danger"}
  145. # Default primary key field type
  146. # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
  147. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  148. AUTH_USER_MODEL = 'user.ShariXUser'
  149. NAME_SYSTEM = sv.NAME_SYSTEM
  150. ########
  151. #
  152. # Jazzmin
  153. #
  154. ########
  155. JAZZMIN_SETTINGS = {
  156. # title of the window (Will default to current_admin_site.site_title if absent or None)
  157. "site_title": "ShariX Admin",
  158. # Title on the login screen (19 chars max) (defaults to current_admin_site.site_header if absent or None)
  159. "site_header": "ShariX Platform",
  160. # Title on the brand (19 chars max) (defaults to current_admin_site.site_header if absent or None)
  161. "site_brand": "ShariX Platform",
  162. # Logo to use for your site, must be present in static files, used for brand on top left
  163. "site_logo": "SharixAdmin/img/logo.png",
  164. # Logo to use for your site, must be present in static files, used for login form logo (defaults to site_logo)
  165. "login_logo": None,
  166. # Logo to use for login form in dark themes (defaults to login_logo)
  167. "login_logo_dark": None,
  168. # CSS classes that are applied to the logo above
  169. "site_logo_classes": "img-circle",
  170. # Relative path to a favicon for your site, will default to site_logo if absent (ideally 32x32 px)
  171. "site_icon": None,
  172. # Welcome text on the login screen
  173. "welcome_sign": "Welcome to the ShariX Admin",
  174. # Copyright on the footer
  175. "copyright": "Acme Library Ltd",
  176. # List of model admins to search from the search bar, search bar omitted if excluded
  177. # If you want to use a single search field you dont need to use a list, you can use a simple string
  178. "search_model": ["SharixAdmin.SharixUser"],
  179. # Field name on user model that contains avatar ImageField/URLField/Charfield or a callable that receives the user
  180. "user_avatar": "",
  181. ############
  182. # Top Menu #
  183. ############
  184. # Links to put along the top menu
  185. "topmenu_links": [
  186. # Url that gets reversed (Permissions can be added)
  187. {"name": "Главная", "url": "admin:index", "permissions": ["auth.view_user"]},
  188. # external url that opens in a new window (Permissions can be added)
  189. #{"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True},
  190. # model admin to link to (Permissions checked against model)
  191. {"model": "SharixAdmin.SharixUser"},
  192. # App with dropdown menu to all its models pages (Permissions checked against models)
  193. {"app": "tickets"},
  194. ],
  195. #############
  196. # User Menu #
  197. #############
  198. # Additional links to include in the user menu on the top right ("app" url type is not allowed)
  199. # "usermenu_links": [
  200. # {"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True},
  201. # {"model": "SharixAdmin.SharixUser"}
  202. # ],
  203. # #############
  204. # # Side Menu #
  205. # #############
  206. # # Whether to display the side menu
  207. # "show_sidebar": True,
  208. # # Whether to aut expand the menu
  209. # "navigation_expanded": True,
  210. # # Hide these apps when generating side menu e.g (auth)
  211. # "hide_apps": [],
  212. # # Hide these models when generating side menu (e.g auth.user)
  213. # "hide_models": [],
  214. # # List of apps (and/or models) to base side menu ordering off of (does not need to contain all apps/models)
  215. # #"order_with_respect_to": ["auth", "books", "books.author", "books.book"],
  216. # # Custom links to append to app groups, keyed on app name
  217. # "custom_links": {
  218. # "tickets": [{
  219. # "name": "Make Messages",
  220. # "url": "make_messages",
  221. # "icon": "fas fa-comments",
  222. # "permissions": ["tickets.view_book"]
  223. # }]
  224. # },
  225. # # Custom icons for side menu apps/models See https://fontawesome.com/icons?d=gallery&m=free&v=5.0.0,5.0.1,5.0.10,5.0.11,5.0.12,5.0.13,5.0.2,5.0.3,5.0.4,5.0.5,5.0.6,5.0.7,5.0.8,5.0.9,5.1.0,5.1.1,5.2.0,5.3.0,5.3.1,5.4.0,5.4.1,5.4.2,5.13.0,5.12.0,5.11.2,5.11.1,5.10.0,5.9.0,5.8.2,5.8.1,5.7.2,5.7.1,5.7.0,5.6.3,5.5.0,5.4.2
  226. # # for the full list of 5.13.0 free icon classes
  227. "icons": {
  228. "auth": "fas fa-users-cog",
  229. "auth.user": "fas fa-user",
  230. "auth.Group": "fas fa-users",
  231. "SharixAdmin": "fas fa-users-cog",
  232. "SharixAdmin.SharixUser": "fas fa-user",
  233. "tickets.Task": "fas fa-check",
  234. "tickets.TaskList": "fas fa-list",
  235. "tickets.Comment": "fas fa-comment",
  236. "tickets.Attachment": "fas fa-file",
  237. },
  238. # # Icons that are used when one is not manually specified
  239. # # "default_icon_parents": "fas fa-chevron-circle-right",
  240. # # "default_icon_children": "fas fa-circle",
  241. # #################
  242. # # Related Modal #
  243. # #################
  244. # # Use modals instead of popups
  245. # "related_modal_active": False,
  246. # #############
  247. # # UI Tweaks #
  248. # #############
  249. # # Relative paths to custom CSS/JS scripts (must be present in static files)
  250. "custom_css": None,
  251. "custom_js": None,
  252. # Whether to link font from fonts.googleapis.com (use custom_css to supply font otherwise)
  253. "use_google_fonts_cdn": True,
  254. # # Whether to show the UI customizer on the sidebar
  255. "show_ui_builder": True,
  256. ###############
  257. # Change view #
  258. ###############
  259. # Render out the change view as a single form, or in tabs, current options are
  260. # - single
  261. # - horizontal_tabs (default)
  262. # - vertical_tabs
  263. # - collapsible
  264. # - carousel
  265. #"changeform_format": "horizontal_tabs",
  266. # override change forms on a per modeladmin basis
  267. #"changeform_format_overrides": {"SharixAdmin.SharixUser": "collapsible", "auth.group": "vertical_tabs"},
  268. # Add a language dropdown into the admin
  269. #"language_chooser": True,
  270. }
  271. JAZZMIN_UI_TWEAKS = {
  272. "navbar_small_text": True,
  273. "footer_small_text": True,
  274. "body_small_text": False,
  275. "brand_small_text": True,
  276. "brand_colour": "navbar-light",
  277. "accent": "accent-navy",
  278. "navbar": "navbar-navy navbar-dark",
  279. "no_navbar_border": False,
  280. "navbar_fixed": False,
  281. "layout_boxed": False,
  282. "footer_fixed": False,
  283. "sidebar_fixed": True,
  284. "sidebar": "sidebar-light-navy",
  285. "sidebar_nav_small_text": False,
  286. "sidebar_disable_expand": False,
  287. "sidebar_nav_child_indent": False,
  288. "sidebar_nav_compact_style": True,
  289. "sidebar_nav_legacy_style": False,
  290. "sidebar_nav_flat_style": False,
  291. "theme": "default",
  292. "dark_mode_theme": None,
  293. "button_classes": {
  294. "primary": "btn-outline-primary",
  295. "secondary": "btn-outline-secondary",
  296. "info": "btn-outline-info",
  297. "warning": "btn-outline-warning",
  298. "danger": "btn-outline-danger",
  299. "success": "btn-outline-success"
  300. },
  301. "actions_sticky_top": False
  302. }
  303. ########
  304. #
  305. # API
  306. #
  307. ########
  308. API_URL = sv.API_URL
  309. REST_FRAMEWORK = {
  310. # Use Django's standard `django.contrib.auth` permissions,
  311. # or allow read-only access for unauthenticated users.
  312. 'DEFAULT_RENDERER_CLASSES':[
  313. 'rest_framework.renderers.JSONRenderer',
  314. 'rest_framework.renderers.BrowsableAPIRenderer',
  315. ],
  316. 'DEFAULT_PERMISSION_CLASSES': [
  317. #'rest_framework.permissions.AllowAny',
  318. #'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
  319. ],
  320. 'DEFAULT_AUTHENTICATION_CLASSES': (
  321. 'rest_framework.authentication.TokenAuthentication',
  322. 'rest_framework.authentication.BasicAuthentication',
  323. 'rest_framework.authentication.SessionAuthentication',
  324. ),
  325. }
  326. SPAGHETTI_SAUCE = {
  327. 'apps': ['auth', 'SharixAdmin',
  328. 'tickets', 'admin',
  329. 'flatpages', 'sessions', 'sites', 'dbsynce'],
  330. 'show_fields': False,
  331. 'show_proxy':True,
  332. }
  333. GRAPH_MODELS = {
  334. 'all_applications': True,
  335. 'group_models': True,
  336. }