diff --git a/requirements.txt b/requirements.txt index 9a8caa10f..3ce416a06 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..1061d98dd 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -7,8 +7,14 @@ DriverListView, DriverDetailView, ManufacturerListView, + ManufacturerCreateView, + ManufacturerUpdateView, + ManufacturerDeleteView, + CarCreateView, + CarUpdateView, CarDeleteView, ) + urlpatterns = [ path("", index, name="index"), path( @@ -22,6 +28,15 @@ 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..1cb22c4d5 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 @@ -52,3 +53,37 @@ class DriverListView(LoginRequiredMixin, generic.ListView): class DriverDetailView(LoginRequiredMixin, generic.DetailView): model = Driver queryset = Driver.objects.all().prefetch_related("cars__manufacturer") + + +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 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") 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_detail.html b/templates/taxi/car_detail.html index ffdbe7186..b99f2c6a0 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 %} + Delete car + Update car {% endblock %} diff --git a/templates/taxi/car_form.html b/templates/taxi/car_form.html new file mode 100644 index 000000000..f107a2a6d --- /dev/null +++ b/templates/taxi/car_form.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} +{% load crispy_forms_filters %} + +{% block content %} +

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

    +
    + {% csrf_token %} + {{ form|crispy }} + +
    +{% endblock %} diff --git a/templates/taxi/car_list.html b/templates/taxi/car_list.html index e107b5797..8abd224dd 100644 --- a/templates/taxi/car_list.html +++ b/templates/taxi/car_list.html @@ -2,6 +2,7 @@ {% block content %}

    Car list

    + Add car {% if car_list %}
      {% for car in car_list %} diff --git a/templates/taxi/manufacturer_form.html b/templates/taxi/manufacturer_form.html new file mode 100644 index 000000000..8bb1ba991 --- /dev/null +++ b/templates/taxi/manufacturer_form.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} +{% load crispy_forms_filters %} + +{% block content %} +

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

      +
      + {% csrf_token %} + {{ form|crispy }} + +
      +{% endblock %} diff --git a/templates/taxi/manufacturer_list.html b/templates/taxi/manufacturer_list.html index 2a31bcf60..204f252f0 100644 --- a/templates/taxi/manufacturer_list.html +++ b/templates/taxi/manufacturer_list.html @@ -10,7 +10,9 @@

      Manufacturer List ID Name Country - + Update + Delete + {% for manufacturer in manufacturer_list %} @@ -23,6 +25,12 @@

      Manufacturer List {{ manufacturer.country }} + + Update + + + Delete + {% endfor %}