diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..258edfc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/db.sqlite3 +/config.json diff --git a/NovelPlus/settings.py b/NovelPlus/settings.py index 9cc3e91..75ae445 100644 --- a/NovelPlus/settings.py +++ b/NovelPlus/settings.py @@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ from pathlib import Path +from bd_config import default_database + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -25,7 +27,7 @@ SECRET_KEY = 'django-insecure-+l_9olvm8c90$1y39)ukodf4_zdt^4vhdf+n+b=^i9tyl$wki% # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["vnovelplus.temp.swtest.ru", "novelplus.ru", "localhost"] # Application definition @@ -37,12 +39,17 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'corsheaders', 'users.apps.UsersConfig', + 'frontend.apps.FrontendConfig', + 'store.apps.StoreConfig', + 'vacancy.apps.VacancyConfig' ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -76,10 +83,7 @@ WSGI_APPLICATION = 'NovelPlus.wsgi.application' # https://docs.djangoproject.com/en/4.2/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } + 'default': default_database } @@ -105,9 +109,9 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/4.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'ru-ru' -TIME_ZONE = 'UTC' +TIME_ZONE = 'Europe/Moscow' USE_I18N = True @@ -118,8 +122,20 @@ USE_TZ = True # https://docs.djangoproject.com/en/4.2/howto/static-files/ STATIC_URL = 'static/' +STATIC_ROOT = BASE_DIR / 'static' + +MEDIA_URL = '/media/' +MEDIA_ROOT = BASE_DIR / 'media' # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +CORS_ORIGIN_ALLOW_ALL = True + +CORS_ALLOW_CREDENTIALS = True + +X_FRAME_OPTIONS = "SAMEORIGIN" + +AUTH_USER_MODEL = "users.User" diff --git a/bd_config.py b/bd_config.py new file mode 100644 index 0000000..f6ffeaa --- /dev/null +++ b/bd_config.py @@ -0,0 +1,19 @@ +import json +import os +from pathlib import Path + +__all__ = ["default_database"] + +BASE_DIR = Path(__file__).resolve().parent + +if not os.path.exists('config.json'): + with open('config.json', 'w', encoding='utf-8') as config_file: + json.dump({ + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': str(BASE_DIR / 'db.sqlite3'), + }, config_file, ensure_ascii=False, indent=4) + + +with open('config.json', 'r', encoding='utf-8') as config_file: + + default_database = json.load(config_file) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bca13ee --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Django~=4.2.13 +django-cors-headers \ No newline at end of file diff --git a/users/admin.py b/users/admin.py index 8c38f3f..90f1b37 100644 --- a/users/admin.py +++ b/users/admin.py @@ -1,3 +1,31 @@ from django.contrib import admin +from django.contrib.auth.admin import UserAdmin -# Register your models here. +from users.admin_forms import UserCreationForm, UserChangeForm +from users.models import User + + +class CustomUserAdmin(UserAdmin): + add_form = UserCreationForm + form = UserChangeForm + model = User + list_display = ("username", "email", "is_staff",) + list_filter = ("username", "email", "is_staff",) + fieldsets = ( + (None, {"fields": ("username", "first_name", "last_name", "email", "password")}), + ("Разрешения", {"fields": ("is_staff", "is_active", "groups", "user_permissions")}), + ) + add_fieldsets = ( + (None, { + "classes": ("wide",), + "fields": ( + "email", "password1", "password2", "is_staff", + "is_active", "groups", "user_permissions" + )} + ), + ) + search_fields = ("email", "username", "email") + ordering = ("id",) + + +admin.site.register(User, CustomUserAdmin) diff --git a/users/admin_forms.py b/users/admin_forms.py new file mode 100644 index 0000000..d1c7406 --- /dev/null +++ b/users/admin_forms.py @@ -0,0 +1,18 @@ +from django.contrib.auth.forms import ( + UserCreationForm as DefaultUserCreationForm, + UserChangeForm as DefaultUserChangeForm +) + +from users.models import User + + +class UserCreationForm(DefaultUserCreationForm): + class Meta: + model = User + fields = ("email",) + + +class UserChangeForm(DefaultUserChangeForm): + class Meta: + model = User + fields = ("email",) diff --git a/users/models.py b/users/models.py index 71a8362..df1ab6b 100644 --- a/users/models.py +++ b/users/models.py @@ -1,3 +1,10 @@ +from django.contrib.auth.models import AbstractUser, UserManager from django.db import models -# Create your models here. +class User(AbstractUser): + + objects = UserManager() + class Meta: + db_table = 'auth_user' + verbose_name = 'Пользователь' + verbose_name_plural = 'Пользователи'