config project

This commit is contained in:
Mikan
2024-09-13 19:23:57 +03:00
parent ee518bd7dc
commit 553a597cc5
7 changed files with 101 additions and 9 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/db.sqlite3
/config.json

View File

@@ -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"

19
bd_config.py Normal file
View File

@@ -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)

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
Django~=4.2.13
django-cors-headers

View File

@@ -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)

18
users/admin_forms.py Normal file
View File

@@ -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",)

View File

@@ -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 = 'Пользователи'