From 082af9948db2a00898b692e76d6ba4e5aa65d46f Mon Sep 17 00:00:00 2001 From: Yuliia Dudych Date: Thu, 5 Dec 2024 13:39:22 +0200 Subject: [PATCH 1/2] Solution --- taxi/urls.py | 21 +++++++ taxi/views.py | 35 +++++++++++ taxi_service/settings.py | 4 ++ templates/taxi/car_confirm_delete.html | 15 +++++ templates/taxi/car_detail.html | 4 ++ templates/taxi/car_form.html | 12 ++++ templates/taxi/car_list.html | 3 + .../taxi/manufacturer_confirm_delete.html | 16 +++++ templates/taxi/manufacturer_form.html | 12 ++++ templates/taxi/manufacturer_list.html | 59 +++++++++++-------- 10 files changed, 156 insertions(+), 25 deletions(-) create mode 100644 templates/taxi/car_confirm_delete.html create mode 100644 templates/taxi/car_form.html create mode 100644 templates/taxi/manufacturer_confirm_delete.html create mode 100644 templates/taxi/manufacturer_form.html diff --git a/taxi/urls.py b/taxi/urls.py index c663d6e22..7176d222e 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -7,6 +7,9 @@ DriverListView, DriverDetailView, ManufacturerListView, + ManufacturerCreateView, + ManufacturerUpdateView, + ManufacturerDeleteView, CarCreateView, CarUpdateView, CarDeleteView, ) urlpatterns = [ @@ -22,6 +25,24 @@ path( "drivers//", DriverDetailView.as_view(), name="driver-detail" ), + path( + "manufacturers/create/", + ManufacturerCreateView.as_view(), + name="manufacturer-create" + ), + path( + "manufacturers//update/", + ManufacturerUpdateView.as_view(), + name="manufacturer-update" + ), + path( + "manufacturers//delete/", + ManufacturerDeleteView.as_view(), + name="manufacturer-delete" + ), + path("cars/create/", CarCreateView.as_view(), name="car-create"), + path("cars//update/", CarUpdateView.as_view(), name="car-update"), + path("cars//delete/", CarDeleteView.as_view(), name="car-delete"), ] app_name = "taxi" diff --git a/taxi/views.py b/taxi/views.py index 4a99a2cd9..0789d616e 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -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 @@ -34,6 +35,23 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView): paginate_by = 5 +class ManufacturerCreateView(LoginRequiredMixin, generic.CreateView): + model = Manufacturer + fields = "__all__" + success_url = reverse_lazy("taxi:manufacturer-list") + + +class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView): + model = Manufacturer + fields = "__all__" + success_url = reverse_lazy("taxi:manufacturer-list") + + +class ManufacturerDeleteView(LoginRequiredMixin, generic.DeleteView): + model = Manufacturer + success_url = reverse_lazy("taxi:manufacturer-list") + + class CarListView(LoginRequiredMixin, generic.ListView): model = Car paginate_by = 5 @@ -44,6 +62,23 @@ class CarDetailView(LoginRequiredMixin, generic.DetailView): model = Car +class CarCreateView(LoginRequiredMixin, generic.CreateView): + model = Car + fields = "__all__" + success_url = reverse_lazy("taxi:car-list") + + +class CarUpdateView(LoginRequiredMixin, generic.UpdateView): + model = Car + fields = "__all__" + success_url = reverse_lazy("taxi:car-list") + + +class CarDeleteView(LoginRequiredMixin, generic.DeleteView): + model = Car + success_url = reverse_lazy("taxi:car-list") + + class DriverListView(LoginRequiredMixin, generic.ListView): model = Driver paginate_by = 5 diff --git a/taxi_service/settings.py b/taxi_service/settings.py index d89c45643..0f1b2e483 100644 --- a/taxi_service/settings.py +++ b/taxi_service/settings.py @@ -44,6 +44,8 @@ "django.contrib.staticfiles", "debug_toolbar", "taxi", + "crispy_forms", + "crispy_bootstrap4", ] MIDDLEWARE = [ @@ -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" diff --git a/templates/taxi/car_confirm_delete.html b/templates/taxi/car_confirm_delete.html new file mode 100644 index 000000000..5d2cc7caa --- /dev/null +++ b/templates/taxi/car_confirm_delete.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} + +{% block content %} +

Delete a car: {{ car }}

+
+
Are you sure you want to delete this car?
+
+
+ {% csrf_token %} + {{ form|crispy }} + + Cancel +
+{% endblock %} \ No newline at end of file diff --git a/templates/taxi/car_detail.html b/templates/taxi/car_detail.html index ffdbe7186..de30e9157 100644 --- a/templates/taxi/car_detail.html +++ b/templates/taxi/car_detail.html @@ -1,6 +1,10 @@ {% extends "base.html" %} {% block content %} +

+ Edit this car + Delete this car +

Manufacturer: ({{ car.manufacturer.name }}, {{ car.manufacturer.country }})

Drivers


diff --git a/templates/taxi/car_form.html b/templates/taxi/car_form.html new file mode 100644 index 000000000..0cd7d7bcc --- /dev/null +++ b/templates/taxi/car_form.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} + +{% block content %} +

