diff --git a/requirements.txt b/requirements.txt index 9a8caa10f..ffe375e7a 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 diff --git a/taxi/urls.py b/taxi/urls.py index c663d6e22..c18802ced 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -7,6 +7,12 @@ DriverListView, DriverDetailView, ManufacturerListView, + CarCreateView, + CarUpdateView, + CarDeleteView, + ManufacturerCreateView, + ManufacturerUpdateView, + ManufacturerDeleteView, ) urlpatterns = [ @@ -16,8 +22,20 @@ ManufacturerListView.as_view(), name="manufacturer-list", ), + 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/", CarListView.as_view(), name="car-list"), path("cars//", CarDetailView.as_view(), name="car-detail"), + 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"), path("drivers/", DriverListView.as_view(), name="driver-list"), path( "drivers//", DriverDetailView.as_view(), name="driver-detail" diff --git a/taxi/views.py b/taxi/views.py index 4a99a2cd9..15a750c24 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,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" + + +class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView): + model = Manufacturer + fields = ["name", "country"] + success_url = reverse_lazy("taxi:manufacturer-list") + template_name = "taxi/manufacturer_list_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 @@ -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 diff --git a/taxi_service/settings.py b/taxi_service/settings.py index d89c45643..f9b6a52c8 100644 --- a/taxi_service/settings.py +++ b/taxi_service/settings.py @@ -44,6 +44,8 @@ "django.contrib.staticfiles", "debug_toolbar", "taxi", + "crispy_bootstrap4", + "crispy_forms", ] 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..ba4338b99 --- /dev/null +++ b/templates/taxi/car_confirm_delete.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% block content %} +

Confirm deletion

+

Are you sure you want to delete {{ car }}?

+
+ {% csrf_token %} + + Cancel +
+{% endblock %} diff --git a/templates/taxi/car_detail.html b/templates/taxi/car_detail.html index ffdbe7186..95d069c59 100644 --- a/templates/taxi/car_detail.html +++ b/templates/taxi/car_detail.html @@ -9,4 +9,6 @@

Drivers

  • {{ driver.username }} ({{ driver.first_name }} {{ driver.last_name }})
  • {% endfor %} + Update + Delete {% endblock %} diff --git a/templates/taxi/car_list.html b/templates/taxi/car_list.html index e107b5797..fe9f5b818 100644 --- a/templates/taxi/car_list.html +++ b/templates/taxi/car_list.html @@ -1,17 +1,28 @@ {% extends "base.html" %} {% block content %} -

    Car list

    +

    Car List

    {% if car_list %} -
      - {% for car in car_list %} -
    • - {{ car.id }} - {{ car.model }} ({{ car.manufacturer.name }}) -
    • - {% endfor %} -
    + + + + + + + + + + {% for car in car_list %} + + + + + + {% endfor %} + +
    IDModelManufacturer
    {{ car.id }}{{ car.model }}{{ car.manufacturer.name }}
    {% else %} -

    There are no cars in taxi

    +

    There are no cars in the taxi system.

    {% endif %} + Car creation page {% endblock %} diff --git a/templates/taxi/car_list_form.html b/templates/taxi/car_list_form.html new file mode 100644 index 000000000..e01af500e --- /dev/null +++ b/templates/taxi/car_list_form.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} +{% block content %} +

    {{ object|yesno:"Update,Create" }} Car

    +
    + {% csrf_token %} + {{ form|crispy }} + +
    +{% endblock %} diff --git a/templates/taxi/manufacturer_confirm_delete.html b/templates/taxi/manufacturer_confirm_delete.html new file mode 100644 index 000000000..329841f9a --- /dev/null +++ b/templates/taxi/manufacturer_confirm_delete.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block content %} +

    Confirm deletion

    +

    Are you sure you want to delete {{ manufacturer }}?

    +
    + {% csrf_token %} + +
    +{% endblock %} diff --git a/templates/taxi/manufacturer_list.html b/templates/taxi/manufacturer_list.html index 2a31bcf60..c019b0492 100644 --- a/templates/taxi/manufacturer_list.html +++ b/templates/taxi/manufacturer_list.html @@ -1,33 +1,44 @@ {% extends "base.html" %} {% block content %} -

    Manufacturer List -

    +

    Manufacturer List

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

    There are no manufacturers in the service.

    +

    There are no manufacturers in the service.

    {% endif %} + + + Manufacturer creation page + {% endblock %} diff --git a/templates/taxi/manufacturer_list_form.html b/templates/taxi/manufacturer_list_form.html new file mode 100644 index 000000000..7a53b8a09 --- /dev/null +++ b/templates/taxi/manufacturer_list_form.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} +{% block content %} +

    {{ object|yesno:"Update,Create" }} Manufacturer

    +
    + {% csrf_token %} + {{ form|crispy }} + +
    +{% endblock %}