Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #905

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
django==4.1
flake8==5.0.4
flake8-quotes==3.3.1
flake8-variables-names==0.0.5
pep8-naming==0.13.2
django-debug-toolbar==3.2.4
django-crispy-forms==1.14.0
django==5.1.4
flake8==5.0.4
flake8-quotes==3.3.1
flake8-variables-names==0.0.5
pep8-naming==0.13.2
django-debug-toolbar==3.2.4
django-crispy-forms==1.14.0
crispy-bootstrap4==2022.1
26 changes: 24 additions & 2 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from django.urls import path

from .views import (
index,
CarListView,
CarDetailView,
DriverListView,
DriverDetailView,
ManufacturerListView,
CarCreateView,
ManufacturerCreateView,
CarUpdateView,
ManufacturerUpdateView,
CarDeleteView,
ManufacturerDeleteView,
)

urlpatterns = [
Expand All @@ -16,12 +21,29 @@
ManufacturerListView.as_view(),
name="manufacturer-list",
),
path(
"manufacturers/create/",
ManufacturerCreateView.as_view(),
name="manufacturer-create"
),
path(
"manufacturers/<int:pk>/update/",
ManufacturerUpdateView.as_view(),
name="manufacturer-update"
),
path(
"manufacturers/<int:pk>/delete/",
ManufacturerDeleteView.as_view(),
name="manufacturer-delete"
),
Comment on lines +24 to +38

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no URL pattern for the manufacturer's detail view. Consider adding a path similar to the car detail view to ensure users can navigate to a specific manufacturer's detail page.

path("cars/", CarListView.as_view(), name="car-list"),
path("cars/<int:pk>/", CarDetailView.as_view(), name="car-detail"),
path("cars/create/", CarCreateView.as_view(), name="car-create"),
path("cars/<int:pk>/update/", CarUpdateView.as_view(), name="car-update"),
path("cars/<int:pk>/delete/", CarDeleteView.as_view(), name="car-delete"),
path("drivers/", DriverListView.as_view(), name="driver-list"),
path(
"drivers/<int:pk>/", DriverDetailView.as_view(), name="driver-detail"
),
]

app_name = "taxi"
41 changes: 41 additions & 0 deletions taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views import generic
from django.contrib.auth.mixins import LoginRequiredMixin

Expand Down Expand Up @@ -34,6 +35,26 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView):
paginate_by = 5


class ManufacturerCreateView(LoginRequiredMixin, generic.CreateView):
model = Manufacturer
fields = "__all__"
success_url = reverse_lazy("taxi:manufacturer-list")
template_name = "taxi/manufacturer_form.html"


class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Manufacturer
fields = "__all__"
success_url = reverse_lazy("taxi:manufacturer-list")
template_name = "taxi/manufacturer_form.html"


class ManufacturerDeleteView(LoginRequiredMixin, generic.DeleteView):
model = Manufacturer
success_url = reverse_lazy("taxi:manufacturer-list")
template_name = "taxi/manufacturer_confirm_delete.html"

Comment on lines +38 to +56

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a ManufacturerDetailView similar to CarDetailView to provide a detail view for individual manufacturers. This will complement the existing list, create, update, and delete views for manufacturers.


class CarListView(LoginRequiredMixin, generic.ListView):
model = Car
paginate_by = 5
Expand All @@ -44,6 +65,26 @@ class CarDetailView(LoginRequiredMixin, generic.DetailView):
model = Car


class CarCreateView(LoginRequiredMixin, generic.CreateView):
model = Car
fields = "__all__"
success_url = reverse_lazy("taxi:car-list")
template_name = "taxi/car_form.html"


class CarUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Car
fields = "__all__"
success_url = reverse_lazy("taxi:car-list")
template_name = "taxi/car_form.html"


class CarDeleteView(LoginRequiredMixin, generic.DeleteView):
model = Car
success_url = reverse_lazy("taxi:car-list")
template_name = "taxi/car_confirm_delete.html"


class DriverListView(LoginRequiredMixin, generic.ListView):
model = Driver
paginate_by = 5
Expand Down
18 changes: 18 additions & 0 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"django.contrib.staticfiles",
"debug_toolbar",
"taxi",
"crispy_forms",
"crispy_bootstrap4"
]

