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 #449

Open
wants to merge 7 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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
DriverListView,
DriverDetailView,
ManufacturerListView,
ManufacturerCreateView,
ManufacturerUpdateView,
ManufacturerDeleteView,
CarCreateView,
CarUpdateView,
CarDeleteView
)

urlpatterns = [
Expand All @@ -16,6 +22,18 @@
ManufacturerListView.as_view(),
name="manufacturer-list",
),
path("manufacturers/create/",
ManufacturerCreateView.as_view(),
name="manufacturer-create"),
path("manufacturers/update/<int:pk>/",
ManufacturerUpdateView.as_view(),
name="manufacturer-update"),
path("manufacturers/delete/<int:pk>/",
ManufacturerDeleteView.as_view(),
name="manufacturer-delete"),
path("cars/create/", CarCreateView.as_view(), name="car-create"),
path("cars/update/<int:pk>/", CarUpdateView.as_view(), name="car-update"),
path("cars/delete/<int:pk>/", CarDeleteView.as_view(), name="car-delete"),
path("cars/", CarListView.as_view(), name="car-list"),
path("cars/<int:pk>/", CarDetailView.as_view(), name="car-detail"),
path("drivers/", DriverListView.as_view(), name="driver-list"),
Expand Down
35 changes: 35 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,12 +35,46 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView):
paginate_by = 5


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")


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")


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 CarDetailView(LoginRequiredMixin, generic.DetailView):
model = Car

Expand Down
4 changes: 4 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,5 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

CRISPY_TEMPLATE_PACK = "bootstrap4"
9 changes: 9 additions & 0 deletions templates/taxi/car_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block content %}
<h1>Delete car
<a type="button" class="btn btn-outline-success" href="{% url 'taxi:car-list' %}">Cancel</a></h1>
<p>Are you sure you want to delete the car {{ car.model }}?</p>
<form action="" method="post">
{% csrf_token %}
<input type="submit" value="Yes, delete" class="btn btn-outline-danger"></form>
{% endblock %}
2 changes: 2 additions & 0 deletions templates/taxi/car_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ <h1>Drivers</h1>
<li>{{ driver.username }} ({{ driver.first_name }} {{ driver.last_name }})</li>
{% endfor %}
</ul>
<a href="{% url 'taxi:car-update' pk=car.id %}" type="button" class="btn btn-outline-primary">Update</a>
<a href="{% url 'taxi:car-delete' pk=car.id %}" type="button" class="btn btn-outline-danger">Delete</a>
{% 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>{{ object|yesno:"Update,Create" }} car</h1>
<form action="" method="POST" novalidate>
{% csrf_token %}
{{ form|crispy}}
<input class="btn btn-primary" type="submit" value="Submit">
</form>
{% endblock %}
4 changes: 2 additions & 2 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% extends "base.html" %}

{% block content %}
<h1>Car list</h1>
<h1>Car list <a type="button" class="btn btn-outline-success" href="{% url 'taxi:car-create' %}">+</a></h1>
{% if car_list %}
<ul>
{% for car in car_list %}
<li>
<a href="{% url "taxi:car-detail" pk=car.id %} ">{{ car.id }}</a>
<a href="{% url "taxi:car-detail" pk=car.id %}">{{ car.id }}</a>
{{ car.model }} ({{ car.manufacturer.name }})
</li>
{% endfor %}
Expand Down
10 changes: 10 additions & 0 deletions templates/taxi/manufacturer_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block content %}
<h1>Delete manufacturer
<a type="button" class="btn btn-outline-success" href="{% url 'taxi:manufacturer-list' %}">Cancel</a></h1>
<p>Are you sure you want to delete the manufacturer {{ manufacturer.name }}?</p>
<p><i>All cars with this manufacturer will be deleted.</i></p>
<form action="" method="post">
{% csrf_token %}
<input type="button" value="Yes, delete" class="btn btn-outline-danger"></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>{{ object|yesno:"Update,Create" }} manufacturer</h1>
<form action="" method="POST" novalidate>
{% csrf_token %}
{{ form|crispy}}
<input class="btn btn-primary" type="submit" value="Submit">
</form>
{% endblock %}
11 changes: 9 additions & 2 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{% extends "base.html" %}

{% block content %}
<h1>Manufacturer List
</h1>
<h1>Manufacturer List <a type="button" class="btn btn-outline-success" href="{% url 'taxi:manufacturer-create' %}">+</a></h1>

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

{% for manufacturer in manufacturer_list %}
Expand All @@ -23,6 +24,12 @@ <h1>Manufacturer List
<td>
{{ manufacturer.country }}
</td>
<td>
<a type="button" class="btn btn-outline-primary" href="{% url 'taxi:manufacturer-update' pk=manufacturer.id %}">Update</a>
</td>
<td>
<a type="button" class="btn btn-outline-danger" href="{% url 'taxi:manufacturer-delete' pk=manufacturer.id %}">Delete</a>
</td>
</tr>
{% endfor %}
</table>
Expand Down
Loading