Base
This commit is contained in:
41
stat/Dockerfile
Normal file
41
stat/Dockerfile
Normal file
@ -0,0 +1,41 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
# declaration of service variables environment
|
||||
ENV STAT_SERVICE_NAME=${STAT_SERVICE_NAME}
|
||||
ENV DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME}
|
||||
ENV DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL}
|
||||
ENV DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD}
|
||||
ARG STAT_SERVICE_NAME
|
||||
ARG DJANGO_SUPERUSER_USERNAME
|
||||
ARG DJANGO_SUPERUSER_EMAIL
|
||||
ARG DJANGO_SUPERUSER_PASSWORD
|
||||
|
||||
COPY ./user_statistics /home/archive/${STAT_SERVICE_NAME}
|
||||
|
||||
# declaration of environment variables for python
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
RUN mkdir -p /home/archive
|
||||
WORKDIR /home/archive
|
||||
|
||||
# installation of dependencies
|
||||
COPY ./conf/requirements.txt .
|
||||
RUN pip3 install --no-cache-dir -r requirements.txt \
|
||||
&& mkdir depedencies && mv requirements.txt depedencies
|
||||
|
||||
# installation of postgresql-client
|
||||
RUN apt-get update && apt-get install -y postgresql-client
|
||||
|
||||
RUN apt-get update && apt-get install -y netcat-openbsd
|
||||
|
||||
RUN mkdir -p logs
|
||||
|
||||
# copy and execute the initialization script
|
||||
COPY ./tools/init.sh /home/archive/init.sh
|
||||
|
||||
# set the final working directory
|
||||
WORKDIR /home/archive/${STAT_SERVICE_NAME}
|
||||
|
||||
# Command for running the application
|
||||
CMD ["/bin/bash", "/home/archive/init.sh"]
|
||||
8
stat/conf/requirements.txt
Normal file
8
stat/conf/requirements.txt
Normal file
@ -0,0 +1,8 @@
|
||||
Django>=4.2,<4.3
|
||||
daphne==4.0.0
|
||||
djangorestframework==3.15.0
|
||||
psycopg2-binary>=2.9,<3.0
|
||||
django-environ
|
||||
django-cors-headers
|
||||
pillow
|
||||
pyotp
|
||||
22
stat/tools/init.sh
Normal file
22
stat/tools/init.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOGFILE="/home/archive/logs/setup.log"
|
||||
echo "initialisation of Django" >> $LOGFILE
|
||||
echo "backend name: $STAT_SERVICE_NAME" >> $LOGFILE
|
||||
|
||||
echo "initialisation of the project $STAT_SERVICE_NAME" >> $LOGFILE
|
||||
|
||||
echo "initialisation of Django done" >> $LOGFILE
|
||||
|
||||
echo "Waiting for postgres to get up and running..."
|
||||
while ! nc -z db_archive 5434; do
|
||||
echo "waiting for postgress to be listening..."
|
||||
sleep 1
|
||||
done
|
||||
#waiting for user to migrate
|
||||
sleep 5
|
||||
echo "PostgreSQL started"
|
||||
pip install -U 'Twisted[tls,http2]'
|
||||
python3 manage.py makemigrations
|
||||
python3 manage.py migrate
|
||||
daphne -b 0.0.0.0 -p 8005 user_statistics.asgi:application
|
||||
22
stat/user_statistics/manage.py
Executable file
22
stat/user_statistics/manage.py
Executable file
@ -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', 'user_statistics.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()
|
||||
0
stat/user_statistics/stat_management/__init__.py
Normal file
0
stat/user_statistics/stat_management/__init__.py
Normal file
3
stat/user_statistics/stat_management/admin.py
Normal file
3
stat/user_statistics/stat_management/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
10
stat/user_statistics/stat_management/apps.py
Normal file
10
stat/user_statistics/stat_management/apps.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.apps import AppConfig
|
||||
from user_statistics.settings import STAT_APP_NAME
|
||||
|
||||
|
||||
class StatManagementConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = f'{STAT_APP_NAME}'
|
||||
|
||||
def ready(self):
|
||||
import stat_management.signals
|
||||
55
stat/user_statistics/stat_management/models.py
Normal file
55
stat/user_statistics/stat_management/models.py
Normal file
@ -0,0 +1,55 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
class GameHistory(models.Model):
|
||||
player_1_id = models.ForeignKey(User, on_delete=models.CASCADE, related_name='player_1')
|
||||
player_2_id = models.ForeignKey(User, on_delete=models.CASCADE, related_name='player_2')
|
||||
player_1_score = models.IntegerField(default=0)
|
||||
player_2_score = models.IntegerField(default=0)
|
||||
winner_id = models.ForeignKey(User, on_delete=models.CASCADE, related_name='winner')
|
||||
date_played = models.DateTimeField(auto_now_add=True)
|
||||
duration = models.FloatField(default=0.0)
|
||||
|
||||
class Meta:
|
||||
db_table = 'users_game_history'
|
||||
|
||||
def __str__(self):
|
||||
return (f'{self.player_1_id} vs {self.player_2_id} '
|
||||
f'on {self.date_played} '
|
||||
f'winner is {self.winner_id} '
|
||||
f'score is {self.player_1_score} - {self.player_2_score}')
|
||||
|
||||
@property
|
||||
def player_1(self):
|
||||
return {'username': self.player_1_id.username, 'score': self.player_1_score}
|
||||
|
||||
@property
|
||||
def player_2(self):
|
||||
return {'username': self.player_2_id.username, 'score': self.player_2_score}
|
||||
|
||||
@property
|
||||
def winner(self):
|
||||
return {'username': self.winner_id.username}
|
||||
|
||||
class Stats(models.Model):
|
||||
player_id = models.ForeignKey(User, on_delete=models.CASCADE, related_name='player')
|
||||
wins = models.IntegerField(default=0)
|
||||
losses = models.IntegerField(default=0)
|
||||
win_rate = models.FloatField(default=0.0)
|
||||
total_games_played = models.IntegerField(default=0)
|
||||
total_hours_played = models.FloatField(default=0.0)
|
||||
goal_scored = models.IntegerField(default=0)
|
||||
goal_conceded = models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
db_table = 'users_stats'
|
||||
|
||||
def __str__(self):
|
||||
return (f'{self.player_id} wins: {self.wins}, losses: {self.losses}, win rate: {self.win_rate:.2f}, '
|
||||
f'total games: {self.total_games_played}, total hours played: {self.total_hours_played:.2f}, '
|
||||
f'goal scored: {self.goal_scored}, goal conceded: {self.goal_conceded}')
|
||||
|
||||
|
||||
29
stat/user_statistics/stat_management/serializers.py
Normal file
29
stat/user_statistics/stat_management/serializers.py
Normal file
@ -0,0 +1,29 @@
|
||||
from rest_framework import serializers
|
||||
from .models import GameHistory, Stats
|
||||
|
||||
class GameHistorySerializer(serializers.ModelSerializer):
|
||||
player_1 = serializers.SerializerMethodField()
|
||||
player_2 = serializers.SerializerMethodField()
|
||||
winner = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = GameHistory
|
||||
fields = [
|
||||
'id', 'player_1_id', 'player_1_score', 'player_2_score', 'player_2_id',
|
||||
'winner_id', 'player_1', 'player_2', 'winner', 'date_played', 'duration'
|
||||
]
|
||||
|
||||
def get_player_1(self, obj):
|
||||
return obj.player_1
|
||||
|
||||
def get_player_2(self, obj):
|
||||
return obj.player_2
|
||||
|
||||
def get_winner(self, obj):
|
||||
return obj.winner
|
||||
|
||||
|
||||
class StatsSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Stats
|
||||
fields = '__all__'
|
||||
42
stat/user_statistics/stat_management/signals.py
Normal file
42
stat/user_statistics/stat_management/signals.py
Normal file
@ -0,0 +1,42 @@
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from .models import GameHistory, Stats
|
||||
|
||||
@receiver(post_save, sender=GameHistory)
|
||||
def update_player_stats(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
# get players
|
||||
player_1_stats, _ = Stats.objects.get_or_create(player_id=instance.player_1_id)
|
||||
player_2_stats, _ = Stats.objects.get_or_create(player_id=instance.player_2_id)
|
||||
|
||||
# update wins and losses
|
||||
if instance.winner_id == instance.player_1_id:
|
||||
player_1_stats.wins += 1
|
||||
player_2_stats.losses += 1
|
||||
else:
|
||||
player_1_stats.losses += 1
|
||||
player_2_stats.wins += 1
|
||||
|
||||
# update games played
|
||||
player_1_stats.total_games_played += 1
|
||||
player_2_stats.total_games_played += 1
|
||||
|
||||
# update win rate
|
||||
player_1_stats.win_rate = player_1_stats.wins / player_1_stats.total_games_played * 100
|
||||
player_2_stats.win_rate = player_2_stats.wins / player_2_stats.total_games_played * 100
|
||||
|
||||
# update hours played
|
||||
player_1_stats.total_hours_played += instance.duration / 3600
|
||||
player_2_stats.total_hours_played += instance.duration / 3600
|
||||
|
||||
# update goal scored
|
||||
player_1_stats.goal_scored += instance.player_1_score
|
||||
player_2_stats.goal_scored += instance.player_2_score
|
||||
|
||||
# update goal conceded
|
||||
player_1_stats.goal_conceded += instance.player_2_score
|
||||
player_2_stats.goal_conceded += instance.player_1_score
|
||||
|
||||
# save stats
|
||||
player_1_stats.save()
|
||||
player_2_stats.save()
|
||||
75
stat/user_statistics/stat_management/tests.py
Normal file
75
stat/user_statistics/stat_management/tests.py
Normal file
@ -0,0 +1,75 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.urls import reverse
|
||||
from .models import GameHistory
|
||||
from .serializers import GameHistorySerializer
|
||||
from rest_framework.test import APITestCase
|
||||
from rest_framework import status
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
# Create your tests here.
|
||||
class GameHistoryModelTest(APITestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.user_1 = User.objects.create_user(username='user1', password='password')
|
||||
self.user_2 = User.objects.create_user(username='user2', password='password')
|
||||
self.user_1.save()
|
||||
|
||||
def test_game_history_model(self):
|
||||
|
||||
# loging user1
|
||||
self.client.login(username='user1', password='password')
|
||||
|
||||
# create a game history
|
||||
gameHistory = {
|
||||
'player_1_id': self.user_1.id,
|
||||
'player_2_id': self.user_2.id,
|
||||
'player_1_score': 5,
|
||||
'player_2_score': 3,
|
||||
'winner_id': self.user_1.id,
|
||||
'duration': '60'
|
||||
}
|
||||
|
||||
url = reverse('game_history')
|
||||
|
||||
print("data send to : ", url)
|
||||
print("data send : ", gameHistory)
|
||||
# send a GameHistory
|
||||
response = self.client.post(url, gameHistory, format='json')
|
||||
print(response.data)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
# get stats
|
||||
url = reverse('stats')
|
||||
print("data send to : ", url)
|
||||
response = self.client.get(url)
|
||||
print(response.data)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# create a game history
|
||||
gameHistory = {
|
||||
'player_1_id': self.user_1.id,
|
||||
'player_2_id': self.user_2.id,
|
||||
'player_1_score': 4,
|
||||
'player_2_score': 13,
|
||||
'winner_id': self.user_2.id,
|
||||
'duration': '10806'
|
||||
}
|
||||
|
||||
url = reverse('game_history')
|
||||
|
||||
print("data send to : ", url)
|
||||
print("data send : ", gameHistory)
|
||||
# send a GameHistory
|
||||
response = self.client.post(url, gameHistory, format='json')
|
||||
print(response.data)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
# get stats
|
||||
url = reverse('stats')
|
||||
print("data send to : ", url)
|
||||
response = self.client.get(url)
|
||||
print(response.data)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
8
stat/user_statistics/stat_management/urls.py
Normal file
8
stat/user_statistics/stat_management/urls.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
from .views import GameHistoryView, AddGameHistoryView, StatsView
|
||||
|
||||
urlpatterns = [
|
||||
path('game-history/<str:username>/', GameHistoryView.as_view(), name='game_history'),
|
||||
path('game-history/', AddGameHistoryView.as_view(), name='add_game_history'),
|
||||
path('stats/<str:username>/', StatsView.as_view(), name='stats'),
|
||||
]
|
||||
52
stat/user_statistics/stat_management/views.py
Normal file
52
stat/user_statistics/stat_management/views.py
Normal file
@ -0,0 +1,52 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from .models import GameHistory, Stats
|
||||
from .serializers import GameHistorySerializer, StatsSerializer
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
class AddGameHistoryView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request):
|
||||
serializer = GameHistorySerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
print("serilizer post: ",serializer.data)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
class GameHistoryView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, username):
|
||||
try:
|
||||
user = username
|
||||
games = GameHistory.objects.filter(Q(player_1_id=user) | Q(player_2_id=user)).order_by('-date_played')[:10]
|
||||
serializer = GameHistorySerializer(games, many=True)
|
||||
print("serilizer get: ",serializer.data)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
except Exception as e:
|
||||
return Response(
|
||||
{'message': f"{type(e).__name__}: {str(e)}"},
|
||||
status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
|
||||
class StatsView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, username):
|
||||
try:
|
||||
user = username
|
||||
stats = Stats.objects.filter(player_id=user).first()
|
||||
if stats is None:
|
||||
return Response([], status=status.HTTP_200_OK)
|
||||
serializer = StatsSerializer(stats)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
except Exception as e:
|
||||
return Response(
|
||||
{'message': f"{type(e).__name__}: {str(e)}"},
|
||||
status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
0
stat/user_statistics/user_statistics/__init__.py
Normal file
0
stat/user_statistics/user_statistics/__init__.py
Normal file
16
stat/user_statistics/user_statistics/asgi.py
Normal file
16
stat/user_statistics/user_statistics/asgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for user_statistics 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', 'user_statistics.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
175
stat/user_statistics/user_statistics/settings.py
Normal file
175
stat/user_statistics/user_statistics/settings.py
Normal file
@ -0,0 +1,175 @@
|
||||
"""
|
||||
Django settings for user_statistics project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.2.11.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import environ
|
||||
|
||||
sys.path.append('/home/archive/user_auth_system')
|
||||
|
||||
# Read environment variables from .env file
|
||||
# And define CONSTANTS
|
||||
env = environ.Env()
|
||||
environ.Env.read_env(env_file='.env.django')
|
||||
|
||||
USER_SERVICE_NAME = env('USER_SERVICE_NAME')
|
||||
STAT_SERVICE_NAME = env('STAT_SERVICE_NAME')
|
||||
AUTH_APP_NAME = env('USER_APP_NAME')
|
||||
STAT_APP_NAME = env('STAT_APP_NAME')
|
||||
DB_NAME = env('DB_ARCHIVE_NAME')
|
||||
DB_USER = env('DB_ARCHIVE_USER')
|
||||
DB_PASSWORD = env('DB_ARCHIVE_PASSWORD')
|
||||
DB_HOST = env('DB_ARCHIVE_HOST')
|
||||
DB_PORT = env('DB_ARCHIVE_PORT')
|
||||
IP_ADDRESS= env('IP_ADDRESS')
|
||||
SECRET_KEY_ENV = env('SECRET_KEY_USER')
|
||||
|
||||
|
||||
# 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/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = SECRET_KEY_ENV
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = False
|
||||
|
||||
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',
|
||||
'corsheaders',
|
||||
f'{AUTH_APP_NAME}',
|
||||
f'{STAT_APP_NAME}',
|
||||
]
|
||||
|
||||
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',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = f'{STAT_SERVICE_NAME}.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 = f'{STAT_SERVICE_NAME}.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': DB_NAME,
|
||||
'USER': DB_USER,
|
||||
'PASSWORD': DB_PASSWORD,
|
||||
'HOST': DB_HOST,
|
||||
'PORT': DB_PORT,
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
# Definition of default user
|
||||
|
||||
AUTH_USER_MODEL = f'{AUTH_APP_NAME}.CustomUser'
|
||||
|
||||
# CORS settings
|
||||
|
||||
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
|
||||
SESSION_COOKIE_NAME = 'sessionid'
|
||||
SESSION_COOKIE_HTTPONLY = True
|
||||
SESSION_COOKIE_SAMESITE = 'Lax'
|
||||
SESSION_COOKIE_SECURE = True
|
||||
|
||||
CSRF_COOKIE_NAME = 'csrftoken'
|
||||
CSRF_COOKIE_HTTPONLY = True
|
||||
CSRF_COOKIE_SAMESITE = 'Lax'
|
||||
CSRF_COOKIE_SECURE = True
|
||||
|
||||
CORS_ALLOW_CREDENTIALS = True
|
||||
CORS_ALLOW_ALL_ORIGINS = True
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = ['https://localhost', 'https://' + IP_ADDRESS]
|
||||
24
stat/user_statistics/user_statistics/urls.py
Normal file
24
stat/user_statistics/user_statistics/urls.py
Normal file
@ -0,0 +1,24 @@
|
||||
"""
|
||||
URL configuration for user_statistics project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.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
|
||||
from user_statistics.settings import STAT_APP_NAME
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('stat/', include(f'{STAT_APP_NAME}.urls'))
|
||||
]
|
||||
16
stat/user_statistics/user_statistics/wsgi.py
Normal file
16
stat/user_statistics/user_statistics/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for user_statistics 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', 'user_statistics.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user