config.py 13 KB

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