settings.py 12 KB

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