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

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

)

urlpatterns = [
Expand All @@ -16,7 +23,16 @@
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"),
path("cars/", CarListView.as_view(), name="car-list"),
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("cars/<int:pk>/", CarDetailView.as_view(), name="car-detail"),
path("drivers/", DriverListView.as_view(), name="driver-list"),
path(
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,12 +35,52 @@ 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
template_name = "taxi/manufacturer_confirm_delete.html"
success_url = reverse_lazy("taxi:manufacturer-list")


class CarListView(LoginRequiredMixin, generic.ListView):
model = Car
paginate_by = 5
queryset = Car.objects.all().select_related("manufacturer")

Choose a reason for hiding this comment

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

The use of select_related is a good practice for optimizing database queries. Ensure that the related fields are correctly specified and necessary for the view to avoid unnecessary data fetching.



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
template_name = "taxi/car_confirm_delete.html"
success_url = reverse_lazy("taxi:car-list")


class CarDetailView(LoginRequiredMixin, generic.DetailView):
model = Car

Expand Down
15 changes: 7 additions & 8 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# Build paths inside the project like this: BASE_DIR / "subdir".
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

Expand Down Expand Up @@ -44,6 +43,7 @@
"django.contrib.staticfiles",
"debug_toolbar",
"taxi",
"crispy_forms",
]

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

WSGI_APPLICATION = "taxi_service.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

Expand All @@ -88,26 +87,25 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators

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

Expand All @@ -126,7 +124,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

Expand All @@ -140,3 +137,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>

Choose a reason for hiding this comment

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

The heading 'Delete Car ' contains an extra space at the end. Consider removing the trailing space for consistency and to maintain a clean appearance.

<form action="" method="post">
{% 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-primary" 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>
Comment on lines +12 to +13

Choose a reason for hiding this comment

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

Ensure there is consistent spacing around the attributes in the <a> tags. There are extra spaces before the href attribute in both buttons. Consider removing these extra spaces for consistency and to adhere to HTML best practices.

{% 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 Form</h1>

Choose a reason for hiding this comment

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

The use of {{ object|yesno:"Update,Create" }} in the heading may not work as intended if object is not defined in the context when creating a new car. Consider using a different approach to dynamically set the heading based on the view context, such as checking if the form instance has a primary key.

<form action="" method="post" novalidate>
{% csrf_token %}
{{ form | crispy }}
<input class="btn btn-primary" type="submit" value="Submit">
</form>
{% endblock %}
30 changes: 21 additions & 9 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
{% extends "base.html" %}

{% block content %}
<h1>Car list</h1>
<h1>Car list <a class="btn btn-primary" style="float: right" href="{% url 'taxi:car-create' %}" role="button">Create</a></h1>

Choose a reason for hiding this comment

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

Ensure there is consistent spacing around the attributes in the <a> tag. There is an extra space before the class attribute. Consider removing this extra space for consistency and to adhere to HTML best practices.

{% 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">
<tr>
<th>ID</th>
<th>Model</th>
<th>Manufacturer</th>
</tr>
{% 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 %}
</table>
{% else %}
<p>There are no cars in taxi</p>
{% endif %}
Expand Down
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>Delete Manufacturer</h1>
<form action="" method="post">
{% 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 the form to allow users to easily navigate back if they decide not to delete the manufacturer. This improves the user experience by providing an easy way to cancel the action.

{% 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 Form</h1>

Choose a reason for hiding this comment

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

The use of {{ object|yesno:"Update,Create" }} in the heading may not work as intended if object is not defined in the context when creating a new manufacturer. Consider using a different approach to dynamically set the heading based on the view context, such as checking if the form instance has a primary key.

<form action="" method="post" novalidate>
{% csrf_token %}
{{ form | crispy }}
<input class="btn btn-primary" type="submit" value="Submit">
</form>
{% endblock %}
12 changes: 9 additions & 3 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}

{% block content %}
<h1>Manufacturer List
<h1>Manufacturer List <a class="btn btn-primary" style="float: right" href="{% url 'taxi:manufacturer-create' %}" role="button">Create</a>

Choose a reason for hiding this comment

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

Ensure there is consistent spacing around the attributes in the <a> tag. There is an extra space before the class attribute. Consider removing this extra space for consistency and to adhere to HTML best practices.

</h1>

{% if manufacturer_list %}
Expand All @@ -10,8 +10,9 @@ <h1>Manufacturer List
<th>ID</th>
<th>Name</th>
<th>Country</th>
<th>Update</th>
<th>Delete</th>
</tr>

{% for manufacturer in manufacturer_list %}
<tr>
<td>
Expand All @@ -23,10 +24,15 @@ <h1>Manufacturer List
<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 %}
Expand Down
Loading