settings.py 12 KB

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