Merge pull request #6 from flifloo/flifloo

Merge branch flifloo
This commit is contained in:
Ethanell 2021-12-03 04:53:35 +01:00 committed by GitHub
commit 804de77f12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 360 additions and 135 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 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) members = ManyToManyField(People)
description = TextField() description = TextField()
def __str__(self):
return self.name

View file

@ -1,3 +1,6 @@
from django.contrib import admin 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): class ThomasPesquetQuotes(Model):
text = TextField() 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 # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
"core.apps.AppConfig",
"rescue.apps.RescueConfig", "rescue.apps.RescueConfig",
"people.apps.PeopleConfig", "people.apps.PeopleConfig",
"boat.apps.BoatConfig",
"error.apps.ErrorConfig", "error.apps.ErrorConfig",
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',

View file

@ -15,14 +15,23 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django_registration.views import RegistrationView
from nuitdelinfo_2021 import views from nuitdelinfo_2021 import views
from nuitdelinfo_2021.forms import MyCustomUserForm
urlpatterns = [ urlpatterns = [
path('', views.index, name="index"), path('', views.index, name="index"),
path("a/", include("rescue.urls")), path("a/", include("rescue.urls"), name="rescue"),
path("p/", include("people.urls")), path("p/", include("people.urls"), name="people"),
path("b/", include("boat.urls"), name="boat"),
path('admin/', admin.site.urls), 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_registration.backends.activation.urls')),
path('accounts/', include('django.contrib.auth.urls')) path('accounts/', include('django.contrib.auth.urls'))
] ]

View file

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

View file