{{ object|yesno:"Edit,Add" }} a car:

+
+ {% csrf_token %} + {{ form|crispy }} + + Cancel +
+{% endblock %} \ No newline at end of file diff --git a/templates/taxi/car_list.html b/templates/taxi/car_list.html index e107b5797..65d36c9e9 100644 --- a/templates/taxi/car_list.html +++ b/templates/taxi/car_list.html @@ -2,6 +2,9 @@ {% block content %}

Car list

+

+ Add a car +

{% if car_list %}
    {% for car in car_list %} diff --git a/templates/taxi/manufacturer_confirm_delete.html b/templates/taxi/manufacturer_confirm_delete.html new file mode 100644 index 000000000..361b8dc1c --- /dev/null +++ b/templates/taxi/manufacturer_confirm_delete.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} + +{% block content %} +

    Delete a manufacturer: {{ manufacturer }}

    +
    Deleting this manufacturer will delete all cars produced by it!
    +
    +
    Are you sure you want to delete this manufacturer?
    +
    +
    + {% csrf_token %} + {{ form|crispy }} + + Cancel +
    +{% endblock %} \ No newline at end of file diff --git a/templates/taxi/manufacturer_form.html b/templates/taxi/manufacturer_form.html new file mode 100644 index 000000000..4125c1a6f --- /dev/null +++ b/templates/taxi/manufacturer_form.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} + +{% block content %} +

    {{ object|yesno:"Edit,Add" }} a manufacturer:

    +
    + {% csrf_token %} + {{ form|crispy }} + + Cancel +
    +{% endblock %} \ No newline at end of file diff --git a/templates/taxi/manufacturer_list.html b/templates/taxi/manufacturer_list.html index 2a31bcf60..57c4e2df6 100644 --- a/templates/taxi/manufacturer_list.html +++ b/templates/taxi/manufacturer_list.html @@ -1,33 +1,42 @@ {% extends "base.html" %} {% block content %} -

    Manufacturer List -

    +

    Manufacturer List

    +

    + Add a manufacturer +

    + {% if manufacturer_list %} + + + + + + + + - {% if manufacturer_list %} -
    IDNameCountryUpdateDelete
    + {% for manufacturer in manufacturer_list %} - - - + + + + + + {% endfor %} +
    IDNameCountry + {{ manufacturer.id }} + + {{ manufacturer.name }} + + {{ manufacturer.country }} + + Update + + Delete +
    - {% for manufacturer in manufacturer_list %} - - - {{ manufacturer.id }} - - - {{ manufacturer.name }} - - - {{ manufacturer.country }} - - - {% endfor %} - - - {% else %} -

    There are no manufacturers in the service.

    - {% endif %} + {% else %} +

    There are no manufacturers in the service.

    + {% endif %} {% endblock %} From 75988146afe1ca2f0be791d348781496d232b6bd Mon Sep 17 00:00:00 2001 From: Yuliia Dudych Date: Thu, 5 Dec 2024 13:59:05 +0200 Subject: [PATCH 2/2] Solution --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 9a8caa10f..72105177c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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>=4.0.0