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 #873

Open
wants to merge 5 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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ 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
18 changes: 18 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
DriverListView,
DriverDetailView,
ManufacturerListView,
CarCreateView,
CarUpdateView,
CarDeleteView,
ManufacturerCreateView,
ManufacturerUpdateView,
ManufacturerDeleteView,
)

urlpatterns = [
Expand All @@ -16,8 +22,20 @@
ManufacturerListView.as_view(),
name="manufacturer-list",
),
path("manufacturers/create/",
ManufacturerCreateView.as_view(),
name="manufacturer-create"),
path("manufacturers/<int:pk>/update/",

Choose a reason for hiding this comment

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

The URL pattern for updating a manufacturer is missing a trailing slash. It should be 'manufacturers/int:pk/update/' to ensure consistency in URL handling.

ManufacturerUpdateView.as_view(),
name="manufacturer-update"),
path("manufacturers/<int:pk>/delete/",
ManufacturerDeleteView.as_view(),
name="manufacturer-delete"),
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"
Expand Down
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 = ["name", "country"]
success_url = reverse_lazy("taxi:manufacturer-list")
template_name = "taxi/manufacturer_list_form.html"

Choose a reason for hiding this comment

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

The template name 'taxi/manufacturer_list_form.html' used in ManufacturerCreateView might be misleading. Consider renaming it to something more descriptive like 'taxi/manufacturer_form.html' to better reflect its purpose as a form for creating or updating manufacturers.

Choose a reason for hiding this comment

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

The template name taxi/manufacturer_list_form.html used in ManufacturerCreateView might be misleading. Consider renaming it to something more descriptive like taxi/manufacturer_form.html to better reflect its purpose.



class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Manufacturer
fields = ["name", "country"]
success_url = reverse_lazy("taxi:manufacturer-list")
template_name = "taxi/manufacturer_list_form.html"

Choose a reason for hiding this comment

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

The template name 'taxi/manufacturer_list_form.html' used in ManufacturerUpdateView might be misleading. Consider renaming it to something more descriptive like 'taxi/manufacturer_form.html' to better reflect its purpose as a form for creating or updating manufacturers.

Choose a reason for hiding this comment

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

The template name taxi/manufacturer_list_form.html used in ManufacturerUpdateView might be misleading. Consider renaming it to something more descriptive like taxi/manufacturer_form.html to better reflect its purpose.



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


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 = ["model", "manufacturer", "drivers"]
success_url = reverse_lazy("taxi:car-list")
template_name = "taxi/car_list_form.html"


class CarUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Car
fields = ["model", "manufacturer", "drivers"]
success_url = reverse_lazy("taxi:car-list")
template_name = "taxi/car_list_form.html"


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


class DriverListView(LoginRequiredMixin, generic.ListView):
model = Driver
paginate_by = 5
Expand Down
4 changes: 4 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_bootstrap4",
"crispy_forms",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -140,3 +142,5 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

CRISPY_TEMPLATE_PACK = "bootstrap4"
10 changes: 10 additions & 0 deletions templates/taxi/car_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block content %}
<h1>Confirm deletion</h1>
<p>Are you sure you want to delete {{ car }}?</p>
<form action="" method="post">

Choose a reason for hiding this comment

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

The action attribute in the form tag is empty. While this will default to the current URL, it's a good practice to explicitly specify the URL for clarity and maintainability. Consider using {% url 'taxi:car-delete' pk=car.id %} to ensure the form submits to the correct endpoint.

Choose a reason for hiding this comment

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

The action attribute in the form tag is empty. While it defaults to the current URL, it's best practice to explicitly specify the URL for clarity and maintainability. Consider using {% url 'taxi:car-delete' pk=car.id %}.

{% csrf_token %}
<input type="submit" value="Yes, delete" class="btn btn-danger">
<a class="btn btn-primary" href="{% url 'taxi:car-detail' pk=car.id %}" role="button">Cancel</a>
</form>
{% endblock %}
2 changes: 2 additions & 0 deletions templates/taxi/car_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ <h1>Drivers</h1>
<li>{{ driver.username }} ({{ driver.first_name }} {{ driver.last_name }})</li>
{% endfor %}
</ul>
<a class="btn btn-warning" href="{% url 'taxi:car-update' pk=car.id %}" role="button">Update</a>
<a class="btn btn-danger" href="{% url 'taxi:car-delete' pk=car.id %}" role="button">Delete</a>
{% endblock %}
31 changes: 21 additions & 10 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
{% extends "base.html" %}

{% block content %}
<h1>Car list</h1>
<h1>Car List</h1>
{% if car_list %}
<ul>
{% for car in car_list %}
<li>
<a href="{% url "taxi:car-detail" pk=car.id %} ">{{ car.id }}</a>
{{ car.model }} ({{ car.manufacturer.name }})
</li>
{% endfor %}
</ul>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Model</th>
<th>Manufacturer</th>
</tr>
</thead>
<tbody>
{% for car in car_list %}
<tr>
<td>{{ car.id }}</td>
<td><a href="{% url 'taxi:car-detail' pk=car.id %}">{{ car.model }}</a></td>
<td>{{ car.manufacturer.name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no cars in taxi</p>
<p>There are no cars in the taxi system.</p>
{% endif %}
<a href="{% url 'taxi:car-create' %}" class="btn btn-primary">Car creation page</a>
{% endblock %}
10 changes: 10 additions & 0 deletions templates/taxi/car_list_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 action="" method="post" novalidate>

Choose a reason for hiding this comment

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

The action attribute in the form tag is empty. While it defaults to the current URL, it's best practice to explicitly specify the URL for clarity and maintainability. Consider setting the action attribute to the appropriate URL for the form's purpose.

{% csrf_token %}
{{ form|crispy }}
<input type="submit" class="btn btn-success" value="Save">
</form>
{% endblock %}
9 changes: 9 additions & 0 deletions templates/taxi/manufacturer_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block content %}
<h1>Confirm deletion</h1>
<p>Are you sure you want to delete {{ manufacturer }}?</p>
<form action="" method="post">

Choose a reason for hiding this comment

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

The action attribute in the form tag is empty. While this will default to the current URL, it's a good practice to explicitly specify the URL for clarity and maintainability. Consider using {% url 'taxi:manufacturer-delete' pk=manufacturer.id %} to ensure the form submits to the correct endpoint.

Choose a reason for hiding this comment

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

The action attribute in the form tag is empty. While it defaults to the current URL, it's best practice to explicitly specify the URL for clarity and maintainability. Consider using {% url 'taxi:manufacturer-delete' pk=manufacturer.id %}.

{% csrf_token %}
<input type="submit" value="Yes, delete" class="btn btn-danger">
</form>

Choose a reason for hiding this comment

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

Consider adding a 'Cancel' button to improve user experience by providing an option to abort the deletion process. This can be done by adding a link back to the manufacturer detail or list page.

{% endblock %}
47 changes: 29 additions & 18 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
{% extends "base.html" %}

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

{% if manufacturer_list %}
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
</tr>

{% for manufacturer in manufacturer_list %}
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for manufacturer in manufacturer_list %}
<tr>
<td>{{ manufacturer.id }}</td>
<td>{{ manufacturer.name }}</td>
<td>{{ manufacturer.country }}</td>
<td>
{{ manufacturer.id }}
</td>
<td>
{{ manufacturer.name }}
<a href="{% url 'taxi:manufacturer-update' pk=manufacturer.id %}" class="btn btn-warning btn-sm">
Update
</a>
</td>
<td>
{{ manufacturer.country }}
<a href="{% url 'taxi:manufacturer-delete' pk=manufacturer.id %}" class="btn btn-danger btn-sm">
Delete
</a>
</td>
</tr>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>

{% else %}
<p>There are no manufacturers in the service.</p>
<p>There are no manufacturers in the service.</p>
{% endif %}

<a href="{% url 'taxi:manufacturer-create' %}" class="btn btn-primary">
Manufacturer creation page
</a>
{% endblock %}
10 changes: 10 additions & 0 deletions templates/taxi/manufacturer_list_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 action="" method="post" novalidate>

Choose a reason for hiding this comment

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

The action attribute in the form tag is empty. While it defaults to the current URL, it's best practice to explicitly specify the URL for clarity and maintainability. Consider setting the action attribute to the appropriate URL for the form's purpose.

{% csrf_token %}
{{ form|crispy }}
<input type="submit" class="btn btn-success" value="Save">
</form>
{% endblock %}
Loading