diff --git a/taxi/urls.py b/taxi/urls.py index c663d6e22..53e4ecee3 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -4,9 +4,15 @@ index, CarListView, CarDetailView, + CarCreateView, + CarUpdateView, + CarDeleteView, DriverListView, DriverDetailView, ManufacturerListView, + ManufacturerCreateView, + ManufacturerUpdateView, + ManufacturerDeleteView, ) urlpatterns = [ @@ -18,7 +24,18 @@ ), 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("manufacturers/", ManufacturerCreateView.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( "drivers//", DriverDetailView.as_view(), name="driver-detail" ), diff --git a/taxi/views.py b/taxi/views.py index 4a99a2cd9..9a766396e 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 = "__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 @@ -44,6 +65,25 @@ class CarDetailView(LoginRequiredMixin, generic.DetailView): model = Car +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") + + +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..830d21a18 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,7 @@ # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4" + +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..806e6a976 --- /dev/null +++ b/templates/taxi/car_confirm_delete.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% block content %} +

Delete Car

+ +

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

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

Create Car

+
+ {% csrf_token %} + {{ form|crispy }} + +
+ +{% endblock %} diff --git a/templates/taxi/car_list.html b/templates/taxi/car_list.html index e107b5797..e7ae79a8c 100644 --- a/templates/taxi/car_list.html +++ b/templates/taxi/car_list.html @@ -1,13 +1,19 @@ {% extends "base.html" %} {% block content %} -

Car list

+

Car list +

{% if car_list %} -
    +
      {% for car in car_list %} -
    • - {{ car.id }} - {{ car.model }} ({{ car.manufacturer.name }}) +
    • +
      + {{ car.id }} + {{ car.model }} ({{ car.manufacturer.name }}) +
      +
      + Update + Delete +
    • {% endfor %}
    diff --git a/templates/taxi/manufacturer_confirm_delete.html b/templates/taxi/manufacturer_confirm_delete.html new file mode 100644 index 000000000..574d3f620 --- /dev/null +++ b/templates/taxi/manufacturer_confirm_delete.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% block content %} +

    Delete Manufacturer

    + +

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

    +
    + {% csrf_token %} + + Cancel +
    + +{% endblock %} diff --git a/templates/taxi/manufacturer_form.html b/templates/taxi/manufacturer_form.html new file mode 100644 index 000000000..a97c90fad --- /dev/null +++ b/templates/taxi/manufacturer_form.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} +{% block content %} +

    Create Manufacturer

    +
    + {% csrf_token %} + {{ form|crispy }} + +
    + +{% endblock %} diff --git a/templates/taxi/manufacturer_list.html b/templates/taxi/manufacturer_list.html index 2a31bcf60..8c564bf54 100644 --- a/templates/taxi/manufacturer_list.html +++ b/templates/taxi/manufacturer_list.html @@ -1,32 +1,34 @@ {% extends "base.html" %} {% block content %} -

    Manufacturer List +

    Manufacturer List +

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

    There are no manufacturers in the service.

    {% endif %}