Pārlūkot izejas kodu

Added a new project configuration method

- Deleted junk files
- Fixed and improved scripts
- Added a new project configuration method
- Edited and extended description about new features
TonyKurts 8 mēneši atpakaļ
vecāks
revīzija
b32fae4d7a

+ 4 - 0
.gitattributes

@@ -0,0 +1,4 @@
+* text=auto
+
+*.txt text
+*.md text

+ 20 - 8
.gitignore

@@ -1,15 +1,26 @@
 # Virtualenv
 env/
 venv/
-#module
+
+# VSCode
+.vscode
+
+# Python
+__pycache__/
+*.py[cod]
+*$py.class
+
+# Apps
 tickets/
 metaservicesynced/
-openlocal/
+conf/
 SharixAdmin/templates/SharixAdmin/
+
+# Django
+migrations/
 staticfiles/
-core/config.py
-SharixAdmin/migrations/
-!SharixAdmin/migrations/__init__.py
+media/
+
 # VSCode
 .vscode
 
@@ -20,7 +31,8 @@ __pycache__/
 
 # Other
 *.sqlite3
-.env
+*.*~
+*.*.swp
 
-# Vim
-*~
+# Project configuration
+core/config.py

+ 40 - 96
README.md

@@ -1,108 +1,52 @@
-# ShariX Open Admin
+# ShariX Open Webapp Base
 
-Admin system implemented as a Django application.
+The base Django project of a service web application to which other modules are connected.
 
-## How install?
+## Installation
+
+Download or clone repository.
+
+For the initial configuration, run:
+
+- *bin/install.sh* - on Unix.
+- *bin/install.bat* - on Windows.
+
+## Configuration
+
+After executing the installation script, the file *core/_config.py* will be copied to the *core/config.py* (only if *core/config.py* does not exist yet). It contains default settings of all modules and applications used in Django project in the form of classes, where each attribute represents one setting. These classes are then used to apply all the necessary settings inside their own configuration files using the setup() function. 
+
+For example, this is how all the customizations for Gunicorn are defined in the *core/config.py* file:
 
-1) Download or clone repository
-```bash
-git clone http://git.sharix-app.org/ShariX_Open/sharix-open-webapp-base.git name_project
-```
-1) Set up a configuration file
 ```python
-#Create file config.py with this setting or rename this file to config.py
-
-#BASE
-DEBUG=True
-SECRET_KEY='secret-key(absolutely any character)'
-ALLOWED_HOSTS = ['127.0.0.1']
-CSRF_TRUSTED_ORIGINS = []
-
-#DATABSE
-DB_NAME=None
-DB_USER=None
-DB_PASSWORD=None
-DB_HOST=None
-
-#GUNICORN
-BIND = "127.0.0.1:8000"
-WORKERS = 2
-THREADS = 4
-
-#STATIC
-from pathlib import Path
-import os
-BASE_DIR = Path(__file__).resolve().parent.parent
-STATIC_URL = '/static/'
-STATICFILES_DIRS = [BASE_DIR / "SharixAdmin/static/", BASE_DIR / "tickets/static/"]
-STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
-```
-3) Run a **install_win.bat**
-4) The system will prompt you to create a superuser
-```
-#Example
-7987654321
-admin
-pa$$w0rd
-pa$$w0rd
-```
-### Ready!
+# core/config.py
 
-## Server instalation
-1) Download or clone repository
-```bash
-git clone http://git.sharix-app.org/ShariX_Open/sharix-open-webapp-base.git name_project
+class ConfigGunicorn:
+    bind = "127.0.0.1"
+    workers = 2
+    worker_class = "sync"
+    threads = 4
+    timeout = 30
+    max_requests = 1000
+    capture_output = True
 ```
-2) Set up a configuration file ```nano core/config_template.py```
+
+And this is how these settings are applied in the *core/gunicorn.py* configuration file used when starting Gunicorn:
+
 ```python
-#Create file config.py with this setting or rename this file to config.py
-
-#BASE
-DEBUG=True
-SECRET_KEY='secret-key(absolutely any character)'
-ALLOWED_HOSTS = ['127.0.0.1']
-CSRF_TRUSTED_ORIGINS = []
-
-#DATABSE
-DB_NAME=None
-DB_USER=None
-DB_PASSWORD=None
-DB_HOST=None
-
-#GUNICORN
-BIND = "127.0.0.1:8000"
-WORKERS = 2
-THREADS = 4
-
-#STATIC
-from pathlib import Path
-import os
-BASE_DIR = Path(__file__).resolve().parent.parent
-STATIC_URL = '/static/'
-STATICFILES_DIRS = [BASE_DIR / "SharixAdmin/static/", BASE_DIR / "tickets/static/"]
-STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
-```
-3) Run a **install_linux.sh**
-4) The system will prompt you to create a superuser
-```
-#Example
-7987654321
-admin
-pa$$w0rd
-pa$$w0rd
-```
-5) Set up the **bin/webuser.sh** file with valid paths
-```bash
-#!/bin/bash
-cd /path/to/project
-exec /path/to/project/env/bin/gunicorn core.wsgi:application -c core/conf_gunicorn.py
+# core/gunicorn.py
+
+from core.utils import setup
+from core.config import ConfigGunicorn
+
+setup(locals(), ConfigGunicorn)
 ```
-6) It remains to configure Nginx conf and start the daemon
 
-## Settings
+This approach provides more convenient project configuration and allows you to store settings for development and production use.
 
-Optional configuration params, which can be added to your project settings:
+To configure special settings, such as changing the database type or specifying domain names for deployment in production that do not match the default settings for the web application, make changes to the *core/config.py* file. If these changes later become necessary for the basic installation of the web application, they should also be made in *core/_config.py*.
 
-```python
+To apply your own classes with configurations, follow the usage example above.
 
-```
+## Launch 
+
+To start the web application on Unix, run *bin/start.sh*.

+ 21 - 0
bin/install.bat

@@ -0,0 +1,21 @@
+git clone -b master http://git.sharix-app.org/ShariX_Open/sharix-open-tickets.git tickets
+git clone -b metasynced_module http://git.sharix-app.org/ShariX_Open/sharix-open-backend.git metaservicesynced
+git clone -b webinterface https://git.sharix-app.org/ShariX_Open/sharix-open-webadmin.git SharixAdmin/templates/SharixAdmin
+
+python -m venv venv
+.\venv\Scripts\activate
+
+pip install --upgrade pip
+pip install -r requirements.txt
+
+if exist core\config.py (
+    echo File config.py already created
+) else (
+    copy core\_config.py core\config.py
+    echo File config.py was successfully created
+)
+
+python manage.py makemigrations SharixAdmin metaservicesynced tickets
+python manage.py migrate
+python manage.py collectstatic -l --no-input
+python manage.py createsuperuser

+ 26 - 0
bin/install.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+
+git clone -b master https://git.sharix-app.org/ShariX_Open/sharix-open-tickets.git tickets
+git clone -b metasynced_module https://git.sharix-app.org/ShariX_Open/sharix-open-backend.git metaservicesynced
+git clone -b webinterface https://git.sharix-app.org/ShariX_Open/sharix-open-webadmin.git SharixAdmin/templates/SharixAdmin
+git clone -b master https://git.sharix-app.org/ShariX_Open/sharix-open-config.git conf
+
+python3 -m venv venv
+source venv/bin/activate
+
+pip install --upgrade pip
+pip install -r requirements.txt
+
+if [ -f core/config.py ]; then
+    echo "File config.py already created"
+else
+    cp core/_config.py core/config.py
+    echo "File config.py was successfully created"
+fi
+
+python manage.py makemigrations SharixAdmin metaservicesynced tickets
+python manage.py migrate
+python manage.py collectstatic -l --no-input
+python manage.py createsuperuser
+
+#cp conf/sharix_open.service /etc/systemd/system/

+ 11 - 0
bin/start.sh

@@ -0,0 +1,11 @@
+#!/bin/bash
+
+#cd <path to project>
+
+venv\bin\activate
+
+python manage.py makemigrations
+python manage.py migrate
+python manage.py collectstatic -l --noinput
+
+gunicorn core.wsgi:application -c core/gunicorn.py

+ 0 - 5
bin/webuser.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-#cd /path/to/project
-cd /root/sharix-open-webapp-base
-#exec /path/to/project/env/bin/gunicorn core.wsgi:application -c core/conf_gunicorn.py
-exec /root/sharix-open-webapp-base/env/bin/gunicorn core.wsgi:application -c core/conf_gunicorn.py

+ 0 - 3
bin/webuser.sh~

@@ -1,3 +0,0 @@
-#!/bin/bash
-cd /path/to/project
-exec /path/to/project/env/bin/gunicorn core.wsgi:application -c core/conf_gunicorn.py

+ 372 - 0
core/_config.py

@@ -0,0 +1,372 @@
+import os
+
+from pathlib import Path
+
+from django.contrib.messages import constants as message_constants
+
+
+class ConfigDjango:
+    # Build paths inside the project like this: BASE_DIR / 'subdir'.
+    BASE_DIR = Path(__file__).resolve().parent.parent
+
+    # SECURITY WARNING: keep the secret key used in production secret!
+    SECRET_KEY = 'django-insecure-$eodx2ilnb*djkahfguiwegbwelgbnajl*u$qkt7j-b)7t1iq'
+    # SECURITY WARNING: don't run with debug turned on in production!
+    DEBUG = True
+    CSRF_TRUSTED_ORIGINS = []
+    ALLOWED_HOSTS = ["127.0.0.1"]
+    INTERNAL_IPS = ["127.0.0.1"]
+
+    # Application definition
+    INSTALLED_APPS = [
+        'jazzmin',
+        'django.contrib.admin',
+        'django.contrib.auth',
+        'django.contrib.contenttypes',
+        'django.contrib.sessions',
+        'django.contrib.messages',
+        'django.contrib.staticfiles',
+        'SharixAdmin.apps.SharixadminConfig',
+        'tickets.apps.TicketsConfig',
+        'metaservicesynced.apps.MetaservicesyncedConfig',
+        'django_tables2',
+        "django.contrib.sites",
+        "django.contrib.flatpages",
+        "django.contrib.admindocs",
+        "django_extensions",
+        'rest_framework',
+        'rest_framework.authtoken',
+        'djoser',
+        'schema_graph',
+        'drf_yasg',
+        'django_spaghetti',
+        'debug_toolbar',
+    ]
+
+    MIDDLEWARE = [
+        'django.middleware.security.SecurityMiddleware',
+        'django.contrib.sessions.middleware.SessionMiddleware',
+        'django.middleware.common.CommonMiddleware',
+        'django.middleware.csrf.CsrfViewMiddleware',
+        'django.contrib.auth.middleware.AuthenticationMiddleware',
+        'django.contrib.messages.middleware.MessageMiddleware',
+        'django.middleware.clickjacking.XFrameOptionsMiddleware',
+        'django.contrib.admindocs.middleware.XViewMiddleware',        
+        "debug_toolbar.middleware.DebugToolbarMiddleware",
+    ]
+
+    ROOT_URLCONF = "core.urls"
+
+    SESSION_EXPIRE_AT_BROWSER_CLOSE = False
+    SESSION_SECURITY_WARN_AFTER = 5
+    SESSION_SECURITY_EXPIRE_AFTER = 12
+
+    TEMPLATES = [
+        {
+            "BACKEND": "django.template.backends.django.DjangoTemplates",
+            "DIRS": [os.path.join(BASE_DIR, "templates")],
+            "APP_DIRS": True,
+            "OPTIONS": {
+                "context_processors": [
+                    "django.template.context_processors.debug",
+                    "django.template.context_processors.request",
+                    "django.contrib.auth.context_processors.auth",
+                    "django.template.context_processors.i18n",
+                    "django.template.context_processors.media",
+                    "django.template.context_processors.static",
+                    "django.template.context_processors.tz",
+                    "django.contrib.messages.context_processors.messages",
+                ],
+            },
+        }
+    ]
+
+    WSGI_APPLICATION = 'core.wsgi.application'
+
+    # Database
+    # https://docs.djangoproject.com/en/4.0/ref/settings/#databases
+    DATABASES = {
+        'default': {
+            'ENGINE': 'django.db.backends.sqlite3',
+            'NAME': BASE_DIR / 'db.sqlite3',
+        }
+    }
+
+    # Password validation
+    # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
+    AUTH_PASSWORD_VALIDATORS = [
+        {
+            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+        },
+        {
+            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+        },
+        {
+            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+        },
+        {
+            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+        },
+    ]
+
+    # Internationalization
+    # https://docs.djangoproject.com/en/4.0/topics/i18n/
+    LANGUAGE_CODE = 'ru'
+    USE_TZ = True
+    TIME_ZONE = 'Europe/Moscow'
+    SITE_ID = 1
+
+    # If you set this to False, Django will make some optimizations so as not
+    # to load the internationalization machinery.
+    USE_I18N = True
+
+    # Static files (CSS, JavaScript, Images)
+    # https://docs.djangoproject.com/en/4.0/howto/static-files/
+    STATIC_URL = "/static/"
+    STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
+
+    # Uploaded media
+    MEDIA_URL = "/media/"
+    MEDIA_ROOT = os.path.join(BASE_DIR, "media")
+
+    # Without this, uploaded files > 4MB end up with perm 0600, unreadable by web server process
+    FILE_UPLOAD_PERMISSIONS = 0o644
+
+    # Override CSS class for the ERROR tag level to match Bootstrap class name
+    MESSAGE_TAGS = {message_constants.ERROR: "danger"}
+
+    # Default primary key field type
+    # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
+    DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
+
+    AUTH_USER_MODEL = 'SharixAdmin.SharixUser'
+
+
+class ConfigJazzmin:
+    JAZZMIN_SETTINGS = {
+        # title of the window (Will default to current_admin_site.site_title if absent or None)
+        "site_title": "ShariX Admin",
+
+        # Title on the login screen (19 chars max) (defaults to current_admin_site.site_header if absent or None)
+        "site_header": "ShariX Platform",
+
+        # Title on the brand (19 chars max) (defaults to current_admin_site.site_header if absent or None)
+        "site_brand": "ShariX Platform",
+
+        # Logo to use for your site, must be present in static files, used for brand on top left
+        "site_logo": "SharixAdmin/img/logo.svg",
+
+        # Logo to use for your site, must be present in static files, used for login form logo (defaults to site_logo)
+        "login_logo": None,
+
+        # Logo to use for login form in dark themes (defaults to login_logo)
+        "login_logo_dark": None,
+
+        # CSS classes that are applied to the logo above
+        "site_logo_classes": "img-circle",
+
+        # Relative path to a favicon for your site, will default to site_logo if absent (ideally 32x32 px)
+        "site_icon": None,
+
+        # Welcome text on the login screen
+        "welcome_sign": "Welcome to the ShariX Admin",
+
+        # Copyright on the footer
+        "copyright": "Acme Library Ltd",
+
+        # List of model admins to search from the search bar, search bar omitted if excluded
+        # If you want to use a single search field you dont need to use a list, you can use a simple string 
+        "search_model": ["SharixAdmin.SharixUser"],
+
+        # Field name on user model that contains avatar ImageField/URLField/Charfield or a callable that receives the user
+        "user_avatar": "",
+
+        ############
+        # Top Menu #
+        ############
+
+        # Links to put along the top menu
+        "topmenu_links": [
+
+            # Url that gets reversed (Permissions can be added)
+            {"name": "Главная",  "url": "admin:index", "permissions": ["auth.view_user"]},
+
+            # external url that opens in a new window (Permissions can be added)
+            #{"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True},
+
+            # model admin to link to (Permissions checked against model)
+            {"model": "SharixAdmin.SharixUser"},
+
+            # App with dropdown menu to all its models pages (Permissions checked against models)
+            {"app": "tickets"},
+        ],
+
+        #############
+        # User Menu #
+        #############
+
+        # Additional links to include in the user menu on the top right ("app" url type is not allowed)
+        # "usermenu_links": [
+        #     {"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True},
+        #     {"model": "SharixAdmin.SharixUser"}
+        # ],
+
+        # #############
+        # # Side Menu #
+        # #############
+
+        # # Whether to display the side menu
+        # "show_sidebar": True,
+
+        # # Whether to aut expand the menu
+        # "navigation_expanded": True,
+
+        # # Hide these apps when generating side menu e.g (auth)
+        # "hide_apps": [],
+
+        # # Hide these models when generating side menu (e.g auth.user)
+        # "hide_models": [],
+
+        # # List of apps (and/or models) to base side menu ordering off of (does not need to contain all apps/models)
+        # #"order_with_respect_to": ["auth", "books", "books.author", "books.book"],
+
+        # # Custom links to append to app groups, keyed on app name
+        # "custom_links": {
+        #     "tickets": [{
+        #         "name": "Make Messages", 
+        #         "url": "make_messages", 
+        #         "icon": "fas fa-comments",
+        #         "permissions": ["tickets.view_book"]
+        #     }]
+        # },
+
+        # # 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
+        # # for the full list of 5.13.0 free icon classes
+        "icons": {
+            "auth": "fas fa-users-cog",
+            "auth.user": "fas fa-user",
+            "auth.Group": "fas fa-users",
+            "SharixAdmin": "fas fa-users-cog",
+            "SharixAdmin.SharixUser": "fas fa-user",
+            "tickets.Task": "fas fa-check",
+            "tickets.TaskList": "fas fa-list",
+            "tickets.Comment": "fas fa-comment",
+            "tickets.Attachment": "fas fa-file",
+        },
+        # # Icons that are used when one is not manually specified
+        # # "default_icon_parents": "fas fa-chevron-circle-right",
+        # # "default_icon_children": "fas fa-circle",
+
+        # #################
+        # # Related Modal #
+        # #################
+        # # Use modals instead of popups
+        # "related_modal_active": False,
+
+        # #############
+        # # UI Tweaks #
+        # #############
+        # # Relative paths to custom CSS/JS scripts (must be present in static files)
+        "custom_css": None,
+        "custom_js": None,
+        # Whether to link font from fonts.googleapis.com (use custom_css to supply font otherwise)
+        "use_google_fonts_cdn": True,
+        # # Whether to show the UI customizer on the sidebar
+        "show_ui_builder": True,
+
+        ###############
+        # Change view #
+        ###############
+        # Render out the change view as a single form, or in tabs, current options are
+        # - single
+        # - horizontal_tabs (default)
+        # - vertical_tabs
+        # - collapsible
+        # - carousel
+        #"changeform_format": "horizontal_tabs",
+        # override change forms on a per modeladmin basis
+        #"changeform_format_overrides": {"SharixAdmin.SharixUser": "collapsible", "auth.group": "vertical_tabs"},
+        # Add a language dropdown into the admin
+        #"language_chooser": True,
+    }
+    JAZZMIN_UI_TWEAKS = {
+        "navbar_small_text": True,
+        "footer_small_text": True,
+        "body_small_text": False,
+        "brand_small_text": True,
+        "brand_colour": "navbar-light",
+        "accent": "accent-navy",
+        "navbar": "navbar-navy navbar-dark",
+        "no_navbar_border": False,
+        "navbar_fixed": False,
+        "layout_boxed": False,
+        "footer_fixed": False,
+        "sidebar_fixed": True,
+        "sidebar": "sidebar-light-navy",
+        "sidebar_nav_small_text": False,
+        "sidebar_disable_expand": False,
+        "sidebar_nav_child_indent": False,
+        "sidebar_nav_compact_style": True,
+        "sidebar_nav_legacy_style": False,
+        "sidebar_nav_flat_style": False,
+        "theme": "default",
+        "dark_mode_theme": None,
+        "button_classes": {
+            "primary": "btn-outline-primary",
+            "secondary": "btn-outline-secondary",
+            "info": "btn-outline-info",
+            "warning": "btn-outline-warning",
+            "danger": "btn-outline-danger",
+            "success": "btn-outline-success"
+        },
+        "actions_sticky_top": False
+    }
+
+
+class ConfigAPI:
+    REST_FRAMEWORK = {
+        # Use Django's standard `django.contrib.auth` permissions,
+        # or allow read-only access for unauthenticated users.
+        'DEFAULT_RENDERER_CLASSES':[
+            'rest_framework.renderers.JSONRenderer',
+            'rest_framework.renderers.BrowsableAPIRenderer',
+        ],
+        'DEFAULT_PERMISSION_CLASSES': [
+            #'rest_framework.permissions.AllowAny',
+            #'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
+        ],
+        'DEFAULT_AUTHENTICATION_CLASSES': (
+            'rest_framework.authentication.TokenAuthentication',
+            'rest_framework.authentication.BasicAuthentication',
+            'rest_framework.authentication.SessionAuthentication',
+        ),
+    }
+
+    SPAGHETTI_SAUCE = {
+        'apps': ['auth', 'SharixAdmin', 
+                'tickets', 'admin', 
+                'flatpages', 'sessions', 'sites', 'metaservicesynced'],
+        'show_fields': False,
+        'show_proxy':True,
+    }
+
+    GRAPH_MODELS = {
+        'all_applications': True,
+        'group_models': True,
+    }
+
+    DJOSER = {
+        'SERIALIZERS': {
+            'token': 'SharixAdmin.api.serializers.CustomTokenSerializer',
+        }
+    }
+
+
+class ConfigGunicorn:
+    bind = "127.0.0.1:8000"
+    workers = 2
+    worker_class = "sync"
+    threads = 4
+    timeout = 30
+    max_requests = 1000
+    capture_output = True

