settings.py 13 KB

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