diff --git a/offer_backend/.gitignore b/offer_backend/.gitignore new file mode 100644 index 0000000..57394ce --- /dev/null +++ b/offer_backend/.gitignore @@ -0,0 +1,12 @@ +.env +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +*.egg-info/ +dist/ +build/ +media/ +staticfiles/ +db.sqlite3 diff --git a/offer_backend/config/__init__.py b/offer_backend/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/offer_backend/config/asgi.py b/offer_backend/config/asgi.py new file mode 100644 index 0000000..787b362 --- /dev/null +++ b/offer_backend/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_asgi_application() diff --git a/offer_backend/config/settings/__init__.py b/offer_backend/config/settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/offer_backend/config/settings/base.py b/offer_backend/config/settings/base.py new file mode 100644 index 0000000..3982c90 --- /dev/null +++ b/offer_backend/config/settings/base.py @@ -0,0 +1,89 @@ +from pathlib import Path +from decouple import config + +BASE_DIR = Path(__file__).resolve().parent.parent.parent + +SECRET_KEY = config('SECRET_KEY') + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + # Third party + 'rest_framework', + 'rest_framework_simplejwt', + 'corsheaders', + 'django_filters', + # Local + 'apps.accounts', + 'apps.organizations', + 'apps.jobs', + 'apps.resumes', + 'apps.applications', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'corsheaders.middleware.CorsMiddleware', + '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', +] + +ROOT_URLCONF = 'config.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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', + ], + }, + }, +] + +AUTH_USER_MODEL = 'accounts.User' + +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework_simplejwt.authentication.JWTAuthentication', + ), + 'DEFAULT_PERMISSION_CLASSES': ( + 'rest_framework.permissions.IsAuthenticated', + ), + 'DEFAULT_FILTER_BACKENDS': [ + 'django_filters.rest_framework.DjangoFilterBackend', + 'rest_framework.filters.SearchFilter', + 'rest_framework.filters.OrderingFilter', + ], + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'PAGE_SIZE': 20, +} + +from datetime import timedelta +SIMPLE_JWT = { + 'ACCESS_TOKEN_LIFETIME': timedelta(hours=2), + 'REFRESH_TOKEN_LIFETIME': timedelta(days=7), +} + +STATIC_URL = '/static/' +MEDIA_URL = '/media/' +MEDIA_ROOT = BASE_DIR / 'media' + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +LANGUAGE_CODE = 'zh-hans' +TIME_ZONE = 'Asia/Shanghai' +USE_I18N = True +USE_TZ = True diff --git a/offer_backend/config/settings/development.py b/offer_backend/config/settings/development.py new file mode 100644 index 0000000..8bd9d9e --- /dev/null +++ b/offer_backend/config/settings/development.py @@ -0,0 +1,26 @@ +from .base import * + +DEBUG = True +ALLOWED_HOSTS = ['*'] + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': config('DB_NAME', default='offer_db'), + 'USER': config('DB_USER', default='postgres'), + 'PASSWORD': config('DB_PASSWORD', default='postgres'), + 'HOST': config('DB_HOST', default='localhost'), + 'PORT': config('DB_PORT', default='5432'), + } +} + +CACHES = { + 'default': { + 'BACKEND': 'django_redis.cache.RedisCache', + 'LOCATION': config('REDIS_URL', default='redis://127.0.0.1:6379/1'), + } +} + +CORS_ALLOW_ALL_ORIGINS = True + +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' diff --git a/offer_backend/config/urls.py b/offer_backend/config/urls.py new file mode 100644 index 0000000..813a165 --- /dev/null +++ b/offer_backend/config/urls.py @@ -0,0 +1,13 @@ +from django.contrib import admin +from django.urls import path, include +from django.conf import settings +from django.conf.urls.static import static + +urlpatterns = [ + path('admin/', admin.site.urls), + path('api/auth/', include('apps.accounts.urls')), + path('api/organizations/', include('apps.organizations.urls')), + path('api/jobs/', include('apps.jobs.urls')), + path('api/resumes/', include('apps.resumes.urls')), + path('api/applications/', include('apps.applications.urls')), +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/offer_backend/config/wsgi.py b/offer_backend/config/wsgi.py new file mode 100644 index 0000000..8ae71e3 --- /dev/null +++ b/offer_backend/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_wsgi_application() diff --git a/offer_backend/manage.py b/offer_backend/manage.py new file mode 100644 index 0000000..8e7ac79 --- /dev/null +++ b/offer_backend/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/offer_backend/requirements.txt b/offer_backend/requirements.txt new file mode 100644 index 0000000..8b13725 --- /dev/null +++ b/offer_backend/requirements.txt @@ -0,0 +1,10 @@ +Django==4.2.20 +djangorestframework==3.16.0 +djangorestframework-simplejwt==5.3.1 +django-cors-headers==4.3.1 +django-filter==23.5 +psycopg2-binary==2.9.9 +redis==5.0.1 +django-redis==5.4.0 +Pillow==10.3.0 +python-decouple==3.8