First Commit
This commit is contained in:
commit
ce0758fbbb
496 changed files with 52062 additions and 0 deletions
0
guestbook/__init__.py
Executable file
0
guestbook/__init__.py
Executable file
3
guestbook/admin.py
Executable file
3
guestbook/admin.py
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
guestbook/apps.py
Executable file
6
guestbook/apps.py
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class GuestbookConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "guestbook"
|
||||
12
guestbook/forms.py
Executable file
12
guestbook/forms.py
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
from django import forms
|
||||
|
||||
class CreateGuestbook(forms.Form):
|
||||
author = forms.CharField(
|
||||
max_length=150,
|
||||
label='',
|
||||
widget=forms.TextInput(attrs={'placeholder': 'Nom'})
|
||||
)
|
||||
content = forms.CharField(
|
||||
label='',
|
||||
widget=forms.Textarea(attrs={'placeholder': 'Message'})
|
||||
)
|
||||
14
guestbook/middleware.py
Executable file
14
guestbook/middleware.py
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
from django.utils.deprecation import MiddlewareMixin
|
||||
from guestbook.models import Guestbook
|
||||
|
||||
class GuestbookMiddleware(MiddlewareMixin):
|
||||
def process_request(self, request):
|
||||
# On récupère les messages du livre d'or et les auteurs
|
||||
guestbook = Guestbook.objects.all().order_by('-created')[:5]
|
||||
|
||||
# On compte le nombre de messages
|
||||
total_guestbook = Guestbook.objects.count()
|
||||
|
||||
# On ajoute les variables à l'objet request
|
||||
request.guestbook = guestbook
|
||||
request.total_guestbook = total_guestbook
|
||||
23
guestbook/migrations/0001_initial.py
Executable file
23
guestbook/migrations/0001_initial.py
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 4.2.16 on 2024-10-22 11:02
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Guestbook",
|
||||
fields=[
|
||||
("id", models.AutoField(primary_key=True, serialize=False)),
|
||||
("author", models.CharField(default="Visiteur", max_length=50)),
|
||||
("content", models.CharField(max_length=100)),
|
||||
("created", models.DateTimeField(auto_now_add=True)),
|
||||
("active", models.BooleanField(default=True)),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
guestbook/migrations/__init__.py
Executable file
0
guestbook/migrations/__init__.py
Executable file
11
guestbook/models.py
Executable file
11
guestbook/models.py
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
from django.db import models
|
||||
|
||||
class Guestbook(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
author = models.CharField(max_length=50, default='Visiteur')
|
||||
content = models.CharField(max_length=100)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'Guestbook({self.id}, {self.author}, {self.content}, {self.created})'
|
||||
3
guestbook/tests.py
Executable file
3
guestbook/tests.py
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
9
guestbook/urls.py
Executable file
9
guestbook/urls.py
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
from django.urls import path
|
||||
from django.conf.urls.static import static
|
||||
|
||||
from passion_retro import settings
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.guestbook_home, name="guestbook_home"),
|
||||
]
|
||||
29
guestbook/views.py
Executable file
29
guestbook/views.py
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
from django.core.paginator import Paginator
|
||||
from django.shortcuts import render
|
||||
from .models import Guestbook
|
||||
from .forms import CreateGuestbook
|
||||
|
||||
def guestbook_home(request):
|
||||
# Si un message est envoyé on le traite
|
||||
if request.method == "POST":
|
||||
form = CreateGuestbook(request.POST)
|
||||
if form.is_valid():
|
||||
author = form.cleaned_data['author']
|
||||
content = form.cleaned_data['content']
|
||||
Guestbook.objects.create(author=author, content=content)
|
||||
|
||||
guestbook = Guestbook.objects.all().order_by('-created')
|
||||
paginator = Paginator(guestbook, 10)
|
||||
|
||||
page_number = request.GET.get('page')
|
||||
guestbook = paginator.get_page(page_number)
|
||||
|
||||
context = {
|
||||
'guestbook': guestbook,
|
||||
'is_paginated': guestbook.has_other_pages(),
|
||||
'page_obj': guestbook,
|
||||
'paginator': paginator,
|
||||
'form': CreateGuestbook(),
|
||||
}
|
||||
|
||||
return render(request, "components/guestbook_home.html", context)
|
||||
Loading…
Add table
Add a link
Reference in a new issue