@ -1,3 +1,5 @@
from django.contrib import admin 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("", views.index, name='index'),
path("<int:people_id>/", views.details, name='details'), path("<int:people_id>/", views.details, name='details'),
path("submit/", views.submit, name="submit"), 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.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.shortcuts import render
from django.urls import reverse from django.urls import reverse
@ -25,13 +26,14 @@ def details(request, people_id: int):
"people": get_people(people_id) "people": get_people(people_id)
}) })
@login_required @login_required
def submit(request): def submit(request):
if request.method == "POST": if request.method == "POST":
form = SubmitPeople(request.POST) form = SubmitPeople(request.POST)
if form.is_valid(): if form.is_valid():
people = form.save() people = form.save()
return HttpResponseRedirect(reverse(index, args=[people.pk])) return HttpResponseRedirect(reverse(details, args=[people.pk]))
else: else:
form = SubmitPeople() form = SubmitPeople()
@ -51,9 +53,13 @@ def edit(request, people_id: int):
people.pending_edit_of = edited_people people.pending_edit_of = edited_people
people.save() people.save()
return HttpResponseRedirect(reverse(index, args=[people.pk])) return HttpResponseRedirect(reverse(details, args=[people.pk]))
else: else:
edited_people.pk = None edited_people.pk = None
form = SubmitPeople(instance=edited_people) form = SubmitPeople(instance=edited_people)
return render(request, "people/edit.html", {"form": form, "edit_id": people_id}) 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 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 SubmitRescue(ModelForm):
class Meta: class Meta:
model = Rescue 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"] "sources"]
widgets = { widgets = {
"date": DateInput() "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 django_quill.fields import QuillField
from boat.models import Boat
from people.models import People from people.models import People
@ -15,7 +17,14 @@ class Rescue(Model):
saved = ManyToManyField(People, related_name="saved") saved = ManyToManyField(People, related_name="saved")
rescuers = ManyToManyField(People, related_name="rescued") 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() description = QuillField()
sources = QuillField() sources = QuillField()
def __str__(self):
return self.name

View file

@ -6,5 +6,6 @@ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('<int:rescue_id>/', views.details, name='details'), path('<int:rescue_id>/', views.details, name='details'),
path("submit/", views.submit, name="submit"), 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.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.shortcuts import render
from django.urls import reverse from django.urls import reverse
@ -28,7 +29,7 @@ def submit(request):
form = SubmitRescue(request.POST) form = SubmitRescue(request.POST)
if form.is_valid(): if form.is_valid():
rescue = form.save() rescue = form.save()
return HttpResponseRedirect(reverse(index, args=[rescue.pk])) return HttpResponseRedirect(reverse(details, args=[rescue.pk]))
else: else:
form = SubmitRescue() form = SubmitRescue()
@ -48,9 +49,13 @@ def edit(request, rescue_id: int):
rescue.pending_edit_of = edited_rescue rescue.pending_edit_of = edited_rescue
rescue.save() rescue.save()
return HttpResponseRedirect(reverse(index, args=[rescue.pk])) return HttpResponseRedirect(reverse(details, args=[rescue.pk]))
else: else:
edited_rescue.pk = None edited_rescue.pk = None
form = SubmitRescue(instance=edited_rescue) form = SubmitRescue(instance=edited_rescue)
return render(request, "article/edit.html", {"form": form, "edit_id": 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 static %}
{% load md5 %}
<head> <head>
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
@ -11,14 +12,18 @@
<div class="left"> <div class="left">
<a href="" class="logo">LSDD</a> <a href="" class="logo">LSDD</a>
<div class="submenu"> <div class="submenu">
<a href="">Articles</a> <a href="/a/">Articles</a>
<a href="">Personnes</a> <a href="/p/">Personnes</a>
<a href="">Equipages</a> <a href="/c/">Equipages</a>
</div> </div>
</div> </div>
<div class="right"> <div class="right">
<a href="#quicksearch"><i class="material-icons search">search</i></a> <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> </div>
</nav> </nav>
@ -27,4 +32,3 @@
{% endblock %} {% endblock %}
</div> </div>
</body> </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 %} {% csrf_token %}
{{ form }} {{ form }}
<input type="submit" value="login" /> <input type="submit" value="Inscription">
</form> </form>
</div>
</section>
</body>

View file

@ -9,42 +9,20 @@
<section> <section>
<h2>Articles récents</h2> <h2>Articles récents</h2>
<div class="flex-card"> <div class="flex-card">
{% for rescue in rescues %}
<div class="card"> <div class="card">
<div class="inner"> <div class="inner">
<div class="img-container"> <div class="img-container">
<img src="{% static 'images/sauvetage.png' %}"> <img src="{% static 'images/sauvetage.png' %}">
</div> </div>
<div class="content"> <div class="content">
<p class="date">16/02/2020</p> <p class="date">{{ rescue.date }}</p>
<p class="titre">Sauvetage risqué en côte d'Ivoire</p> <p class="titre">{{ rescue.name }}</p>
<a class="btn" href="">Voir l'article</a> <a class="btn" href="/a/{{ rescue.pk }}">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>
</div> </div>
</div> </div>
</div> </div>
{% endfor %}
</div> </div>
</section> </section>
{% include 'quicksearch.html' %} {% include 'quicksearch.html' %}

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 %} {% block content %}
<p>Logged out!</p> <p>Logged out!</p>
<a href="{% url 'login'%}">Click here to login again.</a> <a href="/">Click here to go home.</a>
{% endblock %} {% endblock %}

View file

@ -1,37 +1,36 @@
{% block content %} {% load static %}
{% if form.errors %} <head>
<p>Your username and password didn't match. Please try again.</p> <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
{% endif %} <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 next %}
{% if user.is_authenticated %} {% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed, <p>Votre compte n'a pas accès à cette page. Pour continuer, veuillez vous connecter avec un compte qui a accès.</p>
please login with an account that has access.</p>
{% else %} {% else %}
<p>Please login to see this page.</p> <p>Veuillez vous connecter pour voir cette page.</p>
{% endif %} {% endif %}
{% 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' %}"> <form method="post" action="{% url 'login' %}">
{% csrf_token %} {% csrf_token %}
<table> <input type="text" name="username" placeholder="Nom d'utilisateur">
<tr> <input type="password" name="password" placeholder="Mot de passe">
<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="hidden" name="next" value="{{ next }}" /> <input type="hidden" name="next" value="{{ next }}" />
<input type="submit" value="Connexion">
</form> </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 'password_reset' %}">Lost password?</a></p>
<p><a href="{% url 'django_registration_register' %}">Register</a></p> <p><a href="{% url 'django_registration_register' %}">Register</a></p>
</section>
{% endblock %}