+ 0 - 29
core/api_settings.py

@@ -1,29 +0,0 @@
-REST_FRAMEWORK = {
-    # Use Django's standard `django.contrib.auth` permissions,
-    # or allow read-only access for unauthenticated users.
-    'DEFAULT_RENDERER_CLASSES':[
-        'rest_framework.renderers.JSONRenderer',
-        'rest_framework.renderers.BrowsableAPIRenderer',
-    ],
-    'DEFAULT_PERMISSION_CLASSES': [
-        #'rest_framework.permissions.AllowAny',
-        #'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
-    ],
-    'DEFAULT_AUTHENTICATION_CLASSES': (
-        'rest_framework.authentication.TokenAuthentication',
-        'rest_framework.authentication.BasicAuthentication',
-        'rest_framework.authentication.SessionAuthentication',
-    ),
-}
-
-SPAGHETTI_SAUCE = {
-    'apps': ['auth', 'SharixAdmin', 
-             'tickets', 'admin', 
-             'flatpages', 'sessions', 'sites', 'metaservicesynced'],
-    'show_fields': False,
-    'show_proxy':True,
-}
-GRAPH_MODELS = {
-  'all_applications': True,
-  'group_models': True,
-}

+ 0 - 9
core/conf_gunicorn.py

@@ -1,9 +0,0 @@
-#bind = "0.0.0.0:8001"
-import core.config as conf
-bind = conf.BIND
-workers = conf.WORKERS
-worker_class = "sync"
-threads = conf.THREADS
-timeout = 30
-max_requests = 1000
-capture_output = True

