Commit 0775de66 authored by Bonnegent Sebastien's avatar Bonnegent Sebastien
Browse files

avant cours 2

parent 2ed9c2a5
......@@ -3,3 +3,4 @@ conf/
......@@ -108,16 +108,11 @@ AUTH_PASSWORD_VALIDATORS = [
TIME_ZONE = 'Europe/Paris'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
......@@ -11,7 +11,7 @@ def user_directory_path(instance, filename):
class Garage(models.Model):
nom = models.CharField(max_length=32)
adresse = models.CharField(max_length=128, null=True, blank=True)
mail = models.EmailField(null=True)
mail = models.EmailField(null=True, blank=True)
telephone = models.CharField(max_length=12, null=True, blank=True)
createur = models.ForeignKey(User, on_delete=models.CASCADE)
{% extends "garage/home.html" %}
{% load staticfiles %}
{% block content %}
<h2>Liste des garages <a href="#" class="btn btn-success active" role="button" aria-pressed="true">Ajouter</a></h2>
<table class="table table-striped table-bordered" cellspacing="0">
{% for grg in garages %}
<tr><td>{{ grg.nom }}</td><td>{{ grg.adresse }}</td><td>{{ grg.telephone }}</td></tr>
{% empty %}
<tr><td colspan="3">Aucun garage pour le moment</td></tr>
{% endfor %}
{% endblock %}
......@@ -9,7 +9,7 @@
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="/">Garage</a>
<a class="navbar-brand" href="{% url 'garage:home' %}">Accueil</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup"
aria-expanded="false" aria-label="Toggle navigation">
......@@ -17,17 +17,18 @@
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<ul class="navbar-nav mr-auto">
<li class="nav-item active"><a class="nav-link" href="/">Accueil</a></li>
<li class="nav-item"><a class="nav-item nav-link" href="#">Véhicules</a></li>
<li class="nav-item {{ menu_garages }}"><a class="nav-link" href="{% url 'garage:garages' %}">Garages</a></li>
<li class="nav-item {{ menu_vehicules }}"><a class="nav-item nav-link" href="{% url 'garage:vehicules' %}">Véhicules</a></li>
<li class="nav-item {{ menu_mes_vehicules }}"><a class="nav-item nav-link" href="{% url 'garage:mes_vehicules' %}">Mes véhicules</a></li>
<ul class="navbar-nav navbar-right">
{% if user.is_authenticated %}
{% if user.is_staff %}
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
<li class="nav-item"><a class="nav-link" href="/admin">Admin</a></li>
{% endif %}
<li class="nav-item"><a class="nav-link" href="{% url 'logout' %}">Déconnexion</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'logout' %}">Déconnexion</a></li>
{% else %}
<li class="nav-item"><a class="nav-link" href="{% url 'login' %}">Connexion</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'login' %}">Connexion</a></li>
{% endif %}
from django.urls import path
from . import views
from django.contrib.auth.decorators import login_required
app_name = "garage"
urlpatterns = [
path('', views.home, name='home'),
path('garages/', login_required(views.GaragesListView.as_view()), name='garages'),
path('vehicules/', login_required(views.VehiculesListView.as_view()), name='vehicules'),
path('mes_vehicules/', login_required(views.MesVehiculesListView.as_view()), name='mes_vehicules'),
from django.shortcuts import render
#from .models import Question
from .models import Garage, Vehicule
from django.views.generic import ListView
def home_v1(request):
"""Page d'accueil"""
return HttpResponse('ça marche !')
def home(request):
return render(request, 'garage/home.html', {})
class GaragesListView(ListView):
model = Garage
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['menu_garages'] = 'active'
return context
class VehiculesListView(ListView):
model = Vehicule
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['menu_vehicules'] = 'active'
return context
class MesVehiculesListView(ListView):
model = Vehicule
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['menu_mes_vehicules'] = 'active'
return context
def get_queryset(self):
return Vehicule.objects.filter(proprietaire=self.request.user)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment