From e422f655fdf6c354d9988f25d97ff73cd0d1ff3e Mon Sep 17 00:00:00 2001 From: MaziniiX Date: Fri, 21 Jun 2024 14:17:27 +0200 Subject: [PATCH] update --- Django_Frontend/empty_db.sql | 10 +++++++++ Django_Frontend/monprojet/monapp/views.py | 5 +++-- .../monprojet/monprojet/settings.py | 4 +++- Django_api/airline/airline/settings.py | 4 +++- Django_api/airline/api_common/models.py | 21 +++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 Django_Frontend/empty_db.sql diff --git a/Django_Frontend/empty_db.sql b/Django_Frontend/empty_db.sql new file mode 100644 index 0000000..428b866 --- /dev/null +++ b/Django_Frontend/empty_db.sql @@ -0,0 +1,10 @@ +DO $$ DECLARE + r RECORD; +BEGIN + -- if the schema you operate on is not "current", you will want to + -- replace current_schema() in query with 'schematodeletetablesfrom' + -- *and* update the generate 'DROP...' accordingly. + FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP + EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE'; + END LOOP; +END $$; \ No newline at end of file diff --git a/Django_Frontend/monprojet/monapp/views.py b/Django_Frontend/monprojet/monapp/views.py index acd6aee..2892ab8 100644 --- a/Django_Frontend/monprojet/monapp/views.py +++ b/Django_Frontend/monprojet/monapp/views.py @@ -1,6 +1,6 @@ -from django.http import HttpRequest import requests from django.shortcuts import render, redirect +from django.views.decorators.csrf import csrf_exempt from django.contrib import messages from django.contrib.auth.models import User from .forms import ClientForm, StaffForm, StaffTypeForm, RegistrationForm @@ -12,7 +12,7 @@ def get_api_url(request: HttpRequest) -> str: host = request.get_host() protocol = 'https://' if request.is_secure() else 'http://' - api_url = f'{protocol}api.{host}/' + api_url = f'{protocol}{host}/' return api_url def client_create_view(request): @@ -64,6 +64,7 @@ def register(request): form = RegistrationForm() return render(request, 'monapp/register.html', {'form': form}) +@csrf_exempt def login(request): api_url = get_api_url(request) if request.method == 'POST': diff --git a/Django_Frontend/monprojet/monprojet/settings.py b/Django_Frontend/monprojet/monprojet/settings.py index d4a014c..1461a8b 100644 --- a/Django_Frontend/monprojet/monprojet/settings.py +++ b/Django_Frontend/monprojet/monprojet/settings.py @@ -72,7 +72,9 @@ ] if ENVIRONMENT != 'development': - CSRF_TRUSTED_ORIGINS = ["https://" + os.getenv('DOMAIN')] + CSRF_TRUSTED_ORIGINS = ["https://" + os.getenv('DOMAIN'), "https://api." + os.getenv('DOMAIN')] +else: + CSRF_TRUSTED_ORIGINS = ['*'] ROOT_URLCONF = 'monprojet.urls' diff --git a/Django_api/airline/airline/settings.py b/Django_api/airline/airline/settings.py index 58d5b92..92aab91 100644 --- a/Django_api/airline/airline/settings.py +++ b/Django_api/airline/airline/settings.py @@ -69,7 +69,9 @@ ] if ENVIRONMENT != 'development': - CSRF_TRUSTED_ORIGINS = ["https://api." + os.getenv('DOMAIN')] + CSRF_TRUSTED_ORIGINS = ["https://" + os.getenv('DOMAIN'), "https://api." + os.getenv('DOMAIN')] +else: + CSRF_TRUSTED_ORIGINS = ['*'] ROOT_URLCONF = 'airline.urls' diff --git a/Django_api/airline/api_common/models.py b/Django_api/airline/api_common/models.py index 1a457fe..d76bd0e 100644 --- a/Django_api/airline/api_common/models.py +++ b/Django_api/airline/api_common/models.py @@ -2,6 +2,27 @@ from django.db import models from django.contrib.auth.models import User + +############# DO NOT TOUCH THE CODE BELOW THIS LINE ############# +class Client(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) + is_staff = models.BooleanField(default=False) + is_superuser = models.BooleanField(default=False) + + class Meta: + db_table = 'client' + +class Staff(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) + is_staff = models.BooleanField(default=False) + is_superuser = models.BooleanField(default=False) + staff_type = models.ForeignKey('StaffType', on_delete=models.CASCADE) + + class Meta: + db_table = 'staff' +############# DO NOT TOUCH THE CODE ABOVE THIS LINE ############# + + class StaffType(models.Model): type = models.CharField(max_length=100)