+ 0 - 24
core/db_settings.py

@@ -1,24 +0,0 @@
-from pathlib import Path
-import os
-import core.config as conf
-
-BASE_DIR = Path(__file__).resolve().parent.parent
-if conf.DB_NAME is None:
-    DATABASES = {
-        'default': {
-            'ENGINE': 'django.db.backends.sqlite3',
-            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
-        }
-    }
-else:
-    DATABASES = {
-        'default': {
-            'ENGINE': 'django.db.backends.postgresql',
-            'NAME': conf.DB_NAME,
-            'USER': conf.DB_USER,
-            'PASSWORD': conf.DB_PASSWORD,
-            'HOST': conf.DB_HOST,
-            'PORT': '5432',
-        }
-    }
-

+ 5 - 0
core/gunicorn.py

@@ -0,0 +1,5 @@
+from core.utils import setup
+from core.config import ConfigGunicorn
+
+
+setup(locals(), ConfigGunicorn)

+ 0 - 178
core/jazzmin_settings.py

@@ -1,178 +0,0 @@
-JAZZMIN_SETTINGS = {
-    # title of the window (Will default to current_admin_site.site_title if absent or None)
-    "site_title": "ShariX Admin",
-
-    # Title on the login screen (19 chars max) (defaults to current_admin_site.site_header if absent or None)
-    "site_header": "ShariX Platform",
-
-    # Title on the brand (19 chars max) (defaults to current_admin_site.site_header if absent or None)
-    "site_brand": "ShariX Platform",
-
-    # Logo to use for your site, must be present in static files, used for brand on top left
-    "site_logo": "SharixAdmin/img/logo.svg",
-
-    # Logo to use for your site, must be present in static files, used for login form logo (defaults to site_logo)
-    "login_logo": None,
-
-    # Logo to use for login form in dark themes (defaults to login_logo)
-    "login_logo_dark": None,
-
-    # CSS classes that are applied to the logo above
-    "site_logo_classes": "img-circle",
-
-    # Relative path to a favicon for your site, will default to site_logo if absent (ideally 32x32 px)
-    "site_icon": None,
-
-    # Welcome text on the login screen
-    "welcome_sign": "Welcome to the ShariX Admin",
-
-    # Copyright on the footer
-    "copyright": "Acme Library Ltd",
-
-    # List of model admins to search from the search bar, search bar omitted if excluded
-    # If you want to use a single search field you dont need to use a list, you can use a simple string 
-    "search_model": ["SharixAdmin.SharixUser"],
-
-    # Field name on user model that contains avatar ImageField/URLField/Charfield or a callable that receives the user
-    "user_avatar": "",
-
-    ############
-    # Top Menu #
-    ############
-
-    # Links to put along the top menu
-    "topmenu_links": [
-
-        # Url that gets reversed (Permissions can be added)
-        {"name": "Главная",  "url": "admin:index", "permissions": ["auth.view_user"]},
-
-        # external url that opens in a new window (Permissions can be added)
-        #{"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True},
-
-        # model admin to link to (Permissions checked against model)
-        {"model": "SharixAdmin.SharixUser"},
-
-        # App with dropdown menu to all its models pages (Permissions checked against models)
-        {"app": "tickets"},
-    ],
-
-    #############
-    # User Menu #
-    #############
-
-    # Additional links to include in the user menu on the top right ("app" url type is not allowed)
-    # "usermenu_links": [
-    #     {"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True},
-    #     {"model": "SharixAdmin.SharixUser"}
-    # ],
-
-    # #############
-    # # Side Menu #
-    # #############
-
-    # # Whether to display the side menu
-    # "show_sidebar": True,
-
-    # # Whether to aut expand the menu
-    # "navigation_expanded": True,
-
-    # # Hide these apps when generating side menu e.g (auth)
-    # "hide_apps": [],
-
-    # # Hide these models when generating side menu (e.g auth.user)
-    # "hide_models": [],
-
-    # # List of apps (and/or models) to base side menu ordering off of (does not need to contain all apps/models)
-    # #"order_with_respect_to": ["auth", "books", "books.author", "books.book"],
-
-    # # Custom links to append to app groups, keyed on app name
-    # "custom_links": {
-    #     "tickets": [{
-    #         "name": "Make Messages", 
-    #         "url": "make_messages", 
-    #         "icon": "fas fa-comments",
-    #         "permissions": ["tickets.view_book"]
-    #     }]
-    # },
-
-    # # 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
-    # # for the full list of 5.13.0 free icon classes
-    "icons": {
-        "auth": "fas fa-users-cog",
-        "auth.user": "fas fa-user",
-        "auth.Group": "fas fa-users",
-        "SharixAdmin": "fas fa-users-cog",
-        "SharixAdmin.SharixUser": "fas fa-user",
-        "tickets.Task": "fas fa-check",
-        "tickets.TaskList": "fas fa-list",
-        "tickets.Comment": "fas fa-comment",
-        "tickets.Attachment": "fas fa-file",
-    },
-    # # Icons that are used when one is not manually specified
-    # # "default_icon_parents": "fas fa-chevron-circle-right",
-    # # "default_icon_children": "fas fa-circle",
-
-    # #################
-    # # Related Modal #
-    # #################
-    # # Use modals instead of popups
-    # "related_modal_active": False,
-
-    # #############
-    # # UI Tweaks #
-    # #############
-    # # Relative paths to custom CSS/JS scripts (must be present in static files)
-     "custom_css": None,
-     "custom_js": None,
-    # Whether to link font from fonts.googleapis.com (use custom_css to supply font otherwise)
-     "use_google_fonts_cdn": True,
-    # # Whether to show the UI customizer on the sidebar
-    "show_ui_builder": True,
-
-    ###############
-    # Change view #
-    ###############
-    # Render out the change view as a single form, or in tabs, current options are
-    # - single
-    # - horizontal_tabs (default)
-    # - vertical_tabs
-    # - collapsible
-    # - carousel
-    #"changeform_format": "horizontal_tabs",
-    # override change forms on a per modeladmin basis
-    #"changeform_format_overrides": {"SharixAdmin.SharixUser": "collapsible", "auth.group": "vertical_tabs"},
-    # Add a language dropdown into the admin
-    #"language_chooser": True,
-}
-JAZZMIN_UI_TWEAKS = {
-    "navbar_small_text": True,
-    "footer_small_text": True,
-    "body_small_text": False,
-    "brand_small_text": True,
-    "brand_colour": "navbar-light",
-    "accent": "accent-navy",
-    "navbar": "navbar-navy navbar-dark",
-    "no_navbar_border": False,
-    "navbar_fixed": False,
-    "layout_boxed": False,
-    "footer_fixed": False,
-    "sidebar_fixed": True,
-    "sidebar": "sidebar-light-navy",
-    "sidebar_nav_small_text": False,
-    "sidebar_disable_expand": False,
-    "sidebar_nav_child_indent": False,
-    "sidebar_nav_compact_style": True,
-    "sidebar_nav_legacy_style": False,
-    "sidebar_nav_flat_style": False,
-    "theme": "default",
-    "dark_mode_theme": None,
-    "button_classes": {
-        "primary": "btn-outline-primary",
-        "secondary": "btn-outline-secondary",
-        "info": "btn-outline-info",
-        "warning": "btn-outline-warning",
-        "danger": "btn-outline-danger",
-        "success": "btn-outline-success"
-    },
-    "actions_sticky_top": False
-}

+ 5 - 144
core/settings.py

@@ -1,146 +1,7 @@
-from pathlib import Path
-import os
-from core.db_settings import *
-from core.api_settings import *
-from core.tickets_mail_settings import *
-from core.jazzmin_settings import *
-import core.config as conf
-# Build paths inside the project like this: BASE_DIR / 'subdir'.
-BASE_DIR = Path(__file__).resolve().parent.parent
-# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = conf.SECRET_KEY
-
-# SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = conf.DEBUG
-
-ALLOWED_HOSTS = conf.ALLOWED_HOSTS
-CSRF_TRUSTED_ORIGINS = conf.CSRF_TRUSTED_ORIGINS
-
-# Application definition
-INSTALLED_APPS = [
-    'jazzmin',
-    'django.contrib.admin',
-    'django.contrib.auth',
-    'django.contrib.contenttypes',
-    'django.contrib.sessions',
-    'django.contrib.messages',
-    'django.contrib.staticfiles',
-    'SharixAdmin.apps.SharixadminConfig',
-    'tickets.apps.ticketsConfig',
-    'metaservicesynced.apps.MetaservicesyncedConfig',
-    'openlocal.apps.OpenlocalConfig',
-    'django_tables2',
-    "django.contrib.sites",
-    "django.contrib.flatpages",
-    "django.contrib.admindocs",
-    "django_extensions",
-    'rest_framework',
-    'rest_framework.authtoken',
-    'djoser',
-    'schema_graph',
-    'drf_yasg',
-    'django_spaghetti',
-]
-
-MIDDLEWARE = [
-    'django.middleware.security.SecurityMiddleware',
-    'django.contrib.sessions.middleware.SessionMiddleware',
-    'django.middleware.common.CommonMiddleware',
-    'django.middleware.csrf.CsrfViewMiddleware',
-    'django.contrib.auth.middleware.AuthenticationMiddleware',
-    'django.contrib.messages.middleware.MessageMiddleware',
-    'django.middleware.clickjacking.XFrameOptionsMiddleware',
-    'django.contrib.admindocs.middleware.XViewMiddleware',
-]
-
-ROOT_URLCONF = 'core.urls'
-
-#SESSION_EXPIRE_AT_BROWSER_CLOSE = True
-#SESSION_SECURITY_WARN_AFTER = 5
-#SESSION_SECURITY_EXPIRE_AFTER = 12
-INTERNAL_IPS = [
-    '127.0.0.1',
-]
-
-TEMPLATES = [
-    {
-        'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': [
-            BASE_DIR / "templates"
-        ],
-        'APP_DIRS': True,
-        'OPTIONS': {
-            'context_processors': [
-                'django.template.context_processors.debug',
-                'django.template.context_processors.request',
-                'django.contrib.auth.context_processors.auth',
-                'django.contrib.messages.context_processors.messages',
-
-                "django.template.context_processors.i18n",
-                "django.template.context_processors.media",
-                "django.template.context_processors.static",
-                "django.template.context_processors.tz",
-            ],
-            'libraries': {
-                'custom_tags':'tickets.template_tags.custom_tags'
-            }
-        },
-    },
-]
-
-
-WSGI_APPLICATION = 'core.wsgi.application'
-
-# Password validation
-# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
-
-AUTH_PASSWORD_VALIDATORS = [
-    {
-        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
-    },
-    {
-        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
-    },
-    {
-        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
-    },
-    {
-        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
-    },
-]
-
-# Internationalization
-# https://docs.djangoproject.com/en/4.1/topics/i18n/
-
-LANGUAGE_CODE = 'ru'
-
-TIME_ZONE = 'UTC'
-
-USE_I18N = True
-
-USE_TZ = True
-
-SITE_ID = 1
-
-# Static files (CSS, JavaScript, Images)
-# https://docs.djangoproject.com/en/4.1/howto/static-files/
-
-STATIC_URL = conf.STATIC_URL
-STATICFILES_DIRS = conf.STATICFILES_DIRS
-STATIC_ROOT = conf.STATIC_ROOT
-# Uploaded media
-MEDIA_ROOT = os.path.join(BASE_DIR, "media")
-MEDIA_URL = "/media/"
-
-# Default primary key field type
-# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
-
-DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
-
-AUTH_USER_MODEL = 'SharixAdmin.SharixUser'
-
-
-
-
+from core.utils import setup
+from core.config import ConfigDjango, ConfigJazzmin, ConfigAPI
 
 
+setup(locals(), ConfigDjango)
+setup(locals(), ConfigJazzmin)
+setup(locals(), ConfigAPI)

