Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution #444

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
django==4.1
Django==4.2.6
flake8==5.0.4
flake8-quotes==3.3.1
flake8-variables-names==0.0.5
pep8-naming==0.13.2
django-debug-toolbar==3.2.4
django-crispy-forms==1.14.0
django-crispy-forms==2.1
crispy-bootstrap4==2023.1
17 changes: 17 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
index,
CarListView,
CarDetailView,
CarCreateView,
CarUpdateView,
CarDeleteView,
DriverListView,
DriverDetailView,
ManufacturerListView,
ManufacturerCreateView,
ManufacturerUpdateView,
ManufacturerDeleteView,
)

urlpatterns = [
Expand All @@ -18,7 +24,18 @@
),
path("cars/", CarListView.as_view(), name="car-list"),
path("cars/<int:pk>/", CarDetailView.as_view(), name="car-detail"),
path("cars/create/", CarCreateView.as_view(), name="car-create"),
path("cars/<int:pk>/update/", CarUpdateView.as_view(), name="car-update"),
path("cars/<int:pk>/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/<int:pk>/update/", ManufacturerUpdateView.as_view(),
name="manufacturer-update"),
path("manufacturers/<int:pk>/delete/", ManufacturerDeleteView.as_view(),
name="manufacturer-delete"),
path(
"drivers/<int:pk>/", DriverDetailView.as_view(), name="driver-detail"
),
Expand Down
40 changes: 40 additions & 0 deletions taxi/views.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"django.contrib.staticfiles",
"debug_toolbar",
"taxi",
"crispy_forms",
"crispy_bootstrap4",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -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"
12 changes: 12 additions & 0 deletions templates/taxi/car_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block content %}
<h1>Delete Car</h1>

<p>Are you sure you want to delete this car: {{ car }}?</p>
<form action="" method="post">
{% csrf_token %}
<input type="submit" value="Yes, Delete" class="btn btn-danger">
<a href="{% url 'taxi:car-list' %}" class="btn btn-secondary"> Cancel</a>
</form>

{% endblock %}
11 changes: 11 additions & 0 deletions templates/taxi/car_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<h1>Create Car</h1>
<form action="" method="post" novalidate>
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Submit">
</form>

{% endblock %}
16 changes: 11 additions & 5 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{% extends "base.html" %}

{% block content %}
<h1>Car list</h1>
<h1>Car list <a style="float: initial" href="{% url 'taxi:car-create' %}">+</a></h1>
{% if car_list %}
<ul>
<ul class="list-group">
{% for car in car_list %}
<li>
<a href="{% url "taxi:car-detail" pk=car.id %} ">{{ car.id }}</a>
{{ car.model }} ({{ car.manufacturer.name }})
<li class="list-group-item d-flex justify-content-between align-items-center">
<div>
<a href="{% url 'taxi:car-detail' pk=car.id %}">{{ car.id }}</a>
{{ car.model }} ({{ car.manufacturer.name }})
</div>
<div>
<a href="{% url 'taxi:car-update' pk=car.id %}" class="btn btn-sm btn-outline-secondary">Update</a>
<a href="{% url 'taxi:car-delete' pk=car.id %}" class="btn btn-sm btn-outline-danger">Delete</a>
</div>
</li>
{% endfor %}
</ul>
Expand Down
12 changes: 12 additions & 0 deletions templates/taxi/manufacturer_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block content %}
<h1>Delete Manufacturer</h1>

<p>Are you sure you want to delete this manufacturer: {{ manufacturer }}?</p>
<form action="" method="post">
{% csrf_token %}
<input type="submit" value="Yes, Delete" class="btn btn-danger">
<a href="{% url 'taxi:manufacturer-list' %}" class="btn btn-secondary"> Cancel</a>
</form>

{% endblock %}
11 changes: 11 additions & 0 deletions templates/taxi/manufacturer_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}
{% block content %}
<h1>Create Manufacturer</h1>
<form action="" method="post" novalidate>
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Submit">
</form>

{% endblock %}
36 changes: 19 additions & 17 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
{% extends "base.html" %}

{% block content %}
<h1>Manufacturer List
<h1>Manufacturer List <a style="float: initial" href="{% url 'taxi:manufacturer-create' %}">+</a>
</h1>

{% if manufacturer_list %}
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
</tr>

{% for manufacturer in manufacturer_list %}
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
</tr>
</thead>
<tbody>
{% for manufacturer in manufacturer_list %}
<tr>
<td>{{ manufacturer.id }}</td>
<td>{{ manufacturer.name }}</td>
<td>{{ manufacturer.country }}</td>
<td>
{{ manufacturer.id }}
</td>
<td>
{{ manufacturer.name }}
<a href="{% url 'taxi:manufacturer-update' pk=manufacturer.id %}" class="btn btn-sm btn-outline-secondary">Update</a>
</td>
<td>
{{ manufacturer.country }}
<a href="{% url 'taxi:manufacturer-delete' pk=manufacturer.id %}" class="btn btn-sm btn-outline-danger">Delete</a>
</td>
</tr>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>

{% else %}
<p>There are no manufacturers in the service.</p>
{% endif %}
Expand Down
Loading