From 691afa729841495ad9df52eb3c0dac714ee90a5e Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 2 Dec 2021 21:57:32 +0100 Subject: [PATCH 1/7] 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 From d6948e455ac93238fe3326d4420c3ad4a0aad456 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 2 Dec 2021 23:46:42 +0100 Subject: [PATCH 2/7] Setup people submission and edit --- nuitdelinfo_2021/settings.py | 1 + people/forms.py | 18 ++++++++++++++ people/models.py | 30 +++++++++++++---------- people/urls.py | 4 +++- people/views.py | 46 ++++++++++++++++++++++++++++++++---- requirements.txt | 1 + templates/people.html | 0 templates/people/edit.html | 10 ++++++++ templates/people/people.html | 23 ++++++++++++++++++ templates/people/submit.html | 10 ++++++++ 10 files changed, 124 insertions(+), 19 deletions(-) create mode 100644 people/forms.py delete mode 100644 templates/people.html create mode 100644 templates/people/edit.html create mode 100644 templates/people/people.html create mode 100644 templates/people/submit.html diff --git a/nuitdelinfo_2021/settings.py b/nuitdelinfo_2021/settings.py index 9a45ba3..4995664 100644 --- a/nuitdelinfo_2021/settings.py +++ b/nuitdelinfo_2021/settings.py @@ -40,6 +40,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + "django_quill" ] MIDDLEWARE = [ diff --git a/people/forms.py b/people/forms.py new file mode 100644 index 0000000..257c336 --- /dev/null +++ b/people/forms.py @@ -0,0 +1,18 @@ +from django.forms import ModelForm, DateInput + +from people.models import People + + +class DateInput(DateInput): + input_type = "date" + + +class SubmitPeople(ModelForm): + class Meta: + model = People + fields = ["first_name", "last_name", "title", "description", "birth", "death", "history", "genealogy", "awards", + "pro_life", "testimonials", "sources"] + widgets = { + "birth": DateInput(), + "death": DateInput() + } diff --git a/people/models.py b/people/models.py index be8906a..59c349b 100644 --- a/people/models.py +++ b/people/models.py @@ -1,20 +1,24 @@ -from django.db.models import Model, CharField, DateField, TextField +from django.db.models import Model, CharField, DateField, BooleanField, ForeignKey, CASCADE +from django_quill.fields import QuillField class People(Model): - first_name = CharField(max_length=40, null=False) - last_name = CharField(max_length=60, null=False) + first_name = CharField(max_length=40) + last_name = CharField(max_length=60) - title = CharField(max_length=70) - description = TextField(null=False) + title = CharField(max_length=70, null=True, blank=True) + description = QuillField() - birth = DateField(null=False) - death = DateField() + birth = DateField() + death = DateField(null=True, blank=True) - history = TextField() - genealogy = TextField() - awards = TextField() - pro_life = TextField() + history = QuillField(null=True, blank=True) + genealogy = QuillField(null=True, blank=True) + awards = QuillField(null=True, blank=True) + pro_life = QuillField(null=True, blank=True) - testimonials = TextField() - sources = TextField(null=False) + testimonials = QuillField(null=True, blank=True) + sources = QuillField() + + validated = BooleanField(default=False) + pending_edit_of = ForeignKey("self", on_delete=CASCADE, null=True, blank=True) diff --git a/people/urls.py b/people/urls.py index 96de495..ae7518b 100644 --- a/people/urls.py +++ b/people/urls.py @@ -3,5 +3,7 @@ from django.urls import path from . import views urlpatterns = [ - path('/', views.index, name='index'), + path("/", views.index, name='index'), + path("submit/", views.submit, name="submit"), + path("edit//", views.edit, name="edit") ] diff --git a/people/views.py b/people/views.py index 53dc36f..b29af5f 100644 --- a/people/views.py +++ b/people/views.py @@ -1,15 +1,51 @@ -from django.http import Http404 +from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest from django.shortcuts import render +from django.urls import reverse +from people.forms import SubmitPeople from people.models import People -def index(request, people_id: int): +def get_people(people_id: int) -> People: try: - people = People.objects.get(pk=people_id) + return People.objects.get(pk=people_id) except People.DoesNotExist: raise Http404("People does not exist") - return render(request, "people.html", { - "people": people + +def index(request, people_id: int): + return render(request, "people/people.html", { + "people": get_people(people_id) }) + + +def submit(request): + if request.method == "POST": + form = SubmitPeople(request.POST) + if form.is_valid(): + people = form.save() + return HttpResponseRedirect(reverse(index, args=[people.pk])) + else: + form = SubmitPeople() + + return render(request, "people/submit.html", {"form": form}) + + +def edit(request, people_id: int): + edited_people = get_people(people_id) + if not edited_people.validated: + return HttpResponseBadRequest("This entry is not validated, you can't edit it") + + if request.method == "POST": + form = SubmitPeople(request.POST) + if form.is_valid(): + people = form.save() + people.pending_edit_of = edited_people + people.save() + + return HttpResponseRedirect(reverse(index, args=[people.pk])) + else: + edited_people.pk = None + form = SubmitPeople(instance=edited_people) + + return render(request, "people/edit.html", {"form": form, "edit_id": people_id}) diff --git a/requirements.txt b/requirements.txt index c496a00..32348c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ asgiref==3.4.1 Django==3.2.9 +django-quill-editor==0.1.22 pytz==2021.3 sqlparse==0.4.2 diff --git a/templates/people.html b/templates/people.html deleted file mode 100644 index e69de29..0000000 diff --git a/templates/people/edit.html b/templates/people/edit.html new file mode 100644 index 0000000..4e90bc0 --- /dev/null +++ b/templates/people/edit.html @@ -0,0 +1,10 @@ + + {{ form.media }} + + +
+ {% csrf_token %} + {{ form }} + +
+ diff --git a/templates/people/people.html b/templates/people/people.html new file mode 100644 index 0000000..96de6fe --- /dev/null +++ b/templates/people/people.html @@ -0,0 +1,23 @@ +{% if not people.validated %} + {% if people.pending_edit_of %} +

This edit is not validated !

+ {% else %} +

This new entry is not validated !

+ {% endif %} +{% endif %} + +{{ people.first_name }} {{ people.last_name }}
+{{ people.title }}
+
+{{ people.description.html | safe }}
+
+{{ people.birth }}
+{{ people.death }}
+
+{{ people.history.html | safe }}
+{{ people.genealogy.html | safe }}
+{{ people.awards.html | safe }}
+{{ people.pro_life.html | safe }}
+
+{{ people.testimonials.html | safe }}
+{{ people.sources.html | safe }} diff --git a/templates/people/submit.html b/templates/people/submit.html new file mode 100644 index 0000000..f0036e2 --- /dev/null +++ b/templates/people/submit.html @@ -0,0 +1,10 @@ + + {{ form.media }} + + +
+ {% csrf_token %} + {{ form }} + +
+ From 3220219b165b80ac21115074fa8dfc5423d20379 Mon Sep 17 00:00:00 2001 From: flifloo Date: Fri, 3 Dec 2021 00:23:06 +0100 Subject: [PATCH 3/7] Setup rescue submission and edit --- nuitdelinfo_2021/settings.py | 9 ++++--- people/models.py | 3 +++ rescue/forms.py | 17 ++++++++++++ rescue/models.py | 13 ++++----- rescue/urls.py | 4 ++- rescue/views.py | 48 +++++++++++++++++++++++++++++++--- templates/article.html | 0 templates/article/article.html | 28 ++++++++++++++++++++ templates/article/edit.html | 10 +++++++ templates/article/submit.html | 10 +++++++ templates/people/edit.html | 10 +++---- 11 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 rescue/forms.py delete mode 100644 templates/article.html create mode 100644 templates/article/article.html create mode 100644 templates/article/edit.html create mode 100644 templates/article/submit.html diff --git a/nuitdelinfo_2021/settings.py b/nuitdelinfo_2021/settings.py index 4995664..2f0b5f7 100644 --- a/nuitdelinfo_2021/settings.py +++ b/nuitdelinfo_2021/settings.py @@ -80,9 +80,12 @@ WSGI_APPLICATION = 'nuitdelinfo_2021.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } + 'ENGINE': 'django.db.backends.postgresql', + 'HOST': 'localhost', + 'USER': 'nuitdelinfo_2021', + 'NAME': 'nuitdelinfo_2021', + 'PASSWORD': 'nuitdelinfo_2021' + }, } diff --git a/people/models.py b/people/models.py index 59c349b..4a3d94a 100644 --- a/people/models.py +++ b/people/models.py @@ -22,3 +22,6 @@ class People(Model): validated = BooleanField(default=False) pending_edit_of = ForeignKey("self", on_delete=CASCADE, null=True, blank=True) + + def __str__(self): + return f"{self.first_name} {self.last_name}" diff --git a/rescue/forms.py b/rescue/forms.py new file mode 100644 index 0000000..3646b6a --- /dev/null +++ b/rescue/forms.py @@ -0,0 +1,17 @@ +from django.forms import ModelForm, DateInput + +from rescue.models import Rescue + + +class DateInput(DateInput): + input_type = "date" + + +class SubmitRescue(ModelForm): + class Meta: + model = Rescue + fields = ["name", "date", "location_long", "location_lat", "resume", "saved", "rescuers", "description", + "sources"] + widgets = { + "date": DateInput() + } diff --git a/rescue/models.py b/rescue/models.py index 184f618..5089e3b 100644 --- a/rescue/models.py +++ b/rescue/models.py @@ -1,20 +1,21 @@ -from django.db.models import Model, CharField, TextField, DateField, ManyToManyField, DecimalField +from django.db.models import Model, CharField, DateField, ManyToManyField, DecimalField +from django_quill.fields import QuillField from people.models import People class Rescue(Model): - name = CharField(max_length=70, null=False) - date = DateField(null=False) + name = CharField(max_length=70) + date = DateField() 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) + resume = CharField(max_length=125) saved = ManyToManyField(People, related_name="saved") rescuers = ManyToManyField(People, related_name="rescued") - description = TextField() + description = QuillField() - sources = TextField(null=False) + sources = QuillField() diff --git a/rescue/urls.py b/rescue/urls.py index 3b56c66..491a8a0 100644 --- a/rescue/urls.py +++ b/rescue/urls.py @@ -3,5 +3,7 @@ from django.urls import path from . import views urlpatterns = [ - path('', views.index, name='index'), + path('', views.index, name='index'), + path("submit/", views.submit, name="submit"), + path("edit//", views.edit, name="edit") ] diff --git a/rescue/views.py b/rescue/views.py index 39cdda2..da8792c 100644 --- a/rescue/views.py +++ b/rescue/views.py @@ -1,7 +1,49 @@ +from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest from django.shortcuts import render +from django.urls import reverse + +from rescue.forms import SubmitRescue +from rescue.models import Rescue -def index(request, article_id: int): - context = {} - return render(request, "article.html", context) +def get_rescue(rescue_id: int) -> Rescue: + try: + return Rescue.objects.get(pk=rescue_id) + except Rescue.DoesNotExist: + raise Http404("Rescue does not exist") + +def index(request, rescue_id: int): + return render(request, "article/article.html", {"rescue": get_rescue(rescue_id)}) + + +def submit(request): + if request.method == "POST": + form = SubmitRescue(request.POST) + if form.is_valid(): + rescue = form.save() + return HttpResponseRedirect(reverse(index, args=[rescue.pk])) + else: + form = SubmitRescue() + + return render(request, "article/submit.html", {"form": form}) + + +def edit(request, rescue_id: int): + edited_rescue = get_rescue(rescue_id) + if not edited_rescue.validated: + return HttpResponseBadRequest("This entry is not validated, you can't edit it") + + if request.method == "POST": + form = SubmitRescue(request.POST) + if form.is_valid(): + rescue = form.save() + rescue.pending_edit_of = edited_rescue + rescue.save() + + return HttpResponseRedirect(reverse(index, args=[rescue.pk])) + else: + edited_rescue.pk = None + form = SubmitRescue(instance=edited_rescue) + + return render(request, "article/edit.html", {"form": form, "edit_id": edited_rescue}) diff --git a/templates/article.html b/templates/article.html deleted file mode 100644 index e69de29..0000000 diff --git a/templates/article/article.html b/templates/article/article.html new file mode 100644 index 0000000..f222c24 --- /dev/null +++ b/templates/article/article.html @@ -0,0 +1,28 @@ +{% if not rescue.validated %} + {% if rescue.pending_edit_of %} +

This edit is not validated !

+ {% else %} +

This new entry is not validated !

+ {% endif %} +{% endif %} + +{{ rescue.name }}
+{{ rescue.date }}
+
+{{ rescue.location_long }} {{ rescue.location_lat }}
+
+{{ rescue.resume.html | safe }}
+{{ rescue.description.html | safe }}
+
+{{ rescue.testimonials.html | safe }}
+{{ rescue.sources.html | safe }} + +

Saved

+{% for people in rescue.saved.all %} + {{ people }} +{% endfor %} + +

Rescuers

+{% for people in rescue.rescuers.all %} + {{ people }} +{% endfor %} diff --git a/templates/article/edit.html b/templates/article/edit.html new file mode 100644 index 0000000..3685882 --- /dev/null +++ b/templates/article/edit.html @@ -0,0 +1,10 @@ + + {{ form.media }} + + +
+ {% csrf_token %} + {{ form }} + +
+ diff --git a/templates/article/submit.html b/templates/article/submit.html new file mode 100644 index 0000000..8bf0360 --- /dev/null +++ b/templates/article/submit.html @@ -0,0 +1,10 @@ + + {{ form.media }} + + +
+ {% csrf_token %} + {{ form }} + +
+ diff --git a/templates/people/edit.html b/templates/people/edit.html index 4e90bc0..2d13a50 100644 --- a/templates/people/edit.html +++ b/templates/people/edit.html @@ -2,9 +2,9 @@ {{ form.media }} -
- {% csrf_token %} - {{ form }} - -
+
+ {% csrf_token %} + {{ form }} + +
From 3cd8535ab9ae48e98b052578fb1040c22e8a0c0d Mon Sep 17 00:00:00 2001 From: flifloo Date: Fri, 3 Dec 2021 01:08:46 +0100 Subject: [PATCH 4/7] Implement login/register --- .gitignore | 1 + error/migrations/0001_initial.py | 21 +++++++ .../{settings.py => settings.py.exemple} | 9 +++ nuitdelinfo_2021/urls.py | 2 + people/migrations/0001_initial.py | 32 ++++++++++ people/migrations/0002_auto_20211202_2127.py | 59 ++++++++++++++++++ people/migrations/0003_auto_20211202_2225.py | 60 +++++++++++++++++++ rescue/migrations/0001_initial.py | 30 ++++++++++ rescue/migrations/0002_auto_20211202_2301.py | 24 ++++++++ .../activation_complete.html | 1 + .../activation_email_body.txt | 2 + .../activation_email_subject.txt | 1 + .../activation_failed.html | 1 + .../registration_closed.html | 1 + .../registration_complete.html | 1 + .../registration_form.html | 5 ++ templates/registration/logged_out.html | 4 ++ templates/registration/login.html | 37 ++++++++++++ .../registration/password_reset_complete.html | 4 ++ .../registration/password_reset_confirm.html | 27 +++++++++ .../registration/password_reset_done.html | 3 + .../registration/password_reset_email.html | 2 + .../registration/password_reset_form.html | 10 ++++ 23 files changed, 337 insertions(+) create mode 100644 error/migrations/0001_initial.py rename nuitdelinfo_2021/{settings.py => settings.py.exemple} (95%) create mode 100644 people/migrations/0001_initial.py create mode 100644 people/migrations/0002_auto_20211202_2127.py create mode 100644 people/migrations/0003_auto_20211202_2225.py create mode 100644 rescue/migrations/0001_initial.py create mode 100644 rescue/migrations/0002_auto_20211202_2301.py create mode 100644 templates/django_registration/activation_complete.html create mode 100644 templates/django_registration/activation_email_body.txt create mode 100644 templates/django_registration/activation_email_subject.txt create mode 100644 templates/django_registration/activation_failed.html create mode 100644 templates/django_registration/registration_closed.html create mode 100644 templates/django_registration/registration_complete.html create mode 100644 templates/django_registration/registration_form.html create mode 100644 templates/registration/logged_out.html create mode 100644 templates/registration/login.html create mode 100644 templates/registration/password_reset_complete.html create mode 100644 templates/registration/password_reset_confirm.html create mode 100644 templates/registration/password_reset_done.html create mode 100644 templates/registration/password_reset_email.html create mode 100644 templates/registration/password_reset_form.html diff --git a/.gitignore b/.gitignore index d8a75d7..1b4adab 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,4 @@ GitHub.sublime-settings !.vscode/launch.json !.vscode/extensions.json .history +/nuitdelinfo_2021/settings.py diff --git a/error/migrations/0001_initial.py b/error/migrations/0001_initial.py new file mode 100644 index 0000000..bcf7dc6 --- /dev/null +++ b/error/migrations/0001_initial.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.9 on 2021-12-02 20:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='ThomasPesquetQuotes', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('text', models.TextField()), + ], + ), + ] diff --git a/nuitdelinfo_2021/settings.py b/nuitdelinfo_2021/settings.py.exemple similarity index 95% rename from nuitdelinfo_2021/settings.py rename to nuitdelinfo_2021/settings.py.exemple index 2f0b5f7..d7af9dc 100644 --- a/nuitdelinfo_2021/settings.py +++ b/nuitdelinfo_2021/settings.py.exemple @@ -135,3 +135,12 @@ STATICFILES_DIRS = (path.join('static'),) # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +ACCOUNT_ACTIVATION_DAYS = 7 +LOGIN_REDIRECT_URL = '/' + +EMAIL_USE_TLS = True +EMAIL_HOST = 'smtp.gmail.com' +EMAIL_PORT = 587 +EMAIL_HOST_USER = 'me@gmail.com' +EMAIL_HOST_PASSWORD = 'password' diff --git a/nuitdelinfo_2021/urls.py b/nuitdelinfo_2021/urls.py index 72a97e6..6286e2e 100644 --- a/nuitdelinfo_2021/urls.py +++ b/nuitdelinfo_2021/urls.py @@ -23,6 +23,8 @@ urlpatterns = [ path("a/", include("rescue.urls")), path("p/", include("people.urls")), path('admin/', admin.site.urls), + path('accounts/', include('django_registration.backends.activation.urls')), + path('accounts/', include('django.contrib.auth.urls')) ] handler400 = "error.views.index" diff --git a/people/migrations/0001_initial.py b/people/migrations/0001_initial.py new file mode 100644 index 0000000..08d66ae --- /dev/null +++ b/people/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.9 on 2021-12-02 20:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='People', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=40)), + ('last_name', models.CharField(max_length=60)), + ('title', models.CharField(max_length=70)), + ('description', models.TextField()), + ('birth', models.DateField()), + ('death', models.DateField()), + ('history', models.TextField()), + ('genealogy', models.TextField()), + ('awards', models.TextField()), + ('pro_life', models.TextField()), + ('testimonials', models.TextField()), + ('sources', models.TextField()), + ], + ), + ] diff --git a/people/migrations/0002_auto_20211202_2127.py b/people/migrations/0002_auto_20211202_2127.py new file mode 100644 index 0000000..769f649 --- /dev/null +++ b/people/migrations/0002_auto_20211202_2127.py @@ -0,0 +1,59 @@ +# Generated by Django 3.2.9 on 2021-12-02 21:27 + +from django.db import migrations, models +import django_quill.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='people', + name='awards', + field=django_quill.fields.QuillField(null=True), + ), + migrations.AlterField( + model_name='people', + name='death', + field=models.DateField(null=True), + ), + migrations.AlterField( + model_name='people', + name='description', + field=django_quill.fields.QuillField(), + ), + migrations.AlterField( + model_name='people', + name='genealogy', + field=django_quill.fields.QuillField(null=True), + ), + migrations.AlterField( + model_name='people', + name='history', + field=django_quill.fields.QuillField(null=True), + ), + migrations.AlterField( + model_name='people', + name='pro_life', + field=django_quill.fields.QuillField(null=True), + ), + migrations.AlterField( + model_name='people', + name='sources', + field=django_quill.fields.QuillField(), + ), + migrations.AlterField( + model_name='people', + name='testimonials', + field=django_quill.fields.QuillField(null=True), + ), + migrations.AlterField( + model_name='people', + name='title', + field=models.CharField(max_length=70, null=True), + ), + ] diff --git a/people/migrations/0003_auto_20211202_2225.py b/people/migrations/0003_auto_20211202_2225.py new file mode 100644 index 0000000..df83a80 --- /dev/null +++ b/people/migrations/0003_auto_20211202_2225.py @@ -0,0 +1,60 @@ +# Generated by Django 3.2.9 on 2021-12-02 22:25 + +from django.db import migrations, models +import django.db.models.deletion +import django_quill.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0002_auto_20211202_2127'), + ] + + operations = [ + migrations.AddField( + model_name='people', + name='pending_edit_of', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='people.people'), + ), + migrations.AddField( + model_name='people', + name='validated', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='people', + name='awards', + field=django_quill.fields.QuillField(blank=True, null=True), + ), + migrations.AlterField( + model_name='people', + name='death', + field=models.DateField(blank=True, null=True), + ), + migrations.AlterField( + model_name='people', + name='genealogy', + field=django_quill.fields.QuillField(blank=True, null=True), + ), + migrations.AlterField( + model_name='people', + name='history', + field=django_quill.fields.QuillField(blank=True, null=True), + ), + migrations.AlterField( + model_name='people', + name='pro_life', + field=django_quill.fields.QuillField(blank=True, null=True), + ), + migrations.AlterField( + model_name='people', + name='testimonials', + field=django_quill.fields.QuillField(blank=True, null=True), + ), + migrations.AlterField( + model_name='people', + name='title', + field=models.CharField(blank=True, max_length=70, null=True), + ), + ] diff --git a/rescue/migrations/0001_initial.py b/rescue/migrations/0001_initial.py new file mode 100644 index 0000000..33f5c92 --- /dev/null +++ b/rescue/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.9 on 2021-12-02 20:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('people', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Rescue', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=70)), + ('date', models.DateField()), + ('location_long', models.DecimalField(decimal_places=6, max_digits=9)), + ('location_lat', models.DecimalField(decimal_places=6, max_digits=9)), + ('resume', models.CharField(max_length=125)), + ('description', models.TextField()), + ('sources', models.TextField()), + ('rescuers', models.ManyToManyField(related_name='rescued', to='people.People')), + ('saved', models.ManyToManyField(related_name='saved', to='people.People')), + ], + ), + ] diff --git a/rescue/migrations/0002_auto_20211202_2301.py b/rescue/migrations/0002_auto_20211202_2301.py new file mode 100644 index 0000000..305323d --- /dev/null +++ b/rescue/migrations/0002_auto_20211202_2301.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.9 on 2021-12-02 23:01 + +from django.db import migrations +import django_quill.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('rescue', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='rescue', + name='description', + field=django_quill.fields.QuillField(), + ), + migrations.AlterField( + model_name='rescue', + name='sources', + field=django_quill.fields.QuillField(), + ), + ] diff --git a/templates/django_registration/activation_complete.html b/templates/django_registration/activation_complete.html new file mode 100644 index 0000000..ee8b351 --- /dev/null +++ b/templates/django_registration/activation_complete.html @@ -0,0 +1 @@ +Activation complete :/ diff --git a/templates/django_registration/activation_email_body.txt b/templates/django_registration/activation_email_body.txt new file mode 100644 index 0000000..9016fa4 --- /dev/null +++ b/templates/django_registration/activation_email_body.txt @@ -0,0 +1,2 @@ +activation URL: {{site}}/accounts/activate/{{ activation_key }}/ +The number of days remaining during which the account may be activated: {{ expiration_days }} diff --git a/templates/django_registration/activation_email_subject.txt b/templates/django_registration/activation_email_subject.txt new file mode 100644 index 0000000..37320af --- /dev/null +++ b/templates/django_registration/activation_email_subject.txt @@ -0,0 +1 @@ +Activation email for {{ user }} \ No newline at end of file diff --git a/templates/django_registration/activation_failed.html b/templates/django_registration/activation_failed.html new file mode 100644 index 0000000..ccf3414 --- /dev/null +++ b/templates/django_registration/activation_failed.html @@ -0,0 +1 @@ +Activation failed :/ \ No newline at end of file diff --git a/templates/django_registration/registration_closed.html b/templates/django_registration/registration_closed.html new file mode 100644 index 0000000..d12f288 --- /dev/null +++ b/templates/django_registration/registration_closed.html @@ -0,0 +1 @@ +Registration closed :/ \ No newline at end of file diff --git a/templates/django_registration/registration_complete.html b/templates/django_registration/registration_complete.html new file mode 100644 index 0000000..2f6fb3c --- /dev/null +++ b/templates/django_registration/registration_complete.html @@ -0,0 +1 @@ +Registration complete ! \ No newline at end of file diff --git a/templates/django_registration/registration_form.html b/templates/django_registration/registration_form.html new file mode 100644 index 0000000..19e304b --- /dev/null +++ b/templates/django_registration/registration_form.html @@ -0,0 +1,5 @@ +
+ {% csrf_token %} + {{ form }} + +
diff --git a/templates/registration/logged_out.html b/templates/registration/logged_out.html new file mode 100644 index 0000000..61badb0 --- /dev/null +++ b/templates/registration/logged_out.html @@ -0,0 +1,4 @@ +{% block content %} +

