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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
DriverListView,
DriverDetailView,
ManufacturerListView,
ManufacturerCreateView,
ManufacturerUpdateView,
ManufacturerDeleteView, CarCreateView, CarUpdateView, CarDeleteView,
)

urlpatterns = [
Expand All @@ -22,6 +25,24 @@
path(
"drivers/<int:pk>/", DriverDetailView.as_view(), name="driver-detail"
),
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("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"),
]

app_name = "taxi"
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,6 +35,23 @@ 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
Expand All @@ -44,6 +62,23 @@ class CarDetailView(LoginRequiredMixin, generic.DetailView):
model = Car


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 DriverListView(LoginRequiredMixin, generic.ListView):
model = Driver
paginate_by = 5
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"
15 changes: 15 additions & 0 deletions templates/taxi/car_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}

{% block content %}
<h3>Delete a car: <strong>{{ car }}</strong></h3>
<br>
<h6>Are you sure you want to delete this car?</h6>
<br>
<form action="" method="post" novalidate>
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Delete">
<a class="btn btn-primary" href="{% url 'taxi:car-list' %}">Cancel</a>
</form>
{% endblock %}
4 changes: 4 additions & 0 deletions templates/taxi/car_detail.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends "base.html" %}

{% block content %}
<p>
<a class="btn btn-primary" href="{% url 'taxi:car-update' pk=car.pk %}">Edit this car</a>
<a class="btn btn-primary" href="{% url 'taxi:car-delete' pk=car.pk %}">Delete this car</a>
</p>
<p>Manufacturer: ({{ car.manufacturer.name }}, {{ car.manufacturer.country }})</p>
<h1>Drivers</h1>
<hr>
Expand Down
12 changes: 12 additions & 0 deletions templates/taxi/car_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}

{% block content %}
<h1>{{ object|yesno:"Edit,Add" }} a car:</h1>
<form action="" method="post" novalidate>
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="{{ object|yesno:"Submit,Add" }}">
<a class="btn btn-primary" href="{% url 'taxi:car-list' %}">Cancel</a>
</form>
{% endblock %}
3 changes: 3 additions & 0 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

{% block content %}
<h1>Car list</h1>
<p>
<a class="btn btn-primary" href="{% url 'taxi:car-create' %}">Add a car</a>
</p>
{% if car_list %}
<ul>
{% for car in car_list %}
Expand Down
16 changes: 16 additions & 0 deletions templates/taxi/manufacturer_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}

{% block content %}
<h3>Delete a manufacturer: <strong>{{ manufacturer }}</strong></h3>
<h6 style="color:red">Deleting this manufacturer will delete all cars produced by it!</h6>
<br>
<h6>Are you sure you want to delete this manufacturer?</h6>
<br>
<form action="" method="post" novalidate>
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="Delete">
<a class="btn btn-primary" href="{% url 'taxi:manufacturer-list' %}">Cancel</a>
</form>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/taxi/manufacturer_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}

{% block content %}
<h1>{{ object|yesno:"Edit,Add" }} a manufacturer:</h1>
<form action="" method="post" novalidate>
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" value="{{ object|yesno:"Submit,Add" }}">
<a class="btn btn-primary" href="{% url 'taxi:manufacturer-list' %}">Cancel</a>
</form>
{% endblock %}
59 changes: 34 additions & 25 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
{% extends "base.html" %}

{% block content %}
<h1>Manufacturer List
</h1>
<h1>Manufacturer List</h1>
<p>
<a class="btn btn-primary" href="{% url 'taxi:manufacturer-create' %}">Add a manufacturer</a>
</p>
{% if manufacturer_list %}
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
<th>Update</th>
<th>Delete</th>
</tr>

{% if manufacturer_list %}
<table class="table">
{% for manufacturer in manufacturer_list %}
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
<td>
{{ manufacturer.id }}
</td>
<td>
{{ manufacturer.name }}
</td>
<td>
{{ manufacturer.country }}
</td>
<td>
<a class="btn btn-primary" href="{% url 'taxi:manufacturer-update' pk=manufacturer.pk %}">Update</a>
</td>
<td>
<a class="btn btn-primary" href="{% url 'taxi:manufacturer-delete' pk=manufacturer.pk %}">Delete</a>
</td>
</tr>
{% endfor %}
</table>

{% for manufacturer in manufacturer_list %}
<tr>
<td>
{{ manufacturer.id }}
</td>
<td>
{{ manufacturer.name }}
</td>
<td>
{{ manufacturer.country }}
</td>
</tr>
{% endfor %}
</table>

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