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

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 24 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 @@ -16,8 +22,26 @@
ManufacturerListView.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("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(
"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,6 +35,26 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView):
paginate_by = 5


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


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


class ManufacturerDeleteView(LoginRequiredMixin, generic.DeleteView):
model = Manufacturer
success_url = reverse_lazy("taxi:manufacturer-list")
template_name = "taxi/manufacturer_confirm_delete.html"


class CarListView(LoginRequiredMixin, generic.ListView):
model = Car
paginate_by = 5
Expand All @@ -44,6 +65,26 @@ class CarDetailView(LoginRequiredMixin, generic.DetailView):
model = Car


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
success_url = reverse_lazy("taxi:car-list")
template_name = "taxi/car_confirm_delete.html"


class DriverListView(LoginRequiredMixin, generic.ListView):
model = Driver
paginate_by = 5
Expand Down
3 changes: 3 additions & 0 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"debug_toolbar",
"crispy_forms",
"taxi",
]

Expand Down Expand Up @@ -75,6 +76,8 @@
},
]

CRISPY_TEMPLATE_PACK = "bootstrap4"

WSGI_APPLICATION = "taxi_service.wsgi.application"


Expand Down
6 changes: 3 additions & 3 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">
<!-- Add additional CSS in static file -->
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
Expand Down
4 changes: 2 additions & 2 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<ul class="sidebar-nav list-group">
{% if user.is_authenticated %}
<li class="list-group-item">User: <a href="{{ user.get_absolute_url }}">{{ user.get_username }}</a></li>
<li class="list-group-item"><a href="{% url 'logout'%}?next={{request.path}}">Logout</a></li>
<li class="list-group-item"><a href="{% url 'logout' %}?next={{ request.path }}">Logout</a></li>
{% else %}
<li class="list-group-item"><a href="{% url 'login'%}?next={{request.path}}">Login</a></li>
<li class="list-group-item"><a href="{% url 'login' %}?next={{ request.path }}">Login</a></li>
{% endif %}

<br>
Expand Down
4 changes: 2 additions & 2 deletions templates/registration/logged_out.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}

{% block content %}
<p>Logged out!</p>
<p>Logged out!</p>

<a href="{% url 'login'%}">Click here to login again.</a>
<a href="{% url 'login' %}">Click here to login again.</a>
{% endblock %}
26 changes: 13 additions & 13 deletions templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

{% block content %}

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

<h1>Login</h1>
<h1>Login</h1>

{% if next %}
<p>Please login to see this page.</p>
{% endif %}
{% if next %}
<p>Please login to see this page.</p>
{% endif %}

<form method="post" action="{% url 'login' %}">
{% csrf_token %}
{{ form.as_p }}
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
{{ form.as_p }}

<input type="submit" value="Login" class="btn btn-primary" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
<input type="submit" value="Login" class="btn btn-primary"/>
<input type="hidden" name="next" value="{{ next }}"/>
</form>

{% endblock %}
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 want to delete the car: {{ car }}</p>

<form action="" method="post">
{% csrf_token %}
<input type="submit" value="Yes, delete">
</form>
{% endblock %}
6 changes: 3 additions & 3 deletions templates/taxi/car_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<h1>Drivers</h1>
<hr>
<ul>
{% for driver in car.drivers.all %}
<li>{{ driver.username }} ({{ driver.first_name }} {{ driver.last_name }})</li>
{% endfor %}
{% for driver in car.drivers.all %}
<li>{{ driver.username }} ({{ driver.first_name }} {{ driver.last_name }})</li>
{% endfor %}
</ul>
{% endblock %}
13 changes: 13 additions & 0 deletions templates/taxi/car_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% 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 type="submit" value="Submit">
</form>
{% endblock %}
33 changes: 26 additions & 7 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
{% extends "base.html" %}

{% block content %}
<h1>Car list</h1>
<h1>
Car list
<a style="float: right" href="{% url 'taxi:car-create' %}">+</a>
</h1>
{% if car_list %}
<ul>
<table class="table">
<tr>
<th>ID</th>
<th>Model</th>
<th>Update</th>
<th>Delete</th>
</tr>
{% 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>
<td>
{{ car.id }}
</td>
<td>
{{ car.model }}
</td>
<td>
<a href="{% url 'taxi:car-update' pk=car.id %}">Update</a>
</td>
<td>
<a href="{% url 'taxi:car-delete' pk=car.id %}">Delete</a>
</td>
</tr>
{% endfor %}
</ul>
</table>
{% else %}
<p>There are no cars in taxi</p>
{% endif %}
Expand Down
8 changes: 4 additions & 4 deletions templates/taxi/driver_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ <h1>
<h4>Cars</h4>

{% for car in driver.cars.all %}
<hr>
<p><strong>Model:</strong> {{ car.model }}</p>
<p><strong>Manufacturer:</strong> {{ car.manufacturer.name }}</p>
<p class="text-muted"><strong>Id:</strong> {{car.id}}</p>
<hr>
<p><strong>Model:</strong> {{ car.model }}</p>
<p><strong>Manufacturer:</strong> {{ car.manufacturer.name }}</p>
<p class="text-muted"><strong>Id:</strong> {{ car.id }}</p>

{% empty %}
<p>No cars!</p>
Expand Down
31 changes: 16 additions & 15 deletions templates/taxi/driver_list.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% extends "base.html" %}

{% block content %}
<h1>Driver List
</h1>
<h1>Driver List
</h1>

{% if driver_list %}
{% if driver_list %}
<table class="table">
<tr>
<th>ID</th>
Expand All @@ -13,18 +13,19 @@ <h1>Driver List
<th>Last name</th>
<th>License number</th>
</tr>
{% for driver in driver_list %}
<tr>
<td>{{ driver.id }}</td>
<td><a href="{{ driver.get_absolute_url }}">{{ driver.username }} {% if user == driver %} (Me){% endif %}</a></td>
<td>{{ driver.first_name }}</td>
<td>{{ driver.last_name }}</td>
<td>{{ driver.license_number }}</td>
</tr>
{% endfor %}
{% for driver in driver_list %}
<tr>
<td>{{ driver.id }}</td>
<td><a href="{{ driver.get_absolute_url }}">{{ driver.username }} {% if user == driver %} (Me){% endif %}</a>
</td>
<td>{{ driver.first_name }}</td>
<td>{{ driver.last_name }}</td>
<td>{{ driver.license_number }}</td>
</tr>
{% endfor %}

</table>
{% else %}
<p>There are no drivers in the service.</p>
{% endif %}
{% else %}
<p>There are no drivers in the service.</p>
{% endif %}
{% endblock %}
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 want to delete the manufacturer: {{ manufacturer }}</p>

<form action="" method="post">
{% csrf_token %}
<input type="submit" value="Yes, delete">
</form>
{% endblock %}
13 changes: 13 additions & 0 deletions templates/taxi/manufacturer_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% 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 type="submit" value="Submit">
</form>
{% endblock %}
Loading
Loading