Logged out!

+ Click here to login again. +{% endblock %} diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..73fd22d --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,37 @@ +{% block content %} + + {% if form.errors %} +

Your username and password didn't match. Please try again.

+ {% endif %} + + {% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} + {% endif %} + +
+ {% csrf_token %} + + + + + + + + + +
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
+ + +
+ + {# Assumes you setup the password_reset view in your URLconf #} +

Lost password?

+ +

Register

+ +{% endblock %} diff --git a/templates/registration/password_reset_complete.html b/templates/registration/password_reset_complete.html new file mode 100644 index 0000000..5581a6f --- /dev/null +++ b/templates/registration/password_reset_complete.html @@ -0,0 +1,4 @@ +{% block content %} +

The password has been changed!

+

log in again?

+{% endblock %} diff --git a/templates/registration/password_reset_confirm.html b/templates/registration/password_reset_confirm.html new file mode 100644 index 0000000..968951d --- /dev/null +++ b/templates/registration/password_reset_confirm.html @@ -0,0 +1,27 @@ +{% block content %} + {% if validlink %} +

Please enter (and confirm) your new password.

+
+ {% csrf_token %} + + + + + + + + + + + + + +
{{ form.new_password1.errors }} + {{ form.new_password1 }}
{{ form.new_password2.errors }} + {{ form.new_password2 }}
+
+ {% else %} +

Password reset failed

+

The password reset link was invalid, possibly because it has already been used. Please request a new password reset.

+ {% endif %} +{% endblock %} diff --git a/templates/registration/password_reset_done.html b/templates/registration/password_reset_done.html new file mode 100644 index 0000000..db44131 --- /dev/null +++ b/templates/registration/password_reset_done.html @@ -0,0 +1,3 @@ +{% block content %} +

We've emailed you instructions for setting your password. If they haven't arrived in a few minutes, check your spam folder.

+{% endblock %} diff --git a/templates/registration/password_reset_email.html b/templates/registration/password_reset_email.html new file mode 100644 index 0000000..37467b8 --- /dev/null +++ b/templates/registration/password_reset_email.html @@ -0,0 +1,2 @@ +Someone asked for password reset for email {{ email }}. Follow the link below: +{{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} diff --git a/templates/registration/password_reset_form.html b/templates/registration/password_reset_form.html new file mode 100644 index 0000000..6ff122f --- /dev/null +++ b/templates/registration/password_reset_form.html @@ -0,0 +1,10 @@ +{% block content %} +
+ {% csrf_token %} + {% if form.email.errors %} + {{ form.email.errors }} + {% endif %} +

{{ form.email }}

+ +
+{% endblock %} From 232b976f2d6c3303d9624a8263aa72a8b56369ca Mon Sep 17 00:00:00 2001 From: flifloo Date: Fri, 3 Dec 2021 01:11:23 +0100 Subject: [PATCH 5/7] Protect pages with login --- people/views.py | 3 +++ requirements.txt | 3 +++ rescue/views.py | 3 +++ 3 files changed, 9 insertions(+) diff --git a/people/views.py b/people/views.py index b29af5f..3f4dd5d 100644 --- a/people/views.py +++ b/people/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth.decorators import login_required from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest from django.shortcuts import render from django.urls import reverse @@ -19,6 +20,7 @@ def index(request, people_id: int): }) +@login_required def submit(request): if request.method == "POST": form = SubmitPeople(request.POST) @@ -31,6 +33,7 @@ def submit(request): return render(request, "people/submit.html", {"form": form}) +@login_required def edit(request, people_id: int): edited_people = get_people(people_id) if not edited_people.validated: diff --git a/requirements.txt b/requirements.txt index 32348c3..33d2674 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,8 @@ asgiref==3.4.1 +confusable-homoglyphs==3.2.0 Django==3.2.9 django-quill-editor==0.1.22 +django-registration==3.2 +psycopg2==2.9.2 pytz==2021.3 sqlparse==0.4.2 diff --git a/rescue/views.py b/rescue/views.py index da8792c..de31110 100644 --- a/rescue/views.py +++ b/rescue/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth.decorators import login_required from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest from django.shortcuts import render from django.urls import reverse @@ -17,6 +18,7 @@ def index(request, rescue_id: int): return render(request, "article/article.html", {"rescue": get_rescue(rescue_id)}) +@login_required def submit(request): if request.method == "POST": form = SubmitRescue(request.POST) @@ -29,6 +31,7 @@ def submit(request): return render(request, "article/submit.html", {"form": form}) +@login_required def edit(request, rescue_id: int): edited_rescue = get_rescue(rescue_id) if not edited_rescue.validated: From a63fb287fd5ce9ffa6a6b1ed1ace3786c4e4c204 Mon Sep 17 00:00:00 2001 From: flifloo Date: Fri, 3 Dec 2021 01:45:44 +0100 Subject: [PATCH 6/7] Add docker image and compose --- Dockerfile | 9 +++++++++ docker-compose.yml | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5da2f83 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.9.9-alpine +WORKDIR /nuitdelinfo_2021 +COPY . . +RUN apk add --no-cache postgresql-libs && \ + apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \ + pip install --no-cache-dir -r requirements.txt && \ + apk --purge del .build-deps +RUN cp /nuitdelinfo_2021/nuitdelinfo_2021/settings.py.exemple /nuitdelinfo_2021/nuitdelinfo_2021/settings.py +CMD [ "python", "./manage.py", "runserver", "0.0.0.0:8000"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..39a6e11 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3" + +services: + django: + container_name: "nuitdelinfo_2021" + build: ./ + image: nuitdelinfo_2021 + ports: + - "8001:8000" + volumes: + - "django:/nuitdelinfo_2021/" + + postgres: + container_name: "nuitdelinfo_2021_db" + image: postgres + environment: + POSTGRES_PASSWORD: nuitdelinfo_2021 + POSTGRES_USER: nuitdelinfo_2021 + POSTGRES_DB: nuitdelinfo_2021 + volumes: + - "db:/var/lib/postgresql/data" + +volumes: + django: + db: From 8f10a444232a50a84342817396f742f6c79c8e5f Mon Sep 17 00:00:00 2001 From: flifloo Date: Fri, 3 Dec 2021 01:46:05 +0100 Subject: [PATCH 7/7] Test GitHub django workflow --- .github/workflows/django.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/django.yml diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml new file mode 100644 index 0000000..9fb493f --- /dev/null +++ b/.github/workflows/django.yml @@ -0,0 +1,30 @@ +name: Django CI + +on: + push: + branches: [ master, flifloo, kybo ] + pull_request: + branches: [ master, flifloo, kybo ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.7, 3.8, 3.9] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run Tests + run: | + python manage.py test