+ 0 - 31
core/tickets_mail_settings.py

@@ -1,31 +0,0 @@
-#LOGIN_REDIRECT_URL = "tickets:lists"
-#LOGIN_URL = "/accounts/login/"
-#LOGOUT_REDIRECT_URL = "/accounts/login/"
-# tickets-specific settings
-TICKETS_STAFF_ONLY = False
-TICKETS_DEFAULT_LIST_SLUG = 'tickets'
-TICKETS_DEFAULT_ASSIGNEE = None
-TICKETS_PUBLIC_SUBMIT_REDIRECT = '/'
-
-from tickets.mail.producers import imap_producer
-from tickets.mail.consumers import tracker_consumer
-from tickets.mail.delivery import smtp_backend, console_backend
-
-# email notifications configuration
-# each task list can get its own delivery method
-IS_SEND_EMAIL = False
-# TICKETS_MAIL_BACKENDS = {
-#     # mail-queue is the name of the task list, not the worker name
-#     "mail-queue": smtp_backend(
-#         host="*********",
-#         port=465,
-#         use_ssl=True,
-#         username="*********",
-#         password="*********",
-#         # used as the From field when sending notifications.
-#         # a username might be prepended later on
-#         from_address="*******",
-#         # additionnal headers
-#         headers={}
-#     ),
-# }

