Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
dpiuro committed Sep 10, 2024
2 parents 86fe627 + 9ec6aba commit b882ccb
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 13 deletions.
Binary file modified db.sqlite3
Binary file not shown.
5 changes: 5 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django.contrib.auth import views as auth_views
from django.urls import path

from . import views

from .views import (
index,
CarListView,
Expand All @@ -18,6 +21,8 @@
),
path("cars/", CarListView.as_view(), name="car-list"),
path("cars/<int:pk>/", CarDetailView.as_view(), name="car-detail"),
path("login/", auth_views.LoginView.as_view(), name="login"),
path("logout/", auth_views.LogoutView.as_view(), name="logout"),
path("drivers/", DriverListView.as_view(), name="driver-list"),
path(
"drivers/<int:pk>/", DriverDetailView.as_view(), name="driver-detail"
Expand Down
19 changes: 17 additions & 2 deletions taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
<<<<<<< HEAD
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.decorators import method_decorator
=======
from django.contrib.auth.mixins import LoginRequiredMixin
>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
from django.shortcuts import render
from django.views import generic
from django.contrib.auth.decorators import login_required

from .models import Driver, Car, Manufacturer


@login_required
def index(request):
<<<<<<< HEAD
if "num_visits" not in request.session:
request.session["num_visits"] = 0

request.session["num_visits"] += 1

=======
>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
num_drivers = Driver.objects.count()
num_cars = Car.objects.count()
num_manufacturers = Manufacturer.objects.count()

num_visits = request.session.get("num_visits", 0)
request.session["num_visits"] = num_visits + 1

context = {
"num_drivers": num_drivers,
"num_cars": num_cars,
"num_manufacturers": num_manufacturers,
<<<<<<< HEAD
"num_visits": request.session["num_visits"],
=======
"num_visits": num_visits,
>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
}

return render(request, "taxi/index.html", context=context)
return render(request, "taxi/index.html", context)


class ManufacturerListView(LoginRequiredMixin, generic.ListView):
Expand All @@ -38,7 +53,7 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView):
class CarListView(LoginRequiredMixin, generic.ListView):
model = Car
paginate_by = 5
queryset = Car.objects.select_related("manufacturer")
queryset = Car.objects.select_related("manufacturer").order_by("id")


class CarDetailView(LoginRequiredMixin, generic.DetailView):
Expand Down
32 changes: 23 additions & 9 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"django-insecure-8ovil3xu6=eaoqd#-#&ricv159p0pypoh5_lgm*)-dfcjqe=yc"
)

# SECURITY WARNING: don"t run with debug turned on in production!
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
Expand Down Expand Up @@ -90,20 +90,28 @@

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation."
"UserAttributeSimilarityValidator",
"NAME": (
"django.contrib.auth.password_validation."
"UserAttributeSimilarityValidator"
),
},
{
"NAME": "django.contrib.auth.password_validation."
"MinimumLengthValidator",
"NAME": (
"django.contrib.auth.password_validation."
"MinimumLengthValidator"
),
},
{
"NAME": "django.contrib.auth.password_validation."
"CommonPasswordValidator",
"NAME": (
"django.contrib.auth.password_validation."
"CommonPasswordValidator"
),
},
{
"NAME": "django.contrib.auth.password_validation."
"NumericPasswordValidator",
"NAME": (
"django.contrib.auth.password_validation."
"NumericPasswordValidator"
),
},
]

Expand Down Expand Up @@ -137,6 +145,12 @@

LOGIN_REDIRECT_URL = "/"

<<<<<<< HEAD
LOGOUT_REDIRECT_URL = "/login/"

LOGIN_URL = "/login/"
=======
LOGOUT_REDIRECT_URL = "/"

SESSION_ENGINE = "django.contrib.sessions.backends.db"
>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
27 changes: 26 additions & 1 deletion taxi_service/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
<<<<<<< HEAD
=======
"""taxi_service URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path("", views.home, name="home")
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path("", Home.as_view(), name="home")
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path("blog/", include("blog.urls"))
"""

>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views


urlpatterns = [
path("admin/", admin.site.urls),
path("accounts/login/", auth_views.LoginView.as_view(), name="login"),
path("accounts/logout/", auth_views.LogoutView.as_view(), name="logout"),
path("", include("taxi.urls", namespace="taxi")),
<<<<<<< HEAD
path("login/", auth_views.LoginView.as_view(), name="login"),
path("logout/", auth_views.LogoutView.as_view(), name="logout"),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
=======
]
>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
1 change: 0 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">
<!-- Add additional CSS in static file -->
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
Expand Down
18 changes: 18 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
<ul class="sidebar-nav">
{% if user.is_authenticated %}
<li>User: <a href="{% url 'taxi:driver-detail' user.pk %}">{{ user.username }}</a></li>
Expand All @@ -11,3 +12,20 @@
<li><a href="{% url "taxi:car-list" %}">Cars</a></li>
<li><a href="{% url "taxi:driver-list" %}">Drivers</a></li>
</ul>
=======
<div class="sidebar">
<ul>
<li><a href="{% url 'taxi:index' %}">Home page</a></li>
<li><a href="{% url 'taxi:manufacturer-list' %}">Manufacturers</a></li>
<li><a href="{% url 'taxi:car-list' %}">Cars</a></li>
<li><a href="{% url 'taxi:driver-list' %}">Drivers</a></li>
</ul>

{% if user.is_authenticated %}
<p>Logged in as <strong>{{ user.username }}</strong></p>
<a href="{% url 'taxi:logout' %}">Logout</a>
{% else %}
<a href="{% url 'taxi:login' %}">Login</a>
{% endif %}
</div>
>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
10 changes: 10 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div>
<h2>Dynamic content</h2>
<p>The Taxi service has the following record counts:</p>
<ul>
<li>Cars: {{ num_cars }}</li>
<li>Drivers: {{ num_drivers }}</li>
<li>Manufacturers: {{ num_manufacturers }}</li>
</ul>
<p>You have visited this page {{ num_visits }} time{{ num_visits|pluralize }}.</p>
</div>
Empty file.
18 changes: 18 additions & 0 deletions templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
{% extends "base.html" %}

{% block content %}
Expand All @@ -8,3 +9,20 @@ <h2>Login</h2>
<button type="submit">Login</button>
</form>
{% endblock %}
=======
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
</body>
</html>
>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
18 changes: 18 additions & 0 deletions templates/taxi/driver_list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "base.html" %}

{% block content %}
<<<<<<< HEAD
<h1>Drivers</h1>
<ul>
{% for driver in object_list %}
Expand All @@ -14,4 +15,21 @@ <h1>Drivers</h1>
</li>
{% endfor %}
</ul>
=======
<h1>Driver list</h1>
<ul>
{% for driver in object_list %}
<li>
<a href="{% url 'taxi:driver-detail' pk=driver.id %}">{{ driver.username }}</a>
({{ driver.first_name }} {{ driver.last_name }})
{% if driver == user %}
(Me)
{% endif %}
</li>
{% endfor %}
</ul>
{% if not object_list %}
<p>There are no drivers in taxi</p>
{% endif %}
>>>>>>> 9ec6aba500bb01d17ec55bca21b477b65d9d5c38
{% endblock %}

0 comments on commit b882ccb

Please sign in to comment.