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

taxi form solution #870

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 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,7 +22,25 @@
ManufacturerListView.as_view(),
name="manufacturer-list",
),
path(
"manufacturers/create",
TenbReala marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Consider adding a trailing slash to the 'create' path for manufacturers to align with Django's URL conventions and maintain consistency with the car paths.

ManufacturerCreateView.as_view(),
name="manufacturer-create"
),
path(
"manufacturers/<int:pk>/update",
TenbReala marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Consider adding a trailing slash to the 'update' path for manufacturers to align with Django's URL conventions and maintain consistency with the car paths.

ManufacturerUpdateView.as_view(),
name="manufacturer-update"
),
path(
"manufacturers/<int:pk>/delete",
TenbReala marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Consider adding a trailing slash to the 'delete' path for manufacturers to align with Django's URL conventions and maintain consistency with the car paths.

ManufacturerDeleteView.as_view(),
name="manufacturer-delete"
),
path("cars/", CarListView.as_view(), name="car-list"),
path("cars/create", CarCreateView.as_view(), name="car-create"),
TenbReala marked this conversation as resolved.
Show resolved Hide resolved
path("cars/<int:pk>/update", CarUpdateView.as_view(), name="car-update"),
TenbReala marked this conversation as resolved.
Show resolved Hide resolved
path("cars/<int:pk>/delete", CarDeleteView.as_view(), name="car-delete"),
TenbReala marked this conversation as resolved.
Show resolved Hide resolved
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,6 +35,26 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView):
paginate_by = 5


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


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


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


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


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


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
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_forms",
"crispy_bootstrap4",
]

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"
12 changes: 12 additions & 0 deletions templates/taxi/car_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}

{% block content %}
<h1>Delete car</h1>

<p>Are you sure you want to delete the car: {{ car }}</p>
<form action="" method="post">
TenbReala marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Critical Issue: The action attribute of the form is empty. Ensure it points to the correct URL where the delete action should be processed. You can use Django's URL template tag to dynamically generate the correct URL.

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

{% endblock %}
7 changes: 6 additions & 1 deletion templates/taxi/car_detail.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{% extends "base.html" %}

{% block content %}
<h1>
Car: {{ car.model }}
</h1>
<p>Manufacturer: ({{ car.manufacturer.name }}, {{ car.manufacturer.country }})</p>
<h1>Drivers</h1>
<h2>Drivers</h2>
<hr>
<ul>
{% for driver in car.drivers.all %}
TenbReala marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Critical Issue: The method car.drivers.all should be called with parentheses: car.drivers.all(). This is necessary to execute the method and retrieve the list of drivers.

<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">edit</a>
<a class="btn btn-danger" href="{% url 'taxi:car-delete' pk=car.id %}" role="button">delete</a>
{% endblock %}
11 changes: 11 additions & 0 deletions templates/taxi/car_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}

{% block content %}
<h1> {{ object|yesno:"Update, Create" }} car</h1>
<form action="" method="post">
TenbReala marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Critical Issue: The action attribute of the form is empty. Ensure it points to the correct URL where the form data should be submitted. You can use Django's URL template tag to dynamically generate the correct URL.

{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="{{ object|yesno:"Update, Create" }}" role="button">
</form>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% 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>
{% if car_list %}
<ul>
{% for car in car_list %}
Expand Down
13 changes: 13 additions & 0 deletions templates/taxi/manufacturer_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "base.html" %}

{% block content %}
<h1>Delete manufacturer</h1>

<p>Are you sure you want to delete the manufacturer: {{ manufacturer }}</p>
<p><i>All car with this manufacturer will be also deleted</i></p>
<form action="" method="post">
TenbReala marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Critical Issue: The action attribute of the form is empty. Ensure it points to the correct URL where the delete action should be processed. You can use Django's URL template tag to dynamically generate the correct URL.

{% csrf_token %}
<input class="btn btn-danger" type="submit" value="Yes, delete">
<a class="btn btn-primary" href="{% url 'taxi:car-detail' pk=manufacturer.id %}" role="button">Cancel</a>
TenbReala marked this conversation as resolved.
Show resolved Hide resolved
</form>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/taxi/manufacturer_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}

{% block content %}
<h1>{{ object|yesno:"Update, Create" }} manufacturer</h1>

<form action="" method="post">
TenbReala marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

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

Critical Issue: The action attribute of the form is empty. Ensure it points to the correct URL where the form data should be submitted. You can use Django's URL template tag to dynamically generate the correct URL.

{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="{{ object|yesno:"Update, Create" }}" role="button">
</form>
{% endblock %}
10 changes: 9 additions & 1 deletion templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% extends "base.html" %}

{% block content %}
<h1>Manufacturer List
<h1>
Manufacturer List
<a href="{% url 'taxi:manufacturer-create' %}">Create</a>
</h1>

{% if manufacturer_list %}
Expand All @@ -23,6 +25,12 @@ <h1>Manufacturer List
<td>
{{ manufacturer.country }}
</td>
<td>
<a href="{% url 'taxi:manufacturer-update' pk=manufacturer.id %}">Update</a>
</td>
<td>
<a href="manufacturer_confirm_delete.html">Delete</a>
TenbReala marked this conversation as resolved.
Show resolved Hide resolved
</td>
</tr>
{% endfor %}
</table>
Expand Down
Loading