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' #886

Open
wants to merge 2 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
25 changes: 25 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,45 @@
index,
CarListView,
CarDetailView,
CarCreateView,
CarUpdateView,
CarDeleteView,
DriverListView,
DriverDetailView,
ManufacturerListView,
ManufacturerCreateView,
ManufacturerUpdateView,
ManufacturerDeleteView,
)


urlpatterns = [
path("", index, name="index"),
path(
"manufacturers/",
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/", 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/update/<int:pk>/", CarUpdateView.as_view(), name="car-update"),
path("cars/delete/<int:pk>/", CarDeleteView.as_view(), name="car-delete"),
path("drivers/", DriverListView.as_view(), name="driver-list"),
path(
"drivers/<int:pk>/", DriverDetailView.as_view(), name="driver-detail"
Expand Down
41 changes: 41 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,52 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView):
paginate_by = 5


class ManufacturerCreateView(LoginRequiredMixin, generic.CreateView):
model = Manufacturer
fields = "__all__"
template_name = "taxi/car_manufacturer_form.html"
success_url = reverse_lazy("taxi:manufacturer-list")


class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Manufacturer
fields = "__all__"
template_name = "taxi/car_manufacturer_form.html"
success_url = reverse_lazy("taxi:manufacturer-list")


class ManufacturerDeleteView(LoginRequiredMixin, generic.DeleteView):
model = Manufacturer
template_name = "taxi/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__"
template_name = "taxi/car_form.html"
success_url = reverse_lazy("taxi:car-list")


class CarUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Car
fields = "__all__"
template_name = "taxi/car_form.html"
success_url = reverse_lazy("taxi:car-list")


class CarDeleteView(LoginRequiredMixin, generic.DeleteView):
model = Car
template_name = "taxi/confirm_delete.html"
success_url = reverse_lazy("taxi:car-list")


class CarDetailView(LoginRequiredMixin, generic.DetailView):
model = Car

Expand Down
6 changes: 6 additions & 0 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"debug_toolbar",
"crispy_forms",
"crispy_bootstrap4",
"taxi",

]

MIDDLEWARE = [
Expand Down Expand Up @@ -140,3 +143,6 @@
# 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"
7 changes: 4 additions & 3 deletions templates/includes/pagination.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{% if is_paginated %}
<ul class="pagination">
<hr class="mt-5">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a href="?page= {{ page_obj.previous_page_number }}" class="page-link">prev</a>
<a href="?page={{ page_obj.previous_page_number }}" class="page-link">prev</a>
</li>
{% endif %}
<li class="page-item active">
<span class="page-link">{{ page_obj.number }} of {{ paginator.num_pages }}</span>
</li>
{% if page_obj.has_next %}
<li class="page-item">
<a href="?page= {{ page_obj.next_page_number }}" class="page-link">next</a>
<a href="?page={{ page_obj.next_page_number }}" class="page-link">next</a>
</li>
{% endif %}
</ul>
Expand Down
15 changes: 15 additions & 0 deletions templates/taxi/car_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}

{% load crispy_forms_filters %}
{% block content %}
<h2 class="mb-2">{{ object|yesno:"Update, Create new" }} Car</h2>
<hr class="blue-hr">
<div class="mt-5">
<form action="" method="post">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Submit" class="btn btn-primary">
</form>
</div>
<style>.blue-hr{height:3px; background-color:#007bff;}</style>
{% endblock %}
40 changes: 32 additions & 8 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
{% extends "base.html" %}

{% block content %}
<h1>Car list</h1>
<h1 class="d-flex align-items-stretch mb-5 mt-5">
<span>Cars</span>
<a class="alert alert-primary create-link ml-5" href="{% url 'taxi:car-create' %}" role="button">Add new Car</a>
</h1>
<p>List of our fleet. The best brands, proven and reliable models.</p>
{% if car_list %}
<ul>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Model</th>
<th scope="col">Manufacturer</th>
<th scope="col">Modify</th>
</tr>
</thead>
<tbody>
{% for car in car_list %}
<li>
<a href="{% url "taxi:car-detail" pk=car.id %} ">{{ car.id }}</a>
{{ car.model }} ({{ car.manufacturer.name }})
</li>
<tr>
<th scope="row"><span class="c_counter"></span></th>
<td><a href="{% url 'taxi:car-detail' car.pk %}"> {{ car.model }} </a></td>
<td>{{ car.manufacturer }}</td>
<td>
<a href="{% url 'taxi:car-update' car.pk %}" class="btn btn-outline-primary change-link">Update</a>
<a href="{% url 'taxi:car-delete' car.pk %}" class="btn btn-outline-danger change-link">Delete</a>
</td>
</tr>
{% endfor %}
</ul>
</tbody>
</table>
{% else %}
<p>There are no cars in taxi</p>
<p>No cars found.</p>
{% endif %}
<div> </div>
<style>
body {counter-reset: item;} .c_counter::before{content: counter(item); counter-increment: item}
.change-link {opacity:.75} .create-link {font-size:1rem; display: inline-block;}
</style>
{% endblock %}
15 changes: 15 additions & 0 deletions templates/taxi/car_manufacturer_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}

{% load crispy_forms_filters %}
{% block content %}
<h2 class="mb-2">{{ object|yesno:"Update, Create new" }} Manufacturer</h2>
<hr class="blue-hr">
<div class="mt-5">
<form action="" method="post">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Submit" class="btn btn-primary">
</form>
</div>
<style>.blue-hr{height:3px; background-color:#007bff;}</style>
{% endblock %}
17 changes: 17 additions & 0 deletions templates/taxi/confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "base.html" %}

{% load crispy_forms_filters %}

{% block content %}
<h2 class="mb-2">Delete {{ car|yesno:"Car, Manufacturer" }}</h2>
<hr class="blue-hr">
<div class="mt-5">
<p class="text-are-delete">Are you sure you want to delete "{{ object }}"?</p>
<form action="" method="post">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="Confirm" class="btn btn-danger">
</form>
</div>
<style>.blue-hr{height:3px; background-color:#dc3545;} .text-are-delete {font-size:1.5em}</style>
{% endblock %}
15 changes: 13 additions & 2 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{% extends "base.html" %}

{% block content %}
<h1>Manufacturer List
<h1 class="d-flex align-items-stretch mb-5 mt-5">
<span>Manufacturer List</span>
<a class="alert alert-primary create-link ml-5" href="{% url 'taxi:manufacturer-create' %}" role="button">Add new Manufacturer</a>
</h1>

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

{% for manufacturer in manufacturer_list %}
Expand All @@ -23,11 +26,19 @@ <h1>Manufacturer List
<td>
{{ manufacturer.country }}
</td>
<td>
<a href="{% url 'taxi:manufacturer-update' manufacturer.pk %}" class="btn btn-outline-primary change-link">Update</a>
<a href="{% url 'taxi:manufacturer-delete' manufacturer.pk %}" class="btn btn-outline-danger change-link">Delete</a>
</td>
</tr>
{% endfor %}
</table>

{% else %}
<p>There are no manufacturers in the service.</p>
{% endif %}
<style>
body {counter-reset: item;} .c_counter::before{content: counter(item); counter-increment: item}
.change-link {opacity:.75} .create-link {font-size:1rem; display: inline-block;}
</style>
{% endblock %}
Loading