From 691afa729841495ad9df52eb3c0dac714ee90a5e Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 2 Dec 2021 21:57:32 +0100 Subject: [PATCH] Apps split and base of error page --- .../models/__init__.py => README.md | 0 crew/__init__.py | 0 crew/admin.py | 3 +++ crew/apps.py | 6 +++++ crew/migrations/__init__.py | 0 crew/models.py | 10 +++++++++ crew/tests.py | 3 +++ crew/urls.py | 7 ++++++ crew/views.py | 6 +++++ error/__init__.py | 0 error/admin.py | 3 +++ error/apps.py | 6 +++++ error/migrations/__init__.py | 0 error/models.py | 5 +++++ error/tests.py | 3 +++ error/urls.py | 3 +++ error/views.py | 22 +++++++++++++++++++ nuitdelinfo_2021/models/Rescue.py | 6 ----- nuitdelinfo_2021/settings.py | 3 +++ nuitdelinfo_2021/urls.py | 8 ++++++- nuitdelinfo_2021/{views/index.py => views.py} | 0 nuitdelinfo_2021/views/__init__.py | 1 - people/__init__.py | 0 people/admin.py | 3 +++ people/apps.py | 6 +++++ people/migrations/__init__.py | 0 people/models.py | 20 +++++++++++++++++ people/tests.py | 3 +++ people/urls.py | 7 ++++++ people/views.py | 15 +++++++++++++ requirements.txt | 4 ++++ rescue/__init__.py | 0 rescue/admin.py | 3 +++ rescue/apps.py | 6 +++++ rescue/migrations/__init__.py | 0 rescue/models.py | 20 +++++++++++++++++ rescue/tests.py | 3 +++ rescue/urls.py | 7 ++++++ rescue/views.py | 7 ++++++ templates/article.html | 0 templates/crew.html | 0 templates/error.html | 6 +++++ templates/people.html | 0 43 files changed, 197 insertions(+), 8 deletions(-) rename nuitdelinfo_2021/models/__init__.py => README.md (100%) create mode 100644 crew/__init__.py create mode 100644 crew/admin.py create mode 100644 crew/apps.py create mode 100644 crew/migrations/__init__.py create mode 100644 crew/models.py create mode 100644 crew/tests.py create mode 100644 crew/urls.py create mode 100644 crew/views.py create mode 100644 error/__init__.py create mode 100644 error/admin.py create mode 100644 error/apps.py create mode 100644 error/migrations/__init__.py create mode 100644 error/models.py create mode 100644 error/tests.py create mode 100644 error/urls.py create mode 100644 error/views.py delete mode 100644 nuitdelinfo_2021/models/Rescue.py rename nuitdelinfo_2021/{views/index.py => views.py} (100%) delete mode 100644 nuitdelinfo_2021/views/__init__.py create mode 100644 people/__init__.py create mode 100644 people/admin.py create mode 100644 people/apps.py create mode 100644 people/migrations/__init__.py create mode 100644 people/models.py create mode 100644 people/tests.py create mode 100644 people/urls.py create mode 100644 people/views.py create mode 100644 requirements.txt create mode 100644 rescue/__init__.py create mode 100644 rescue/admin.py create mode 100644 rescue/apps.py create mode 100644 rescue/migrations/__init__.py create mode 100644 rescue/models.py create mode 100644 rescue/tests.py create mode 100644 rescue/urls.py create mode 100644 rescue/views.py create mode 100644 templates/article.html create mode 100644 templates/crew.html create mode 100644 templates/error.html create mode 100644 templates/people.html diff --git a/nuitdelinfo_2021/models/__init__.py b/README.md similarity index 100% rename from nuitdelinfo_2021/models/__init__.py rename to README.md diff --git a/crew/__init__.py b/crew/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/crew/admin.py b/crew/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/crew/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/crew/apps.py b/crew/apps.py new file mode 100644 index 0000000..5940414 --- /dev/null +++ b/crew/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CrewConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'crew' diff --git a/crew/migrations/__init__.py b/crew/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/crew/models.py b/crew/models.py new file mode 100644 index 0000000..c5f6578 --- /dev/null +++ b/crew/models.py @@ -0,0 +1,10 @@ +from django.db.models import Model, CharField, ManyToManyField, TextField + +from nuitdelinfo_2021.models import People + + +class Crew(Model): + name = CharField() + members = ManyToManyField(People) + + description = TextField() diff --git a/crew/tests.py b/crew/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/crew/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/crew/urls.py b/crew/urls.py new file mode 100644 index 0000000..c803ac5 --- /dev/null +++ b/crew/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] diff --git a/crew/views.py b/crew/views.py new file mode 100644 index 0000000..9d99631 --- /dev/null +++ b/crew/views.py @@ -0,0 +1,6 @@ +from django.shortcuts import render + + +def index(request, crew_id: int): + context = {} + return render(request, "crew.html", context) diff --git a/error/__init__.py b/error/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/error/admin.py b/error/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/error/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/error/apps.py b/error/apps.py new file mode 100644 index 0000000..aa7fbf5 --- /dev/null +++ b/error/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ErrorConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'error' diff --git a/error/migrations/__init__.py b/error/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/error/models.py b/error/models.py new file mode 100644 index 0000000..2d34d62 --- /dev/null +++ b/error/models.py @@ -0,0 +1,5 @@ +from django.db.models import Model, TextField + + +class ThomasPesquetQuotes(Model): + text = TextField() diff --git a/error/tests.py b/error/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/error/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/error/urls.py b/error/urls.py new file mode 100644 index 0000000..1322dd5 --- /dev/null +++ b/error/urls.py @@ -0,0 +1,3 @@ +from django.urls import path + +from . import views diff --git a/error/views.py b/error/views.py new file mode 100644 index 0000000..7172a8a --- /dev/null +++ b/error/views.py @@ -0,0 +1,22 @@ +from django.http import Http404 +from django.shortcuts import render + +from error.models import ThomasPesquetQuotes + + +def index(request, exception=None): + try: + quote = ThomasPesquetQuotes.objects.order_by("?")[0].text + except: + quote = None + + response = render(request, "error.html", { + "quote": quote + }) + + response.status_code = 500 + + if isinstance(exception, Http404): + response.status_code = 404 + + return response diff --git a/nuitdelinfo_2021/models/Rescue.py b/nuitdelinfo_2021/models/Rescue.py deleted file mode 100644 index 0200447..0000000 --- a/nuitdelinfo_2021/models/Rescue.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.db.models import Model, CharField, TextField - - -class Rescue(Model): - name = CharField(max_length="256") - text = TextField() diff --git a/nuitdelinfo_2021/settings.py b/nuitdelinfo_2021/settings.py index 99314c7..9a45ba3 100644 --- a/nuitdelinfo_2021/settings.py +++ b/nuitdelinfo_2021/settings.py @@ -31,6 +31,9 @@ ALLOWED_HOSTS = ["3cab-134-214-214-199.ngrok.io", "localhost"] # Application definition INSTALLED_APPS = [ + "rescue.apps.RescueConfig", + "people.apps.PeopleConfig", + "error.apps.ErrorConfig", 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/nuitdelinfo_2021/urls.py b/nuitdelinfo_2021/urls.py index eec4ad8..72a97e6 100644 --- a/nuitdelinfo_2021/urls.py +++ b/nuitdelinfo_2021/urls.py @@ -14,11 +14,17 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include from nuitdelinfo_2021 import views urlpatterns = [ path('', views.index, name="index"), + path("a/", include("rescue.urls")), + path("p/", include("people.urls")), path('admin/', admin.site.urls), ] + +handler400 = "error.views.index" +handler404 = "error.views.index" +handler500 = "error.views.index" diff --git a/nuitdelinfo_2021/views/index.py b/nuitdelinfo_2021/views.py similarity index 100% rename from nuitdelinfo_2021/views/index.py rename to nuitdelinfo_2021/views.py diff --git a/nuitdelinfo_2021/views/__init__.py b/nuitdelinfo_2021/views/__init__.py deleted file mode 100644 index 2079d08..0000000 --- a/nuitdelinfo_2021/views/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .index import index diff --git a/people/__init__.py b/people/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/people/admin.py b/people/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/people/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/people/apps.py b/people/apps.py new file mode 100644 index 0000000..c2ddd3b --- /dev/null +++ b/people/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PeopleConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'people' diff --git a/people/migrations/__init__.py b/people/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/people/models.py b/people/models.py new file mode 100644 index 0000000..be8906a --- /dev/null +++ b/people/models.py @@ -0,0 +1,20 @@ +from django.db.models import Model, CharField, DateField, TextField + + +class People(Model): + first_name = CharField(max_length=40, null=False) + last_name = CharField(max_length=60, null=False) + + title = CharField(max_length=70) + description = TextField(null=False) + + birth = DateField(null=False) + death = DateField() + + history = TextField() + genealogy = TextField() + awards = TextField() + pro_life = TextField() + + testimonials = TextField() + sources = TextField(null=False) diff --git a/people/tests.py b/people/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/people/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/people/urls.py b/people/urls.py new file mode 100644 index 0000000..96de495 --- /dev/null +++ b/people/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('/', views.index, name='index'), +] diff --git a/people/views.py b/people/views.py new file mode 100644 index 0000000..53dc36f --- /dev/null +++ b/people/views.py @@ -0,0 +1,15 @@ +from django.http import Http404 +from django.shortcuts import render + +from people.models import People + + +def index(request, people_id: int): + try: + people = People.objects.get(pk=people_id) + except People.DoesNotExist: + raise Http404("People does not exist") + + return render(request, "people.html", { + "people": people + }) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c496a00 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +asgiref==3.4.1 +Django==3.2.9 +pytz==2021.3 +sqlparse==0.4.2 diff --git a/rescue/__init__.py b/rescue/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rescue/admin.py b/rescue/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/rescue/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/rescue/apps.py b/rescue/apps.py new file mode 100644 index 0000000..9643ec7 --- /dev/null +++ b/rescue/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class RescueConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'rescue' diff --git a/rescue/migrations/__init__.py b/rescue/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rescue/models.py b/rescue/models.py new file mode 100644 index 0000000..184f618 --- /dev/null +++ b/rescue/models.py @@ -0,0 +1,20 @@ +from django.db.models import Model, CharField, TextField, DateField, ManyToManyField, DecimalField + +from people.models import People + + +class Rescue(Model): + name = CharField(max_length=70, null=False) + date = DateField(null=False) + + location_long = DecimalField(max_digits=9, decimal_places=6) + location_lat = DecimalField(max_digits=9, decimal_places=6) + + resume = CharField(max_length=125, null=False) + + saved = ManyToManyField(People, related_name="saved") + rescuers = ManyToManyField(People, related_name="rescued") + + description = TextField() + + sources = TextField(null=False) diff --git a/rescue/tests.py b/rescue/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/rescue/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/rescue/urls.py b/rescue/urls.py new file mode 100644 index 0000000..3b56c66 --- /dev/null +++ b/rescue/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] diff --git a/rescue/views.py b/rescue/views.py new file mode 100644 index 0000000..39cdda2 --- /dev/null +++ b/rescue/views.py @@ -0,0 +1,7 @@ +from django.shortcuts import render + + +def index(request, article_id: int): + context = {} + return render(request, "article.html", context) + diff --git a/templates/article.html b/templates/article.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/crew.html b/templates/crew.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..8ed7b0e --- /dev/null +++ b/templates/error.html @@ -0,0 +1,6 @@ +

Oups, une erreur est survenue :/

+ +{% if quote %} +

Pour nous faire pardonner voici une citation de Thomas Pesquet:

+

{{ quote }}

+{% endif %} diff --git a/templates/people.html b/templates/people.html new file mode 100644 index 0000000..e69de29