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

Develop #785

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
20 changes: 20 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
body {
margin-top: 20px;
background-color: #e7eeee;
}

table {
border-collapse: collapse;
}

th, td {
border-top: 1px solid #757373;
border-bottom: 1px solid #757373;
padding: 10px;
}
.col-sm-3 {
max-width: 250px;
max-height: 150px;
padding: 10px;
font-family: monospace;
white-space: pre-wrap;
box-shadow: 0 40px 40px rgba(0, 0, 0, 0.1);
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
17 changes: 17 additions & 0 deletions taxi/migrations/0004_alter_car_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.1 on 2024-09-10 19:23

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('taxi', '0003_alter_manufacturer_name'),
]

operations = [
migrations.AlterModelOptions(
name='car',
options={'ordering': ['model']},
),
]
3 changes: 3 additions & 0 deletions taxi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ class Car(models.Model):
manufacturer = models.ForeignKey(Manufacturer, on_delete=models.CASCADE)
drivers = models.ManyToManyField(Driver, related_name="cars")

class Meta:
ordering = ["model"]

def __str__(self):
return self.model
17 changes: 12 additions & 5 deletions taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.views import generic

from .models import Driver, Car, Manufacturer


@login_required
def index(request):
"""View function for the home page of the site."""

num_drivers = Driver.objects.count()
num_cars = Car.objects.count()
num_manufacturers = Manufacturer.objects.count()

num_visits = request.session.get("num_visits", 0)
request.session["num_visits"] = num_visits + 1

context = {
"num_drivers": num_drivers,
"num_cars": num_cars,
"num_manufacturers": num_manufacturers,
"num_visits": num_visits + 1,
}

return render(request, "taxi/index.html", context=context)


class ManufacturerListView(generic.ListView):
class ManufacturerListView(LoginRequiredMixin, generic.ListView):
model = Manufacturer
context_object_name = "manufacturer_list"
template_name = "taxi/manufacturer_list.html"
paginate_by = 5


class CarListView(generic.ListView):
class CarListView(LoginRequiredMixin, generic.ListView):
model = Car
paginate_by = 5
queryset = Car.objects.select_related("manufacturer")


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


class DriverListView(generic.ListView):
class DriverListView(LoginRequiredMixin, generic.ListView):
model = Driver
paginate_by = 5


class DriverDetailView(generic.DetailView):
class DriverDetailView(LoginRequiredMixin, generic.DetailView):
model = Driver
queryset = Driver.objects.prefetch_related("cars__manufacturer")
2 changes: 2 additions & 0 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

LOGIN_REDIRECT_URL = "/"
1 change: 1 addition & 0 deletions taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("taxi.urls", namespace="taxi")),
path("accounts/", include("django.contrib.auth.urls")),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
7 changes: 7 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<ul class="sidebar-nav">
{% if user.is_authenticated %}
<li><a href="{% url "taxi:driver-detail" pk=user.id %}">{{ user.username }}</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'login' %}">Login</a></li>
{% endif %}
<br>
<li><a href="{% url "taxi:index" %}">Home page</a></li>
<li><a href="{% url "taxi:manufacturer-list" %}">Manufacturers</a></li>
<li><a href="{% url "taxi:car-list" %}">Cars</a></li>
Expand Down
6 changes: 6 additions & 0 deletions templates/registration/logged_out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "base.html" %}

{% block content %}
<p>Logged out!</p>
<a href="{% url 'login'%}">Click here to login again.</a>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block content %}
<h1>Login</h1>
{% if form.errors %}
<p style="color: #c92752">Invalid credentials</p>
{% endif %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Log In</button>
</form>
{% endblock %}
1 change: 1 addition & 0 deletions templates/taxi/car_detail.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{% extends "base.html" %}

{% block content %}
Expand Down
31 changes: 20 additions & 11 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{% extends "base.html" %}

{% block content %}
<h1>Car list</h1>
<h1>Car List</h1>
{% if car_list %}
<ul>
{% for car in car_list %}
<li>
<a href="{% url "taxi:car-detail" pk=car.id %} ">{{ car.id }}</a>
{{ car.model }} ({{ car.manufacturer.name }})
</li>
{% endfor %}
</ul>
<table>
<thead>
<tr>
<th>ID</th>
<th>Manufacturer</th>
<th>Model</th>
</tr>
</thead>
<tbody>
{% for car in car_list %}
<tr>
<td><a href="{% url 'taxi:car-detail' car.id %}">{{ car.id }}</a></td>
<td><a href="{% url 'taxi:car-detail' car.id %}">{{ car.manufacturer.name }}</a></td>
<td><a href="{% url 'taxi:car-detail' car.id %}">{{ car.model }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no cars in taxi</p>
<p>No cars available.</p>
{% endif %}
{% endblock %}
31 changes: 20 additions & 11 deletions templates/taxi/driver_list.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{% extends "base.html" %}

{% block content %}
<h1>Driver list</h1>
<h1>Driver List</h1>
{% if driver_list %}
<ul>
{% for driver in driver_list%}
<li>
<a href="{% url "taxi:driver-detail" pk=driver.id %}">{{ driver.username }}</a>
({{ driver.first_name }} {{ driver.last_name }})
</li>
{% endfor %}
</ul>
<table>
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
{% for driver in driver_list %}
<tr>
<td><a href="{% url 'taxi:driver-detail' driver.id %}">{{ driver.id }}</a></td>
<td><a href="{% url 'taxi:driver-detail' driver.id %}">{{ driver.first_name }}</a></td>
<td><a href="{% url 'taxi:driver-detail' driver.id %}">{{ driver.last_name }}</a>{% if user == driver %} (me) {% endif %} </td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no drivers in taxi</p>
<p>No drivers available.</p>
{% endif %}
{% endblock %}
9 changes: 9 additions & 0 deletions templates/taxi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
{% block content %}
<h1>Taxi Service Home</h1>
<p>Welcome to Best Taxi Ever!</p>
<div class="col-sm-3">
<pre>
______
/|_||_\`.__
( _ _ _\
=`-(_)--(_)-'
</pre>
</div>
<h2>Dynamic content</h2>
<p>The Taxi service has the following record counts:</p>
<ul>
<li><strong>Cars:</strong> {{ num_cars }}</li>
<li><strong>Drivers:</strong> {{ num_drivers }}</li>
<li><strong>Manufacturers:</strong> {{ num_manufacturers }}</li>
</ul>
<p>You have visited this page {{ num_visits }} time{{ num_visits|pluralize }}.</p>
{% endblock %}
29 changes: 21 additions & 8 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
{% extends "base.html" %}

{% block content %}
<h1>Manufacturer list</h1>

<h1>Manufacturer List</h1>
{% if manufacturer_list %}
<ul>
{% for manufacturer in manufacturer_list %}
<li>{{ manufacturer.name }} {{ manufacturer.country }}</li>
{% endfor %}
</ul>
<table>
<thead>
<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>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No manufacturers =(</p>
{% endif %}
{% endblock %}
Loading