diff --git a/webpizza/applipizza/templates/applipizza/base.html b/webpizza/applipizza/templates/applipizza/base.html index e3f2b1b96eab885764009e8cb12c077dda9276a5..663fbfa4bf7316ff83bd50d8e8f17f696ff3dc5e 100644 --- a/webpizza/applipizza/templates/applipizza/base.html +++ b/webpizza/applipizza/templates/applipizza/base.html @@ -27,12 +27,27 @@ </div> <nav class="navbar"> <ul> - <li class="nav-link active"> - <a href="/pizzas/">Les pizzas</a> - </li> - <li class="nav-link"> - <a href="/ingredients/">Les ingrédients</a> - </li> + {% 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> diff --git a/webpizza/applipizza/templates/applipizza/formulaireCreationPizza.html b/webpizza/applipizza/templates/applipizza/formulaireCreationPizza.html new file mode 100644 index 0000000000000000000000000000000000000000..fc522645713776589551e18bc14292d171eb2e4e --- /dev/null +++ b/webpizza/applipizza/templates/applipizza/formulaireCreationPizza.html @@ -0,0 +1,85 @@ +{% 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 diff --git a/webpizza/applipizza/templates/applipizza/ingredients.html b/webpizza/applipizza/templates/applipizza/ingredients.html new file mode 100644 index 0000000000000000000000000000000000000000..1270f4aa9d87bd1215c382c570b2ad1cec4b41b4 --- /dev/null +++ b/webpizza/applipizza/templates/applipizza/ingredients.html @@ -0,0 +1,38 @@ +{% 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 diff --git a/webpizza/applipizza/urls.py b/webpizza/applipizza/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..f39dac54404392885635d85b6e8aa6110dded38c --- /dev/null +++ b/webpizza/applipizza/urls.py @@ -0,0 +1,21 @@ +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 diff --git a/webpizza/applipizza/views.py b/webpizza/applipizza/views.py index 05a35a42bd8a4c3bd376b455b981f50d9e33863d..ae9f44d2a8200cb138ced67d3de45c0697fe8d2d 100644 --- a/webpizza/applipizza/views.py +++ b/webpizza/applipizza/views.py @@ -1,4 +1,4 @@ -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 @@ -124,4 +124,26 @@ def viewPizza(request, id, status=None): def supprimerIngredientDansPizza(request, pizzaId, compositionId): composition = Composition.objects.get(id=compositionId) composition.delete() - return viewPizza(request, pizzaId, 'success') \ No newline at end of file + 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 diff --git a/webpizza/connexion/__init__.py b/webpizza/connexion/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/webpizza/connexion/admin.py b/webpizza/connexion/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/webpizza/connexion/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/webpizza/connexion/apps.py b/webpizza/connexion/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..a263761cf3551301d30802c8d69b17207ededc2e --- /dev/null +++ b/webpizza/connexion/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ConnexionConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'connexion' diff --git a/webpizza/connexion/migrations/__init__.py b/webpizza/connexion/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/webpizza/connexion/models.py b/webpizza/connexion/models.py new file mode 100644 index 0000000000000000000000000000000000000000..71a836239075aa6e6e4ecb700e9c42c95c022d91 --- /dev/null +++ b/webpizza/connexion/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/webpizza/connexion/templates/base.html b/webpizza/connexion/templates/base.html new file mode 100644 index 0000000000000000000000000000000000000000..245f45f39243fc9a7586f7d8df7ea02e9c703a2b --- /dev/null +++ b/webpizza/connexion/templates/base.html @@ -0,0 +1,71 @@ +{% 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 diff --git a/webpizza/connexion/templates/login.html b/webpizza/connexion/templates/login.html new file mode 100644 index 0000000000000000000000000000000000000000..5a0d4e78cdd2112ed225bc8d76343a4551e40067 --- /dev/null +++ b/webpizza/connexion/templates/login.html @@ -0,0 +1,87 @@ +{% 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 diff --git a/webpizza/connexion/templates/logout.html b/webpizza/connexion/templates/logout.html new file mode 100644 index 0000000000000000000000000000000000000000..38a47758033b9c9370495dd6de62a721d238caf7 --- /dev/null +++ b/webpizza/connexion/templates/logout.html @@ -0,0 +1,14 @@ +{% 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 diff --git a/webpizza/connexion/tests.py b/webpizza/connexion/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/webpizza/connexion/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/webpizza/connexion/urls.py b/webpizza/connexion/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..463e06550d0bb93061ddfe01971d340e9cf690bf --- /dev/null +++ b/webpizza/connexion/urls.py @@ -0,0 +1,13 @@ +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"), +] diff --git a/webpizza/connexion/views.py b/webpizza/connexion/views.py new file mode 100644 index 0000000000000000000000000000000000000000..91ea44a218fbd2f408430959283f0419c921093e --- /dev/null +++ b/webpizza/connexion/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/webpizza/webpizza/settings.py b/webpizza/webpizza/settings.py index 51b5d88970d84629319c67fdf83485a2a3c07f8a..757e1c164d02da7b47a641b1e82a2d40d6e85f23 100644 --- a/webpizza/webpizza/settings.py +++ b/webpizza/webpizza/settings.py @@ -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' @@ -127,4 +128,5 @@ STATIC_URL = 'static/' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' MEDIA_ROOT = BASE_DIR/'media' -MEDIA_URL = '/media/' \ No newline at end of file +MEDIA_URL = '/media/' +LOGIN_REDIRECT_URL = "home" \ No newline at end of file diff --git a/webpizza/webpizza/urls.py b/webpizza/webpizza/urls.py index 7c7f5e4595ba0fe3563faa5cdcea167cfaa0aec6..dc21fc6995918f792b33c28d442b8da263b2f5f4 100644 --- a/webpizza/webpizza/urls.py +++ b/webpizza/webpizza/urls.py @@ -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 +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # new \ No newline at end of file