Skip to content
Snippets Groups Projects
Commit 47815486 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

TP10 terminé + Page ingrédients & création pizza.

parent e65da1d9
Branches
No related tags found
No related merge requests found
Showing
with 408 additions and 21 deletions
......@@ -27,12 +27,27 @@
</div>
<nav class="navbar">
<ul>
{% if user.is_authenticated %}
<li class="nav-link active">
<a href="/pizzas/">Les pizzas</a>
</li>
<li class="nav-link">
<a href="/ingredients/">Les ingrédients</a>
</li>
<li class="nav-link">
<a href="/pizzas/add">Ajouter une pizza</a>
</li>
<li class="nav-link">
<a href="/ingredients/add">Ajouter un ingrédient</a>
</li>
<li class="nav-link">
<a href="{% url 'logout' %}">Déconnexion</a>
</li>
{% else %}
<li class="nav-link">
<a href="{% url 'login' %}">Connexion</a>
</li>
{% endif %}
</ul>
</nav>
</div>
......
{% extends 'applipizza/base.html' %}
{% load static %}
{% block title %}
Lasri Del Arte - Ajouter un ingrédient
{% endblock %}
{% block content %}
<div class="container">
{% if status %}
{% if status == 'success' %}
<div class="alert-message success" data-alert>
<a class="close" href="#">×</a>
<p><strong>Enregistré !</strong> L'ingrédient {{ nomIngredient }} a bien été ajouté.</p>
</div>
{% endif %}
{% if status == 'error' %}
<div class="alert-message error" data-alert>
<a class="close" href="#">×</a>
<p><strong>Erreur !</strong> L'ingrédient n'a pas pu être ajouté.</p>
</div>
{% endif %}
{% endif %}
<h2>Ajouter un ingrédient</h2>
<p>Renseigner le nom de l'ingrédient à ajouter.</p>
<form method="post" class="form-stacked">
{% csrf_token %}
{% for field in form %}
{% if field.errors %}
<div class="clearfix error">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="input">
{{ field }}
<span class="help-inline">
{% for error in field.errors %}
{{ error }}
{% endfor %}
</span>
</div>
{% else %}
<div class="clearfix">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="input">
{{ field }}
</div>
</div>
{% endif %}
{% endfor %}
<div class="actions">
<input type="submit" value="Ajouter" class="btn primary">
<button type="reset" class="btn">Annuler</button>
</div>
</form>
</div>
{% endblock %}
{% block javascripts %}
<script type="text/javascript" src="{% static 'applipizza/js/bootstrap-alerts.js' %}"></script>
<script type="text/javascript">
var form = $('form');
var formRequiredFields = form.find('input[required]');
var formSubmitButton = form.find('input[type=submit]');
// We disable form validation
form.attr('novalidate', 'novalidate');
form.submit(function (e) {
formRequiredFields.each(function () {
if ($(this).val() == '') {
console.log('empty');
e.preventDefault();
$(this).parent().append('<span class="help-inline">Ce champ est obligatoire</span>');
$(this).parent().parent().addClass('error');
} else {
if ($(this).parent().find('span.help-inline').length > 0) {
$(this).parent().find('span.help-inline').remove();
$(this).parent().parent().removeClass('error');
}
}
});
});
// We disable the submit button
//formSubmitButton.attr('disabled', 'disabled');
</script>
{% endblock %}
\ No newline at end of file
{% extends 'applipizza/base.html' %}
{% load static %}
{% block title %}
Lasri Del Arte - Nos pizzas
{% endblock %}
{% block content %}
<div class="container">
<h2>Nos ingrédients</h2>
<p>Découvrez notre large choix d'ingrédients pas bios.</p>
<table id="ingredients">
<thead>
<tr>
<th>Nom de l'ingrédient</th>
</tr>
</thead>
<tbody>
{% for ingredient in ingredients %}
<tr>
<td>{{ ingredient.nom }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
{% block javascripts %}
<script type="text/javascript" src="{% static 'applipizza/js/bootstrap-alerts.js' %}"></script>
<script type="text/javascript" src="{% static 'applipizza/js/jquery.tablesorter.min.js' %}"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#ingredients').tablesorter({sortList: [[0]]});
});
</script>
{% endblock %}
\ No newline at end of file
from applipizza import views
from django.conf import settings # new
from django.urls import path, include # new
from django.conf.urls.static import static # new
urlpatterns = [
path('', views.pizzas, name="home"),
path('pizzas/', views.pizzas),
path('pizzas/add', views.create_pizza),
path('pizza/<int:id>', views.pizza),
path('pizza/<int:id>/addIngredient', views.ajouterIngredientDansPizza),
path('pizza/<int:pizzaId>/deleteIngredient/<int:compositionId>', views.supprimerIngredientDansPizza),
path('pizza/<int:id>/update', views.modifierPizza),
path('pizza/<int:id>/update/post', views.traitementFormulaireModificationPizza),
path('pizza/<int:id>/delete', views.supprimerPizza),
path('ingredients/', views.listeIngredients),
path('ingredients/add', views.formulaireCreationIngredient),
path('ingredients/add/post', views.creerIngredient),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # new
from django.shortcuts import render
from django.shortcuts import render, redirect
from applipizza.models import Pizza, Ingredient, Composition
from applipizza.forms import IngredientForm, CompositionForm, PizzaForm
......@@ -125,3 +125,25 @@ def supprimerIngredientDansPizza(request, pizzaId, compositionId):
composition = Composition.objects.get(id=compositionId)
composition.delete()
return viewPizza(request, pizzaId, 'success')
def create_pizza(request):
if request.method == 'POST':
form = PizzaForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('pizzas')
else:
form = PizzaForm()
return render(
request,
'applipizza/formulaireCreationPizza.html',
{'form': form}
)
def listeIngredients(request):
ingredients = Ingredient.objects.all()
return render(
request,
'applipizza/ingredients.html',
{'ingredients': ingredients}
)
\ No newline at end of file
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ConnexionConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'connexion'
from django.db import models
# Create your models here.
{% load static %}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'applipizza/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'applipizza/css/font-awesome.min.css' %}">
<link rel="stylesheet" href="{% static 'applipizza/css/styles.css' %}">
</head>
<body>
<header>
<div class="container">
<div class="top-meta">
<div class="logo-link">
<a href="/"><img src="{% static 'applipizza/img/lasridelarte.png' %}" alt="logo"></a>
</div>
<div class="right-part">
<div class="certificate">
<img src="{% static 'applipizza/img/certificate.png' %}" alt="certificat">
</div>
<div class="meta">
<p><strong>Lasri Del Arte
<br>5th Cave Jonhson Street, Rosewood</strong></p>
</div>
</div>
</div>
<nav class="navbar">
<ul>
<li class="nav-link">
<a href="/pizzas">Revenir sur le site</a>
</li>
</ul>
</nav>
</div>
</header>
<div class="page-content">
{% block content %}{% endblock %}
</div>
<footer>
<div class="container">
<p>© 2012 Lasri Del Arte - Tous droits réservés</p>
</div>
</footer>
<script type="text/javascript">
// Si le footer n'est pas tout en bas de la page car il y a peu de contenu
// On le place tout en bas de la page
function footerPosition() {
var footer = document.querySelector("footer")
var footerHeight = footer.offsetHeight;
var windowHeight = window.innerHeight;
var bodyHeight = document.body.offsetHeight;
if (bodyHeight < windowHeight) {
footer.style.position = 'absolute';
footer.style.bottom = '0';
} else {
footer.style.position = 'relative';
footer.style.bottom = '0';
}
}
footerPosition();
window.addEventListener('resize', footerPosition);
</script>
<script src="{% static 'applipizza/js/jquery-1.5.2.min.js' %}"></script>
{% block javascripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
Lasri Del Arte - Ajouter un ingrédient
{% endblock %}
{% block content %}
<div class="container">
{% if form.non_field_error %}
{% if status == 'success' %}
<div class="alert-message success" data-alert>
<a class="close" href="#">×</a>
<p><strong>Connecté !</p>
</div>
{% endif %}
{% if form.non_field_error %}
{% for error in form.non_field_errors %}
<div class="alert-message error" data-alert>
<a class="close" href="#">×</a>
<p>{{ error }}</p>
</div>
{% endfor %}
{% endif %}
{% endif %}
<h2>Se connecter</h2>
<form method="post" class="form-stacked" id="form_login">
{% csrf_token %}
{% for field in form %}
{% if field.errors %}
<div class="clearfix error">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="input">
{{ field }}
<span class="help-inline">
{% for error in field.errors %}
{{ error }}
{% endfor %}
</span>
</div>
{% else %}
<div class="clearfix">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
<div class="input">
{{ field }}
</div>
</div>
{% endif %}
{% endfor %}
<div class="actions">
<input type="submit" value="Se connecter" class="btn success">
<a href="/forgotten-password" class="btn danger">Mot de passe oublié ?</a>
<a href="/register">Pas encore inscrit ?</a>
</div>
</form>
</div>
{% endblock %}
{% block javascripts %}
<script type="text/javascript" src="{% static 'applipizza/js/bootstrap-alerts.js' %}"></script>
<script type="text/javascript">
var form = $('form');
var formRequiredFields = form.find('input[required]');
var formSubmitButton = form.find('input[type=submit]');
// We disable form validation
form.attr('novalidate', 'novalidate');
form.submit(function (e) {
formRequiredFields.each(function () {
if ($(this).val() == '') {
console.log('empty');
e.preventDefault();
$(this).parent().append('<span class="help-inline">Ce champ est obligatoire</span>');
$(this).parent().parent().addClass('error');
} else {
if ($(this).parent().find('span.help-inline').length > 0) {
$(this).parent().find('span.help-inline').remove();
$(this).parent().parent().removeClass('error');
}
}
});
});
// We disable the submit button
//formSubmitButton.attr('disabled', 'disabled');
</script>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
Lasri Del Arte - Ajouter un ingrédient
{% endblock %}
{% block content %}
<div class="container">
<h2>Ne partez pas si vite !</h2>
<p>Voici 50 % de réduction sur tout ce dont vous n'avez pas besoin ! <a href="/login">Se reconnecter</a></p>
</div>
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import path
from applipizza import views
from django.conf import settings # new
from django.urls import path, include # new
from django.conf.urls.static import static # new
urlpatterns = [
path('admin/', admin.site.urls),
path('login/', auth_views.LoginView.as_view(template_name="login.html"), name="login"),
path('logout/', auth_views.LogoutView.as_view(template_name="logout.html"), name="logout"),
]
from django.shortcuts import render
# Create your views here.
......@@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'applipizza',
'connexion'
]
MIDDLEWARE = [
......@@ -108,7 +109,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'UTC'
......@@ -128,3 +129,4 @@ STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_ROOT = BASE_DIR/'media'
MEDIA_URL = '/media/'
LOGIN_REDIRECT_URL = "home"
\ No newline at end of file
......@@ -21,17 +21,18 @@ from django.conf import settings # new
from django.urls import path, include # new
from django.conf.urls.static import static # new
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import path
from applipizza import views
from django.conf import settings # new
from django.urls import path, include # new
from django.conf.urls.static import static # new
urlpatterns = [
path('admin/', admin.site.urls),
path('pizzas/', views.pizzas),
path('pizza/<int:id>', views.pizza),
path('pizza/<int:id>/addIngredient', views.ajouterIngredientDansPizza),
path('pizza/<int:pizzaId>/deleteIngredient/<int:compositionId>', views.supprimerIngredientDansPizza),
path('pizza/<int:id>/update', views.modifierPizza),
path('pizza/<int:id>/update/post', views.traitementFormulaireModificationPizza),
path('pizza/<int:id>/delete', views.supprimerPizza),
path('ingredients/add', views.formulaireCreationIngredient),
path('ingredients/add/post', views.creerIngredient),
path('', include('connexion.urls')),
path('', include('applipizza.urls'))
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # new
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment