settings.py 13 KB

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