MIDDLEWARE = [
Expand Down Expand Up @@ -77,6 +79,20 @@

WSGI_APPLICATION = "taxi_service.wsgi.application"

DEBUG_TOOLBAR_PANELS = [
"debug_toolbar.panels.versions.VersionsPanel",
"debug_toolbar.panels.timer.TimerPanel",
"debug_toolbar.panels.settings.SettingsPanel",
"debug_toolbar.panels.headers.HeadersPanel",
"debug_toolbar.panels.request.RequestPanel",
"debug_toolbar.panels.sql.SQLPanel",
"debug_toolbar.panels.templates.TemplatesPanel",
"debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel",
"debug_toolbar.panels.logging.LoggingPanel",
"debug_toolbar.panels.profiling.ProfilingPanel",
]


# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
Expand Down Expand Up @@ -140,3 +156,5 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

CRISPY_TEMPLATE_PACK = "bootstrap4"
9 changes: 9 additions & 0 deletions templates/taxi/car_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block content %}
<h1>Delete Car</h1>
<p>Are you sure you want to delete this car: {{ car.model }}?</p>
<form method="post" action="">
{% csrf_token %}
<input type="submit" value="Yes, I'm sure" class="btn btn-danger">
</form>
{% endblock %}
10 changes: 10 additions & 0 deletions templates/taxi/car_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<h1>{{ object|yesno:"Update,Create" }} Car</h1>
<form method="post" action="" novalidate>
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Submit">
</form>
{% endblock %}
24 changes: 17 additions & 7 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
{% extends "base.html" %}

{% block content %}
<h1>Car list</h1>
<h1>Car list <a style="float: right" href="{% url "taxi:car-create" %}">+</a></h1>
{% if car_list %}
<ul>
<table class="table table-striped">
<tr>
<th>ID</th>
<th>Model</th>
<th>Manufacturer</th>
<th>Update</th>
<th>Delete</th>
</tr>
{% for car in car_list %}
<li>
<a href="{% url "taxi:car-detail" pk=car.id %} ">{{ car.id }}</a>
{{ car.model }} ({{ car.manufacturer.name }})
</li>
<tr>
<td><a href="{% url "taxi:car-detail" pk=car.id %} ">{{ car.id }}</a></td>
<td>{{ car.model }}</td>
<td>{{ car.manufacturer.name }}</td>
<td><a href="{% url "taxi:car-update" pk=car.id %}">Update</a></td>
<td><a href="{% url "taxi:car-delete" pk=car.id %}">Delete</a></td>
</tr>
{% endfor %}
</ul>
</table>
{% else %}
<p>There are no cars in taxi</p>
{% endif %}
Expand Down
11 changes: 11 additions & 0 deletions templates/taxi/manufacturer_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block content %}
<h1>Delete Manufacturer</h1>

<p>Are you sure you want to delete this manufacturer: {{ manufacturer.name }}?</p>
<p><i>All Cars with this manufacturer will be also delete</i></p>
<form method="post" action="">
{% csrf_token %}
<input type="submit" value="Yes, I'm sure" class="btn btn-danger">
</form>
{% endblock %}
10 changes: 10 additions & 0 deletions templates/taxi/manufacturer_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<h1>{{ object|yesno:"Update,Create" }} Manufacturer</h1>
<form method="post" action="" novalidate>
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Submit">
</form>
{% endblock %}
50 changes: 22 additions & 28 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
{% extends "base.html" %}

{% block content %}
<h1>Manufacturer List
</h1>

{% if manufacturer_list %}
<table class="table">
<h1>Manufacturer List <a style="float: right" href="{% url "taxi:manufacturer-create" %}">+</a></h1>
{% if manufacturer_list %}
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
<th>Update</th>
<th>Delete</th>
</tr>
{% for manufacturer in manufacturer_list %}
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
</tr>

{% for manufacturer in manufacturer_list %}
<tr>
<td>
{{ manufacturer.id }}
</td>
<td>
{{ manufacturer.name }}
</td>
<td>
{{ manufacturer.country }}
</td>
</tr>
{% endfor %}
</table>

{% else %}
<p>There are no manufacturers in the service.</p>
{% endif %}
<td><a href="{% url "taxi:car-detail" pk=manufacturer.id %} ">{{ manufacturer.id }}</a></td>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL {% url "taxi:car-detail" pk=manufacturer.id %} seems incorrect for linking to a manufacturer's detail page. Ensure that the correct URL pattern is used, such as "taxi:manufacturer-detail", if it exists.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL for the manufacturer's detail view is incorrect. It currently uses {% url "taxi:car-detail" pk=manufacturer.id %}. It should likely be {% url "taxi:manufacturer-detail" pk=manufacturer.id %} if such a URL pattern exists.

<td>{{ manufacturer.name }}</td>
<td>{{ manufacturer.country }}</td>
<td><a href="{% url "taxi:manufacturer-update" pk=manufacturer.id %}">Update</a></td>
<td><a href="{% url "taxi:manufacturer-delete" pk=manufacturer.id %}">Delete</a></td>
</tr>
{% endfor %}
</table>
{% else %}
<p>There are no manufacturers in the service.</p>
{% endif %}
{% endblock %}
Loading