diff --git a/Procfile b/Procfile index bf8021527b..f77ba1da23 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ release: python manage.py migrate -web: gunicorn Ultron.wsgi +web: gunicorn config.wsgi diff --git a/Ultron/__init__.py b/Ultron/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/Ultron/asgi.py b/Ultron/asgi.py deleted file mode 100644 index e0e9b36516..0000000000 --- a/Ultron/asgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -ASGI config for Ultron 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', 'Ultron.settings') - -application = get_asgi_application() diff --git a/Ultron/settings.py b/Ultron/settings.py deleted file mode 100644 index 2315c3c9ec..0000000000 --- a/Ultron/settings.py +++ /dev/null @@ -1,147 +0,0 @@ -""" -Django settings for Ultron project. - -Generated by 'django-admin startproject' using Django 3.2.8. - -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 os -from pathlib import Path -import environ - -# Initialise environment variables -env = environ.Env() -environ.Env.read_env() - -# 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 = env('SECRET_KEY') - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = env('ALLOWED_HOSTS').split() - - -# Application definition -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django_extensions', - 'location', - 'people', - 'followup', - 'tools', - 'profiles', - 'planning', - 'objective', -] - -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', - 'whitenoise.middleware.WhiteNoiseMiddleware', -] - -ROOT_URLCONF = 'Ultron.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, "templates"),], - '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 = 'Ultron.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/3.2/ref/settings/#databases -DATABASES = { - 'default': env.db() -} - - -# 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 - -LOGIN_URL = "/login/" - -LOGOUT_URL = "/logout/" - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.2/howto/static-files/ - -STATIC_URL = "/static/" -STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),) -STATIC_ROOT = BASE_DIR / 'staticfiles' - -# Default primary key field type -# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' - - -# Simplified static file serving. -# https://warehouse.python.org/project/whitenoise/ - -STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' diff --git a/Ultron/urls.py b/Ultron/urls.py deleted file mode 100644 index 7d281cd61b..0000000000 --- a/Ultron/urls.py +++ /dev/null @@ -1,63 +0,0 @@ -"""Ultron 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 include, path - -import followup.urls -import location.urls -import people.urls -import Ultron.views -import profiles.urls -import planning.urls -import objective.urls - -urlpatterns = [ - # Global search - path(r"search/", Ultron.views.search, name="global_search"), - - # Profile list - path(r"profile/", include(profiles.urls.profile_urlpatterns)), - - # Gymnast management - path(r"gymnast/", include(people.urls.gymnast_urlpatterns)), - - # Location management - path(r"place/", include(location.urls.place_urlpatterns)), - path(r"country/", include(location.urls.country_urlpatterns)), - path(r"club/", include(location.urls.club_urlpatterns)), - - # Follow-up management - path(r"chrono/", include(followup.urls.chrono_urlpatterns)), - path(r"learnedskill/", include(followup.urls.learnedskill_urlpatterns)), - path(r"score/", include(followup.urls.score_urlpatterns)), - path(r"accident/", include(followup.urls.accident_urlpatterns)), - path(r"mindstate/", include(followup.urls.mindstate_urlpatterns)), - - # Objective management - path(r"skill/", include(objective.urls.skill_urlpatterns)), - path(r"routine/", include(objective.urls.routine_urlpatterns)), - - # Planning management - path(r"event/", include(planning.urls.event_urlpatterns)), - - # Login & logout - path(r"login/", Ultron.views.login, name="login"), - path(r"logout/", Ultron.views.logout, name="logout"), - path(r"", Ultron.views.home, name="home"), - - # Administration - path('admin/', admin.site.urls), -] diff --git a/Ultron/views.py b/Ultron/views.py deleted file mode 100644 index 96a871292f..0000000000 --- a/Ultron/views.py +++ /dev/null @@ -1,154 +0,0 @@ - -from datetime import datetime, timedelta, date -from functools import reduce -import operator - -from django.db.models import Q -from django.shortcuts import render -from django.template import RequestContext -from django.utils import timezone -from django.utils.html import format_html -from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout -from django.http import HttpResponseRedirect -from django.contrib.auth.decorators import login_required -from django.views.decorators.http import require_http_methods -from objective.models import Routine - -from profiles.models import Profile -from followup.models import Accident, Skill, MindState, Point -from location.models import Place, Club -from people.models import Gymnast -from planning.models import Event -from tools.models import get_number_of_weeks_between - - -def login(request): - """ - Formulaire d'authentifictation. - """ - - if request.method == "POST": - username = request.POST["login"] - password = request.POST["password"] - - user = authenticate(username=username, password=password) - - if user is not None: # Pq pas "if user:" ?? - if user.is_active: - auth_login(request, user) - try: - profile = Profile.objects.get(user=user) - request.session["profileid"] = profile.id - request.session["template"] = profile.template_color - request.session["sidebar"] = profile.sidebar_color - request.session["is_sidebar_minified"] = profile.is_sidebar_minified - except Exception: - pass - request.session["clubid"] = request.POST.get("clubid", None) - return HttpResponseRedirect("/") - else: - context = {"message": "Account disabled."} - else: - context = {"message": "Wrong login/password."} - else: - context = {} - - return render(request, "ultron/login.html", context) - - -@login_required -@require_http_methods(["GET"]) -def logout(request): - """ - Fonction de déconnexion - """ - auth_logout(request) - return HttpResponseRedirect("/login/") - - -def next_birthdays(request, number_of_birthday): - """ - Renvoie la liste des `number_of_birthday` prochains anniversaires. - """ - birthday_list = sorted( - Gymnast.objects.all(), key=lambda t: t.next_birthday_in_days - )[:number_of_birthday] - return birthday_list - - -@login_required -@require_http_methods(["GET"]) -def home(request): - """ - Génère la page d'accueil du site basée sur la saison (si celle-ci est connue) - """ - event_list = Event.objects.filter(datebegin__gte=timezone.now()).order_by('datebegin')[:5] - - last_updated_gymnast = Gymnast.objects.filter( - Q(mindstate__created_at__gt=request.user.last_login) | - Q(points__created_at__gt=request.user.last_login) | - Q(chronos__created_at__gt=request.user.last_login) | - Q(accident__created_at__gt=request.user.last_login) | - Q(known_skills__created_at__gt=request.user.last_login) - ).distinct() - - nb_gymnast = Gymnast.objects.filter(is_active=True).count() - nb_event = Event.objects.all().count() - nb_skill = Skill.objects.all().count() - nb_routine = Routine.objects.all().count() - nb_score = Point.objects.all().count() - percentage_week = int((get_number_of_weeks_between(datetime(2021, 9, 1), datetime.now()) / 52) * 100) - - birthday_list = next_birthdays(request, 5) - - context = { - 'event_list': event_list, - 'last_updated_gymnast': last_updated_gymnast, - 'nb_gymnast': nb_gymnast, - 'nb_event': nb_event, - 'nb_skill': nb_skill, - 'nb_routine': nb_routine, - 'nb_score': nb_score, - 'percentage_week': percentage_week, - 'birthday_list': birthday_list - } - return render(request, "ultron/dashboard/dashboard.html", context) - - -@login_required -@require_http_methods(["GET"]) -def search(request): - """ - Recherche globale au travers de toutes les applications. - """ - pattern = request.GET.get("pattern", None) - - if pattern: - gymnast_list = Gymnast.objects.filter( - Q(last_name__icontains=pattern) | Q(first_name__icontains=pattern) - ) - skill_list = Skill.objects.filter( - Q(long_label__icontains=pattern) | Q(short_label__icontains=pattern) - ) - event_list = Event.objects.filter( - Q(name__icontains=pattern) | Q(place__name__icontains=pattern) - ) - place_list = Place.objects.filter( - Q(name__icontains=pattern) | Q(city__icontains=pattern) - ) - club_list = Club.objects.filter( - Q(name__icontains=pattern) | Q(place__name__icontains=pattern) | Q(place__city__icontains=pattern) - ) - - context = { - 'gymnast_list': gymnast_list, - 'skill_list': skill_list, - 'event_list': event_list, - 'place_list': place_list, - 'club_list': club_list, - 'pattern': pattern - } - else: - context = {} - - return render(request, "ultron/search/results.html", context) diff --git a/Ultron/wsgi.py b/Ultron/wsgi.py deleted file mode 100644 index 224815d21e..0000000000 --- a/Ultron/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for Ultron 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', 'Ultron.settings') - -application = get_wsgi_application() diff --git a/followup/admin.py b/followup/admin.py index d20ebd1f27..86a584650a 100644 --- a/followup/admin.py +++ b/followup/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from django.db.models import fields -from Ultron.views import search +from config.views import search from .models import Chrono, LearnedSkill, Point, Accident, MindState, GymnastHasRoutine from django_extensions.admin import ForeignKeyAutocompleteAdmin diff --git a/manage.py b/manage.py index 61f5e874b4..8e7ac79b95 100755 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ import sys def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Ultron.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: