Merge branch 'master' into kybo

# Conflicts:
#	templates/base.html
This commit is contained in:
Ethanell 2021-12-03 04:55:50 +01:00
commit 5771853cdc
45 changed files with 358 additions and 133 deletions

0
boat/__init__.py Normal file
View file

3
boat/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
boat/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class BoatConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'boat'

13
boat/forms.py Normal file
View file

@ -0,0 +1,13 @@
from django.forms import ModelForm, DateInput
from boat.models import Boat
class DateInput(DateInput):
input_type = "date"
class SubmitBoat(ModelForm):
class Meta:
model = Boat
fields = ["name", "model", "description"]

View file

17
boat/models.py Normal file
View file

@ -0,0 +1,17 @@
from django.db.models import Model, CharField, BooleanField, ForeignKey, CASCADE
from django_quill.fields import QuillField
from people.models import People
class Boat(Model):
name = CharField(max_length=80)
model = CharField(max_length=80)
description = QuillField()
validated = BooleanField(default=False)
pending_edit_of = ForeignKey(People, on_delete=CASCADE, null=True, blank=True)
def __str__(self):
return self.name

3
boat/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

11
boat/urls.py Normal file
View file

@ -0,0 +1,11 @@
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name='index'),
path("<int:boat_id>/", views.details, name='details'),
path("submit/", views.submit, name="submit"),
path("edit/<int:boat_id>/", views.edit, name="edit"),
path("ajax/search/<str:text>/", views.ajax_search, name="ajax_search")
]

65
boat/views.py Normal file
View file

@ -0,0 +1,65 @@
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest, JsonResponse
from django.shortcuts import render
from django.urls import reverse
from boat.forms import SubmitBoat
from boat.models import Boat
def get_boat(boat_id: int) -> Boat:
try:
return Boat.objects.get(pk=boat_id)
except Boat.DoesNotExist:
raise Http404("Boat does not exist")
def index(request):
return render(request, "boat/boats.html", {
"boats": Boat.objects.all()
})
def details(request, boat_id: int):
return render(request, "boat/boat.html", {
"boat": get_boat(boat_id)
})
@login_required
def submit(request):
if request.method == "POST":
form = SubmitBoat(request.POST)
if form.is_valid():
boat = form.save()
return HttpResponseRedirect(reverse(details, args=[boat.pk]))
else:
form = SubmitBoat()
return render(request, "boat/submit.html", {"form": form})
@login_required
def edit(request, boat_id: int):
edited_boat = get_boat(boat_id)
if not edited_boat.validated:
return HttpResponseBadRequest("This entry is not validated, you can't edit it")
if request.method == "POST":
form = SubmitBoat(request.POST)
if form.is_valid():
boat = form.save()
boat.pending_edit_of = edited_boat
boat.save()
return HttpResponseRedirect(reverse(details, args=[boat.pk]))
else:
edited_boat.pk = None
form = SubmitBoat(instance=edited_boat)
return render(request, "boat/edit.html", {"form": form, "edit_id": boat_id})
def ajax_search(request, text: str):
return JsonResponse(Boat.objects.filter(Q(name__icontains=text) | Q(description__icontains=text)))

0
core/__init__.py Normal file
View file

3
core/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
core/apps.py Normal file
View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class CoreConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'core'

View file

3
core/models.py Normal file
View file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View file

9
core/templatetags/md5.py Normal file
View file

@ -0,0 +1,9 @@
from django import template
import hashlib
register = template.Library()
@register.filter(name='md5')
def md5_string(value: str):
return hashlib.md5(value.encode()).hexdigest()

3
core/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
core/views.py Normal file
View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View file

@ -1,3 +1,6 @@
from django.contrib import admin
# Register your models here.
from crew.models import Crew
admin.site.register(Crew)

View file

@ -8,3 +8,6 @@ class Crew(Model):
members = ManyToManyField(People)
description = TextField()
def __str__(self):
return self.name

View file

@ -1,3 +1,6 @@
from django.contrib import admin
# Register your models here.
from error.models import ThomasPesquetQuotes
admin.site.register(ThomasPesquetQuotes)

View file

@ -3,3 +3,6 @@ from django.db.models import Model, TextField
class ThomasPesquetQuotes(Model):
text = TextField()
def __str__(self):
return self.text

