From bc07757a7333dbeebbb64691bb699c12958a65f9 Mon Sep 17 00:00:00 2001 From: Olha Stadnik Date: Sat, 23 Nov 2024 21:40:06 +0200 Subject: [PATCH 1/4] solution --- taxi/urls.py | 16 ++++++++ taxi/views.py | 41 +++++++++++++++++++ taxi_service/settings.py | 16 ++++---- templates/taxi/car_confirm_delete.html | 9 ++++ templates/taxi/car_detail.html | 2 + templates/taxi/car_form.html | 10 +++++ templates/taxi/car_list.html | 30 ++++++++++---- .../taxi/manufacturer_confirm_delete.html | 9 ++++ templates/taxi/manufacturer_form.html | 10 +++++ templates/taxi/manufacturer_list.html | 12 ++++-- 10 files changed, 135 insertions(+), 20 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..6a9e94329 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -7,6 +7,13 @@ DriverListView, DriverDetailView, ManufacturerListView, + ManufacturerCreateView, + CarCreateView, + ManufacturerUpdateView, + CarUpdateView, + ManufacturerDeleteView, + CarDeleteView, + ) urlpatterns = [ @@ -16,7 +23,16 @@ 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/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("cars//", CarDetailView.as_view(), name="car-detail"), path("drivers/", DriverListView.as_view(), name="driver-list"), path( diff --git a/taxi/views.py b/taxi/views.py index 4a99a2cd9..38d33805a 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,12 +35,52 @@ 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 queryset = Car.objects.all().select_related("manufacturer") +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") + template_name = "taxi/car_form.html" + + +class CarDeleteView(LoginRequiredMixin, generic.DeleteView): + model = Car + template_name = "taxi/car_confirm_delete.html" + success_url = reverse_lazy("taxi:car-list") + + class CarDetailView(LoginRequiredMixin, generic.DetailView): model = Car diff --git a/taxi_service/settings.py b/taxi_service/settings.py index d89c45643..1f2e9220d 100644 --- a/taxi_service/settings.py +++ b/taxi_service/settings.py @@ -15,7 +15,6 @@ # Build paths inside the project like this: BASE_DIR / "subdir". BASE_DIR = Path(__file__).resolve().parent.parent - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ @@ -44,6 +43,8 @@ "django.contrib.staticfiles", "debug_toolbar", "taxi", + "crispy_forms", + "crispy_bootstrap4", ] MIDDLEWARE = [ @@ -77,7 +78,6 @@ WSGI_APPLICATION = "taxi_service.wsgi.application" - # Database # https://docs.djangoproject.com/en/4.0/ref/settings/#databases @@ -88,26 +88,25 @@ } } - # Password validation # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { "NAME": "django.contrib.auth.password_validation." - "UserAttributeSimilarityValidator", + "UserAttributeSimilarityValidator", }, { "NAME": "django.contrib.auth.password_validation." - "MinimumLengthValidator", + "MinimumLengthValidator", }, { "NAME": "django.contrib.auth.password_validation." - "CommonPasswordValidator", + "CommonPasswordValidator", }, { "NAME": "django.contrib.auth.password_validation." - "NumericPasswordValidator", + "NumericPasswordValidator", }, ] @@ -126,7 +125,6 @@ USE_TZ = True - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.0/howto/static-files/ @@ -140,3 +138,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..341959012 --- /dev/null +++ b/templates/taxi/car_confirm_delete.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block content %} +

Delete Car Format

+
+ {% csrf_token %} + + Cancel +
+{% endblock %} \ No newline at end of file diff --git a/templates/taxi/car_detail.html b/templates/taxi/car_detail.html index ffdbe7186..0426ff5d4 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_form.html b/templates/taxi/car_form.html new file mode 100644 index 000000000..5d3561496 --- /dev/null +++ b/templates/taxi/car_form.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} +{% block content %} +

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

    +
    + {% csrf_token %} + {{ form | crispy }} + +
    +{% endblock %} \ No newline at end of file diff --git a/templates/taxi/car_list.html b/templates/taxi/car_list.html index e107b5797..350045573 100644 --- a/templates/taxi/car_list.html +++ b/templates/taxi/car_list.html @@ -1,16 +1,28 @@ {% extends "base.html" %} {% block content %} -

    Car list

    +

    Car list Create

    {% 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

    {% endif %} diff --git a/templates/taxi/manufacturer_confirm_delete.html b/templates/taxi/manufacturer_confirm_delete.html new file mode 100644 index 000000000..da1ad8d05 --- /dev/null +++ b/templates/taxi/manufacturer_confirm_delete.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} + +{% block content %} +

    Delete Manufacturer Format

    +
    + {% csrf_token %} + +
    +{% 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..fb356719e --- /dev/null +++ b/templates/taxi/manufacturer_form.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} +{% block content %} +

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

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

    Manufacturer List +

    Manufacturer List Create

    {% if manufacturer_list %} @@ -10,8 +10,9 @@

    Manufacturer List ID Name Country + Update + Delete - {% for manufacturer in manufacturer_list %} @@ -23,10 +24,15 @@

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

    There are no manufacturers in the service.

    {% endif %} From 6565f8224e063eaa0e92f0ea989bc29048090fa2 Mon Sep 17 00:00:00 2001 From: Olha Stadnik Date: Sat, 23 Nov 2024 21:52:56 +0200 Subject: [PATCH 2/4] solution --- requirements.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9a8caa10f..98fa9d51a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,14 @@ -django==4.1 +asgiref==3.8.1 +crispy-bootstrap4==2024.10 +Django==4.1 +django-crispy-forms==1.14.0 +django-debug-toolbar==3.2.4 flake8==5.0.4 flake8-quotes==3.3.1 flake8-variables-names==0.0.5 +mccabe==0.7.0 pep8-naming==0.13.2 -django-debug-toolbar==3.2.4 -django-crispy-forms==1.14.0 +pycodestyle==2.9.1 +pyflakes==2.5.0 +sqlparse==0.5.2 +tzdata==2024.2 From 726cba7b8a1577266d7d0f33d44f9b05b614d112 Mon Sep 17 00:00:00 2001 From: Olha Stadnik Date: Sat, 23 Nov 2024 21:59:39 +0200 Subject: [PATCH 3/4] solution --- requirements.txt | 13 +++---------- taxi_service/settings.py | 1 - 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index 98fa9d51a..9a8caa10f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,7 @@ -asgiref==3.8.1 -crispy-bootstrap4==2024.10 -Django==4.1 -django-crispy-forms==1.14.0 -django-debug-toolbar==3.2.4 +django==4.1 flake8==5.0.4 flake8-quotes==3.3.1 flake8-variables-names==0.0.5 -mccabe==0.7.0 pep8-naming==0.13.2 -pycodestyle==2.9.1 -pyflakes==2.5.0 -sqlparse==0.5.2 -tzdata==2024.2 +django-debug-toolbar==3.2.4 +django-crispy-forms==1.14.0 diff --git a/taxi_service/settings.py b/taxi_service/settings.py index 1f2e9220d..32c0ff2de 100644 --- a/taxi_service/settings.py +++ b/taxi_service/settings.py @@ -44,7 +44,6 @@ "debug_toolbar", "taxi", "crispy_forms", - "crispy_bootstrap4", ] MIDDLEWARE = [ From 2cf238ef688662667710f536c2d5daace84940e2 Mon Sep 17 00:00:00 2001 From: Olha Stadnik Date: Sun, 24 Nov 2024 12:47:30 +0200 Subject: [PATCH 4/4] solution --- templates/taxi/car_confirm_delete.html | 2 +- templates/taxi/car_form.html | 2 +- templates/taxi/manufacturer_confirm_delete.html | 2 +- templates/taxi/manufacturer_form.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/taxi/car_confirm_delete.html b/templates/taxi/car_confirm_delete.html index 341959012..716544214 100644 --- a/templates/taxi/car_confirm_delete.html +++ b/templates/taxi/car_confirm_delete.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% block content %} -

    Delete Car Format

    +

    Delete Car

    {% csrf_token %} diff --git a/templates/taxi/car_form.html b/templates/taxi/car_form.html index 5d3561496..e9d5986a5 100644 --- a/templates/taxi/car_form.html +++ b/templates/taxi/car_form.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load crispy_forms_filters %} {% block content %} -

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

    +

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

    {% csrf_token %} {{ form | crispy }} diff --git a/templates/taxi/manufacturer_confirm_delete.html b/templates/taxi/manufacturer_confirm_delete.html index da1ad8d05..68e4c8317 100644 --- a/templates/taxi/manufacturer_confirm_delete.html +++ b/templates/taxi/manufacturer_confirm_delete.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block content %} -

    Delete Manufacturer Format

    +

    Delete Manufacturer

    {% csrf_token %} diff --git a/templates/taxi/manufacturer_form.html b/templates/taxi/manufacturer_form.html index fb356719e..7665f461c 100644 --- a/templates/taxi/manufacturer_form.html +++ b/templates/taxi/manufacturer_form.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load crispy_forms_filters %} {% block content %} -

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

    +

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

    {% csrf_token %} {{ form | crispy }}