new first commit
This commit is contained in:
commit
51050a362a
|
@ -0,0 +1,101 @@
|
|||
# Django #
|
||||
*.log
|
||||
*.pot
|
||||
*.pyc
|
||||
__pycache__
|
||||
db.sqlite3
|
||||
media
|
||||
|
||||
# Configs #git init
|
||||
*.cnf
|
||||
|
||||
# Backup files #
|
||||
*.bak
|
||||
|
||||
# If you are using PyCharm #
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
*.iws /out/
|
||||
|
||||
# Python #
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# Distribution / packaging
|
||||
.Python build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
.pytest_cache/
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery
|
||||
celerybeat-schedule.*
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
# Package control specific files Package
|
||||
Control.last-run
|
||||
Control.ca-list
|
||||
Control.ca-bundle
|
||||
Control.system-ca-bundle
|
||||
GitHub.sublime-settings
|
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/env" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (bij1-backend)" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/backend.iml" filepath="$PROJECT_DIR$/.idea/backend.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,11 @@
|
|||
from django.contrib import admin
|
||||
from .models import *
|
||||
|
||||
admin.site.register(Department)
|
||||
admin.site.register(Role)
|
||||
admin.site.register(Province)
|
||||
admin.site.register(Township)
|
||||
admin.site.register(Neighbourhood)
|
||||
admin.site.register(Election)
|
||||
admin.site.register(Member)
|
||||
admin.site.register(ElectionNeighbourhood)
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'api'
|
|
@ -0,0 +1,99 @@
|
|||
# Generated by Django 3.2.5 on 2021-07-26 18:58
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Department',
|
||||
fields=[
|
||||
('_id', models.AutoField(editable=False, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Election',
|
||||
fields=[
|
||||
('_id', models.AutoField(editable=False, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('date', models.DateField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Province',
|
||||
fields=[
|
||||
('_id', models.AutoField(editable=False, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Township',
|
||||
fields=[
|
||||
('_id', models.AutoField(editable=False, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('province', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='api.province')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Role',
|
||||
fields=[
|
||||
('_id', models.AutoField(editable=False, primary_key=True, serialize=False)),
|
||||
('role', models.CharField(choices=[(1, 'Administrator'), (2, 'Manager'), (3, 'User'), (4, 'Guest')], max_length=1)),
|
||||
('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.department')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Neighbourhood',
|
||||
fields=[
|
||||
('_id', models.AutoField(editable=False, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('code', models.CharField(max_length=20)),
|
||||
('district', models.CharField(max_length=20)),
|
||||
('residents', models.IntegerField()),
|
||||
('township', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='api.township')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Member',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('member', models.CharField(max_length=100)),
|
||||
('registrationDate', models.DateField()),
|
||||
('active', models.BooleanField()),
|
||||
('neighbourhood', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='api.neighbourhood')),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ElectionNeighbourhood',
|
||||
fields=[
|
||||
('_id', models.AutoField(editable=False, primary_key=True, serialize=False)),
|
||||
('flyer', models.BooleanField()),
|
||||
('status', models.DecimalField(decimal_places=2, max_digits=3)),
|
||||
('election', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.election')),
|
||||
('neighbourhood', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.neighbourhood')),
|
||||
('responsible', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='api.member')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='election',
|
||||
name='neighbourhoods',
|
||||
field=models.ManyToManyField(through='api.ElectionNeighbourhood', to='api.Neighbourhood'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='department',
|
||||
name='users',
|
||||
field=models.ManyToManyField(through='api.Role', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,77 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class Department(models.Model):
|
||||
_id = models.AutoField(primary_key=True, editable=False)
|
||||
name = models.CharField(max_length=200, null=False, blank=False)
|
||||
users = models.ManyToManyField(User, through='Role')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Role(models.Model):
|
||||
_id = models.AutoField(primary_key=True, editable=False)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, null=False)
|
||||
department = models.ForeignKey(Department, on_delete=models.CASCADE, null=False)
|
||||
DEPARTMENT_ROLES = (
|
||||
(1, 'Administrator'),
|
||||
(2, 'Manager'),
|
||||
(3, 'User'),
|
||||
(4, 'Guest'),
|
||||
)
|
||||
role = models.CharField(max_length=1, choices=DEPARTMENT_ROLES)
|
||||
|
||||
|
||||
class Province(models.Model):
|
||||
_id = models.AutoField(primary_key=True, editable=False)
|
||||
name = models.CharField(max_length=200, null=False, blank=False)
|
||||
|
||||
|
||||
class Township(models.Model):
|
||||
_id = models.AutoField(primary_key=True, editable=False)
|
||||
name = models.CharField(max_length=200, null=False, blank=False)
|
||||
province = models.ForeignKey(Province, on_delete=models.CASCADE, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Neighbourhood(models.Model):
|
||||
_id = models.AutoField(primary_key=True, editable=False)
|
||||
name = models.CharField(max_length=200, null=False, blank=False)
|
||||
code = models.CharField(max_length=20, null=False, blank=False)
|
||||
district = models.CharField(max_length=20, null=False, blank=False)
|
||||
township = models.ForeignKey(Township, on_delete=models.CASCADE, null=True, blank=True)
|
||||
residents = models.IntegerField(null=False, blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Election(models.Model):
|
||||
_id = models.AutoField(primary_key=True, editable=False)
|
||||
neighbourhoods = models.ManyToManyField(Neighbourhood, through='ElectionNeighbourhood')
|
||||
name = models.CharField(max_length=200, null=False, blank=False)
|
||||
date = models.DateField(null=False, blank=False)
|
||||
|
||||
|
||||
class Member(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
member = models.CharField(max_length=100)
|
||||
neighbourhood = models.ForeignKey(Neighbourhood, on_delete=models.CASCADE, null=True, blank=True)
|
||||
registrationDate = models.DateField(null=False, blank=False)
|
||||
active = models.BooleanField(null=False, blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
|
||||
|
||||
class ElectionNeighbourhood(models.Model):
|
||||
_id = models.AutoField(primary_key=True, editable=False)
|
||||
election = models.ForeignKey(Election, on_delete=models.CASCADE, null=False, related_name='election_to_neighbourhood')
|
||||
neighbourhood = models.ForeignKey(Neighbourhood, on_delete=models.CASCADE, null=False, related_name='neighbourhood_to_election')
|
||||
responsible = models.ForeignKey(Member, on_delete=models.CASCADE, null=True, blank=True)
|
||||
flyer = models.BooleanField(null=False, blank=False)
|
||||
status = models.DecimalField(max_digits=3, decimal_places=2, null=False, blank=False)
|
|
@ -0,0 +1,68 @@
|
|||
from rest_framework import serializers
|
||||
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
||||
from .models import *
|
||||
|
||||
|
||||
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
|
||||
def create(self, validated_data):
|
||||
pass
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
pass
|
||||
|
||||
def validate(self, attrs):
|
||||
data = super().validate(attrs)
|
||||
|
||||
data['username'] = self.user.username
|
||||
data['email'] = self.user.email
|
||||
data['id'] = self.user.id
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class MemberSerializer(serializers.ModelSerializer):
|
||||
neighbourhood = serializers.StringRelatedField(many=False)
|
||||
|
||||
class Meta:
|
||||
model = Member
|
||||
fields = ('member', 'registrationDate', 'active', 'neighbourhood')
|
||||
|
||||
|
||||
class UserDetailsSerializer(serializers.ModelSerializer):
|
||||
member = MemberSerializer(many=False)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name', 'username', 'member')
|
||||
|
||||
|
||||
class NeighbourhoodSerializer(serializers.ModelSerializer):
|
||||
township = serializers.StringRelatedField(many=False)
|
||||
|
||||
class Meta:
|
||||
model = Neighbourhood
|
||||
fields = ('_id', 'name', 'code', 'district', 'residents', 'township')
|
||||
|
||||
|
||||
class ElectionNeighbourhoodSerializer(serializers.ModelSerializer):
|
||||
neighbourhood = NeighbourhoodSerializer(many=False)
|
||||
responsible = serializers.StringRelatedField(many=False)
|
||||
|
||||
class Meta:
|
||||
model = ElectionNeighbourhood
|
||||
fields = ('neighbourhood', 'responsible', 'flyer', 'status')
|
||||
|
||||
|
||||
class ElectionSerializer(serializers.ModelSerializer):
|
||||
# neighbourhoods = NeighbourhoodSerializer(many=True, read_only=True)
|
||||
election_to_neighbourhood = ElectionNeighbourhoodSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = Election
|
||||
fields = ('_id', 'name', 'date', 'election_to_neighbourhood')
|
||||
|
||||
|
||||
class DepartmentSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Department
|
||||
fields = '__all__'
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,11 @@
|
|||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('users/login', views.MyTokenObtainPairView.as_view(), name='token_obtain_pair'),
|
||||
path('routes', views.getRoutes, name="routes"),
|
||||
path('users/<str:pk>', views.getUserDetails, name="user-details"),
|
||||
path('departments/', views.getDepartments, name="departments"),
|
||||
path('election/', views.getLatestElection, name="election"),
|
||||
# path('users/', views.getUsers, name="users"),
|
||||
]
|
|
@ -0,0 +1,52 @@
|
|||
from rest_framework.decorators import api_view, permission_classes
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated, IsAdminUser
|
||||
from django.http import JsonResponse
|
||||
from .models import *
|
||||
from .serializers import DepartmentSerializer, UserDetailsSerializer, MyTokenObtainPairSerializer, ElectionSerializer
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||
|
||||
|
||||
class MyTokenObtainPairView(TokenObtainPairView):
|
||||
serializer_class = MyTokenObtainPairSerializer
|
||||
|
||||
|
||||
def getRoutes(request):
|
||||
routes = [
|
||||
'/api/users/',
|
||||
'/api/users/<id>'
|
||||
]
|
||||
return JsonResponse(routes, safe=False)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def getUserDetails(request, pk):
|
||||
if request.user.id == pk or request.user.is_staff:
|
||||
user = User.objects.get(id=pk)
|
||||
serializer = UserDetailsSerializer(user, many=False)
|
||||
return Response(serializer.data)
|
||||
else:
|
||||
return Response()
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def getDepartments(request):
|
||||
departments = Department.objects.all()
|
||||
serializer = DepartmentSerializer(departments, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def getLatestElection(request):
|
||||
election = Election.objects.latest('date')
|
||||
serializer = ElectionSerializer(election, many=False)
|
||||
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
#@api_view(['PUT'])
|
||||
#@permission_classes([IsAuthenticated])
|
||||
#def setNeigbourhoodResponsible(request):
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
ASGI config for backend 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/3.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
|
||||
|
||||
application = get_asgi_application()
|
|
@ -0,0 +1,6 @@
|
|||
[client]
|
||||
DATABASE: 'bij1'
|
||||
USER: 'root'
|
||||
PASSWORD: 'password'
|
||||
HOST: 'localhost'
|
||||
PORT: '3306'
|
|
@ -0,0 +1,167 @@
|
|||
"""
|
||||
Django settings for backend project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 3.2.3.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.2/ref/settings/
|
||||
"""
|
||||
import pymysql
|
||||
from pathlib import Path
|
||||
from datetime import timedelta
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-6q=jazhun$2=fuqfiax^qwjgi1d2e^4t_g!-)nq*6eo+_ng2h@'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'api',
|
||||
]
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
||||
)
|
||||
}
|
||||
|
||||
SIMPLE_JWT = {
|
||||
'ACCESS_TOKEN_LIFETIME': timedelta(days=30),
|
||||
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
|
||||
'ROTATE_REFRESH_TOKENS': False,
|
||||
'BLACKLIST_AFTER_ROTATION': True,
|
||||
'UPDATE_LAST_LOGIN': False,
|
||||
|
||||
'ALGORITHM': 'HS256',
|
||||
# 'SIGNING_KEY': settings.SECRET_KEY,
|
||||
'VERIFYING_KEY': None,
|
||||
'AUDIENCE': None,
|
||||
'ISSUER': None,
|
||||
|
||||
'AUTH_HEADER_TYPES': ('Bearer',),
|
||||
'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
|
||||
'USER_ID_FIELD': 'id',
|
||||
'USER_ID_CLAIM': 'user_id',
|
||||
'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule',
|
||||
|
||||
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
|
||||
'TOKEN_TYPE_CLAIM': 'token_type',
|
||||
|
||||
'JTI_CLAIM': 'jti',
|
||||
|
||||
'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
|
||||
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
|
||||
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
|
||||
}
|
||||
|
||||
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',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'backend.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',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'backend.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'OPTIONS': {
|
||||
'read_default_file': './backend/configs/mysql.cnf'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pymysql.version_info = (1, 4, 2, "final", 0)
|
||||
pymysql.install_as_MySQLdb()
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
@ -0,0 +1,22 @@
|
|||
"""backend URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/', include('api.urls')),
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for backend 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/3.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
|
||||
|
||||
application = get_wsgi_application()
|
|
@ -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', 'backend.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()
|
Loading…
Reference in New Issue