12
nuitdelinfo_2021/forms.py Normal file
View file

@ -0,0 +1,12 @@
from django.forms import TextInput, PasswordInput
from django_registration.forms import RegistrationForm
class MyCustomUserForm(RegistrationForm):
class Meta(RegistrationForm.Meta):
widgets = {
"username": TextInput(attrs={'placeholder': "Nom d'utilisateur"}),
"email": TextInput(attrs={'placeholder': "Email"}),
"password1": PasswordInput(attrs={'placeholder': "Mot de passe"}),
"password2": PasswordInput(attrs={'placeholder': "Confirmation du mot de passe"}),
}

View file

@ -31,8 +31,10 @@ ALLOWED_HOSTS = ["3cab-134-214-214-199.ngrok.io", "localhost", "4125-134-214-214
# Application definition
INSTALLED_APPS = [
"core.apps.AppConfig",
"rescue.apps.RescueConfig",
"people.apps.PeopleConfig",
"boat.apps.BoatConfig",
"error.apps.ErrorConfig",
'django.contrib.admin',
'django.contrib.auth',

View file

@ -15,14 +15,23 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
from django_registration.views import RegistrationView
from nuitdelinfo_2021 import views
from nuitdelinfo_2021.forms import MyCustomUserForm
urlpatterns = [
path('', views.index, name="index"),
path("a/", include("rescue.urls")),
path("p/", include("people.urls")),
path("a/", include("rescue.urls"), name="rescue"),
path("p/", include("people.urls"), name="people"),
path("b/", include("boat.urls"), name="boat"),
path('admin/', admin.site.urls),
path('accounts/register/',
RegistrationView.as_view(
form_class=MyCustomUserForm
),
name='django_registration_register',
),
path('accounts/', include('django_registration.backends.activation.urls')),
path('accounts/', include('django.contrib.auth.urls'))
]

View file

@ -1,6 +1,9 @@
from django.shortcuts import render
from rescue.models import Rescue
def index(request):
context = {}
return render(request, "index.html", context)
return render(request, "index.html", {
"rescues": Rescue.objects.order_by("date")[:3]
})

View file

@ -1,3 +1,5 @@
from django.contrib import admin
# Register your models here.
from people.models import People
admin.site.register(People)

View file

@ -6,5 +6,6 @@ urlpatterns = [
path("", views.index, name='index'),
path("<int:people_id>/", views.details, name='details'),
path("submit/", views.submit, name="submit"),
path("edit/<int:people_id>/", views.edit, name="edit")
path("edit/<int:people_id>/", views.edit, name="edit"),
path("ajax/search/<str:text>/", views.ajax_search, name="ajax_search")
]

View file

@ -1,5 +1,6 @@
from django.contrib.auth.decorators import login_required
from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest
from django.db.models import Q
from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest, JsonResponse
from django.shortcuts import render
from django.urls import reverse
@ -25,13 +26,14 @@ def details(request, people_id: int):
"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]))
return HttpResponseRedirect(reverse(details, args=[people.pk]))
else:
form = SubmitPeople()
@ -51,9 +53,13 @@ def edit(request, people_id: int):
people.pending_edit_of = edited_people
people.save()
return HttpResponseRedirect(reverse(index, args=[people.pk]))
return HttpResponseRedirect(reverse(details, 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})
def ajax_search(request, text: str):
return JsonResponse(People.objects.filter(Q(first_name__icontains=text) | Q(first_name__icontains=text)))

View file

@ -1,3 +1,6 @@
from django.contrib import admin
# Register your models here.
from rescue.models import Rescue
admin.site.register(Rescue)

View file

@ -10,7 +10,7 @@ class DateInput(DateInput):
class SubmitRescue(ModelForm):
class Meta:
model = Rescue
fields = ["name", "date", "location_long", "location_lat", "resume", "saved", "rescuers", "description",
fields = ["name", "date", "location_long", "location_lat", "resume", "saved", "rescuers", "boats", "description",
"sources"]
widgets = {
"date": DateInput()

View file

@ -1,6 +1,8 @@
from django.db.models import Model, CharField, DateField, ManyToManyField, DecimalField
from django.db.models import Model, CharField, DateField, ManyToManyField, DecimalField, BooleanField, ForeignKey, \
CASCADE
from django_quill.fields import QuillField
from boat.models import Boat
from people.models import People
@ -15,7 +17,14 @@ class Rescue(Model):
saved = ManyToManyField(People, related_name="saved")
rescuers = ManyToManyField(People, related_name="rescued")
boats = ManyToManyField(Boat)
validated = BooleanField(default=False)
pending_edit_of = ForeignKey(People, on_delete=CASCADE, null=True, blank=True)
description = QuillField()
sources = QuillField()
def __str__(self):
return self.name

View file

@ -6,5 +6,6 @@ urlpatterns = [
path('', views.index, name='index'),
path('<int:rescue_id>/', views.details, name='details'),
path("submit/", views.submit, name="submit"),
path("edit/<int:rescue_id>/", views.edit, name="edit")
path("edit/<int:rescue_id>/", views.edit, name="edit"),
path("ajax/search/<str:text>/", views.ajax_search, name="ajax_search")
]

View file

@ -1,5 +1,6 @@
from django.contrib.auth.decorators import login_required
from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest
from django.db.models import Q
from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest, JsonResponse
from django.shortcuts import render
from django.urls import reverse
@ -28,7 +29,7 @@ def submit(request):
form = SubmitRescue(request.POST)
if form.is_valid():
rescue = form.save()
return HttpResponseRedirect(reverse(index, args=[rescue.pk]))
return HttpResponseRedirect(reverse(details, args=[rescue.pk]))
else:
form = SubmitRescue()
@ -48,9 +49,13 @@ def edit(request, rescue_id: int):
rescue.pending_edit_of = edited_rescue
rescue.save()
return HttpResponseRedirect(reverse(index, args=[rescue.pk]))
return HttpResponseRedirect(reverse(details, 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})
def ajax_search(request, text: str):
return JsonResponse(Rescue.objects.filter(Q(name__icontains=text) | Q(date__icontains=text) | Q(resume__icontains=text)))

View file

@ -1,4 +1,5 @@
{% load static %}
{% load md5 %}
<head>
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
@ -14,12 +15,16 @@
<div class="submenu">
<a href="/a/">Sauvetages</a>
<a href="/p/">Personnes</a>
<a href="">Equipages</a>
<a href="/b/">Bateaux</a>
</div>
</div>
<div class="right">
<a href="#quicksearch"><i class="material-icons search">search</i></a>
<img src="{% static 'images/pesquet.jpg' %}">
{% if user.is_authenticated %}
<a href="{% url 'logout' %}"><img src="https://www.gravatar.com/avatar/{{ user.email | lower | md5 }}"></a>
{% else %}
<a href="{% url 'login' %}">Login</a>
{% endif %}
</div>
</nav>
@ -28,4 +33,3 @@
{% endblock %}
</div>
</body>

17
templates/boat/boat.html Normal file
View file

@ -0,0 +1,17 @@
{% if not rescue.validated %}
{% if rescue.pending_edit_of %}
<h1>This edit is not validated !</h1>
{% else %}
<h1>This new entry is not validated !</h1>
{% endif %}
{% endif %}
{{ boat.name }} <br />
{{ boat.model }} <br />
<br />
{{ boat.description.html | safe }} <br />
<h3>Rescues</h3>
{% for rescue in rescues.all %}
<a href="/a/{{ rescue.pk }}">{{ rescue }}</a>
{% endfor %}

25
templates/boat/boats.html Normal file
View file

@ -0,0 +1,25 @@
{% extends 'base.html' %}
{% load static %}
{% block content %}
<section>
<h1>Bateaux</h1>
<div class="flex-card">
{% for boat in boats %}
<div class="card">
<div class="inner">
<div class="img-container">
<img src="{% static 'images/sauvetage.png' %}">
</div>
<div class="content">
<p class="titre">{{ boat.name }}</p>
<a class="btn" href="/b/{{ boat.pk }}/">Voir le bateau</a>
</div>
</div>
</div>
{% endfor %}
</div>
<a class="btn btn--blue" href="">Charger plus de bateaux</a>
</section>
{% include 'quicksearch.html' %}
{% endblock %}

10
templates/boat/edit.html Normal file
View file

@ -0,0 +1,10 @@
<head>
{{ form.media }}
</head>
<body>
<form action="/b/edit/{{ edit_id }}/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
</body>

View file

@ -0,0 +1,10 @@
<head>
{{ form.media }}
</head>
<body>
<form action="/b/submit/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
</body>

View file

@ -1,5 +1,20 @@
<form method="post">
{% load static %}
<head>
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="{% static 'js/script.js' %}"></script>
</head>
<body>
<section>
<h1 class="regilog-title">S'inscrire</h1>
<div class="regilog-form">
<form method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="login" />
</form>
<input type="submit" value="Inscription">
</form>
</div>
</section>
</body>

View file

@ -10,42 +10,20 @@
<section>
<h2>Articles récents</h2>
<div class="flex-card">
{% for rescue in rescues %}
<div class="card">
<div class="inner">
<div class="img-container">
<img src="{% static 'images/sauvetage.png' %}">
</div>
<div class="content">
<p class="date">16/02/2020</p>
<p class="titre">Sauvetage risqué en côte d'Ivoire</p>
<a class="btn" href="">Voir l'article</a>
</div>
</div>
</div>
<div class="card">
<div class="inner">
<div class="img-container">
<img src="{% static 'images/sauvetage.png' %}">
</div>
<div class="content">
<p class="date">16/02/2020</p>
<p class="titre">Sauvetage risqué en côte d'Ivoire</p>
<a class="btn" href="">Voir l'article</a>
</div>
</div>
</div>
<div class="card">
<div class="inner">
<div class="img-container">
<img src="{% static 'images/sauvetage.png' %}">
</div>
<div class="content">
<p class="date">16/02/2020</p>
<p class="titre">Sauvetage risqué en côte d'Ivoire</p>
<a class="btn" href="">Voir l'article</a>
<p class="date">{{ rescue.date }}</p>
<p class="titre">{{ rescue.name }}</p>
<a class="btn" href="/a/{{ rescue.pk }}">Voir l'article</a>
</div>
</div>
</div>
{% endfor %}
</div>
</section>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>

View file

@ -1,19 +0,0 @@
{% load static %}
<head>
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="{% static 'js/script.js' %}"></script>
</head>
<body>
<section>
<h1 class="regilog-title">Se connecter</h1>
<div class="regilog-form">
<input type="text" placeholder="Nom d'utilisateur">
<input type="password" placeholder="Mot de passe">
<input type="submit" value="Connexion">
</div>
</section>
</body>

View file

@ -1,24 +0,0 @@
{% load static %}
<head>
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="{% static 'js/script.js' %}"></script>
</head>
<body>
<section>
<h1 class="regilog-title">S'inscrire</h1>
<div class="regilog-form">
<div class="flexgroup">
<input type="text" placeholder="Prénom">
<input type="text" placeholder="Nom">
</div>
<input type="text" placeholder="Nom d'utilisateur">
<input type="email" placeholder="Email">
<input type="password" placeholder="Mot de passe">
<input type="submit" value="Inscription">
</div>
</section>
</body>

View file

@ -1,4 +1,4 @@
{% block content %}
<p>Logged out!</p>
<a href="{% url 'login'%}">Click here to login again.</a>
<a href="/">Click here to go home.</a>
{% endblock %}

View file

@ -1,37 +1,36 @@
{% block content %}
{% load static %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<head>
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="{% static 'js/script.js' %}"></script>
</head>
<body>
<section>
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
<p>Votre compte n'a pas accès à cette page. Pour continuer, veuillez vous connecter avec un compte qui a accès.</p>
{% else %}
<p>Please login to see this page.</p>
<p>Veuillez vous connecter pour voir cette page.</p>
{% endif %}
{% endif %}
<h1 class="regilog-title">Se connecter</h1>
{% if form.errors %}
<p>Votre nom d'utilisateur et votre mot de passe ne correspondent pas. Veuillez réessayer.</p>
{% endif %}
<div class="regilog-form">
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
<input type="text" name="username" placeholder="Nom d'utilisateur">
<input type="password" name="password" placeholder="Mot de passe">
<input type="hidden" name="next" value="{{ next }}" />
<input type="submit" value="Connexion">
</form>
</div>
{# Assumes you setup the password_reset view in your URLconf #}
<p><a href="{% url 'password_reset' %}">Lost password?</a></p>
<p><a href="{% url 'django_registration_register' %}">Register</a></p>
{% endblock %}
</section>