+ 6 - 12
core/urls.py

@@ -4,22 +4,16 @@ from django.urls import path, include
 from django.conf.urls.static import static
 
 
-
-urlpatterns = (
-    [
+urlpatterns = [
     path('admin/doc/', include('django.contrib.admindocs.urls')),
     path('admin/', admin.site.urls),
     path('', include('SharixAdmin.urls')),
-    path('tickets/', include("tickets.urls"), name='tickets'),
-    #metaservice
+    path('tickets/', include('tickets.urls', namespace='tickets'), name='tickets'),
     path('metaservicesynced/', include("metaservicesynced.urls"), name="metaservicesynced"),
-    path('openlocal/', include("openlocal.urls"), name="openlocal"),
-    
-
 ] 
-+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
-+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
-)
 
 if settings.DEBUG:
-    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+   urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
+   urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+   
+   urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))

+ 8 - 0
core/utils.py

@@ -0,0 +1,8 @@
+def setup(local_namespace: dict, config_class):
+    """setup(local_namespace: dict, config_class)
+
+    Adds all attributes of the configuration class
+    to the passed namespace as ordinary variables.
+    
+    """
+    local_namespace.update(vars(config_class))

+ 0 - 16
install_unix.sh

@@ -1,16 +0,0 @@
-#!/bin/bash
-git clone -b unstable https://git.sharix-app.org/ShariX_Open/sharix-open-tickets.git tickets
-git clone -b metasynced_module https://git.sharix-app.org/ShariX_Open/sharix-open-backend.git metaservicesynced
-git clone -b webinterface https://git.sharix-app.org/ShariX_Open/sharix-open-webadmin.git SharixAdmin/templates/SharixAdmin
-git clone -b master https://git.sharix-app.org/ShariX_Open/sharix-open-local.git openlocal
-git clone -b master https://git.sharix-app.org/ShariX_Open/sharix-open-config.git conf
-python3 -m venv env
-source env/bin/activate
-pip3 install --upgrade pip
-pip3 install -r requirements.txt
-python3 manage.py makemigrations
-python3 manage.py migrate
-python3 manage.py collectstatic
-python3 manage.py createsuperuser
-deactivate
-cp conf/sharix_open.service /etc/systemd/system/

+ 0 - 7
install_win.bat

@@ -1,7 +0,0 @@
-@echo off
-git clone -b unstable http://git.sharix-app.org/ShariX_Open/sharix-open-tickets.git tickets
-git clone -b metasynced_module http://git.sharix-app.org/ShariX_Open/sharix-open-backend.git metaservicesynced
-git clone -b webinterface https://git.sharix-app.org/ShariX_Open/sharix-open-webadmin.git SharixAdmin/templates/SharixAdmin
-git clone -b master https://git.sharix-app.org/ShariX_Open/sharix-open-local.git openlocal
-python -m venv env
-.\env\Scripts\activate && pip install -r requirements.txt && python manage.py makemigrations && python manage.py migrate && python manage.py createsuperuser && python manage.py runserver

+ 1 - 0
requirements.txt

@@ -10,6 +10,7 @@ coreschema==0.0.4
 cryptography==39.0.0
 defusedxml==0.7.1
 Django==4.1.3
+django-debug-toolbar==4.1.0
 django-extensions==3.2.1
 django-jazzmin==2.6.0
 django-schema-graph==2.2.1