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 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/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/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/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: 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/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/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.exemple similarity index 87% rename from nuitdelinfo_2021/settings.py rename to nuitdelinfo_2021/settings.py.exemple index cf7903c..2cafeae 100644 --- a/nuitdelinfo_2021/settings.py +++ b/nuitdelinfo_2021/settings.py.exemple @@ -31,12 +31,16 @@ ALLOWED_HOSTS = ["3cab-134-214-214-199.ngrok.io", "localhost", "4125-134-214-214 # Application definition INSTALLED_APPS = [ + "rescue.apps.RescueConfig", + "people.apps.PeopleConfig", + "error.apps.ErrorConfig", 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + "django_quill" ] MIDDLEWARE = [ @@ -76,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' + }, } @@ -128,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 eec4ad8..6286e2e 100644 --- a/nuitdelinfo_2021/urls.py +++ b/nuitdelinfo_2021/urls.py @@ -14,11 +14,19 @@ 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), + path('accounts/', include('django_registration.backends.activation.urls')), + path('accounts/', include('django.contrib.auth.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/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/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/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..4a3d94a --- /dev/null +++ b/people/models.py @@ -0,0 +1,27 @@ +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) + last_name = CharField(max_length=60) + + title = CharField(max_length=70, null=True, blank=True) + description = QuillField() + + birth = DateField() + death = DateField(null=True, blank=True) + + 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 = QuillField(null=True, blank=True) + sources = QuillField() + + 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/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..ae7518b --- /dev/null +++ b/people/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + 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 new file mode 100644 index 0000000..3f4dd5d --- /dev/null +++ b/people/views.py @@ -0,0 +1,54 @@ +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 + +from people.forms import SubmitPeople +from people.models import People + + +def get_people(people_id: int) -> People: + try: + return People.objects.get(pk=people_id) + except People.DoesNotExist: + raise Http404("People does not exist") + + +def index(request, people_id: int): + return render(request, "people/people.html", { + "people": get_people(people_id) + }) + + +@login_required +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}) + + +@login_required +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 new file mode 100644 index 0000000..33d2674 --- /dev/null +++ b/requirements.txt @@ -0,0 +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/__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/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/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/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..5089e3b --- /dev/null +++ b/rescue/models.py @@ -0,0 +1,21 @@ +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) + 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) + + saved = ManyToManyField(People, related_name="saved") + rescuers = ManyToManyField(People, related_name="rescued") + + description = QuillField() + + sources = QuillField() 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..491a8a0 --- /dev/null +++ b/rescue/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + 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 new file mode 100644 index 0000000..de31110 --- /dev/null +++ b/rescue/views.py @@ -0,0 +1,52 @@ +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 + +from rescue.forms import SubmitRescue +from rescue.models import Rescue + + +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)}) + + +@login_required +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}) + + +@login_required +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/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/crew.html b/templates/crew.html new file mode 100644 index 0000000..e69de29 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/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/edit.html b/templates/people/edit.html new file mode 100644 index 0000000..2d13a50 --- /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 }} + +
+ 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 %}