-
Notifications
You must be signed in to change notification settings - Fork 885
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oleksandra
committed
Jan 30, 2024
1 parent
46d9023
commit 9a072f3
Showing
21 changed files
with
220 additions
and
167 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
body { | ||
margin-top: 20px; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
hr { | ||
margin: 6px 0 18px; | ||
} | ||
|
||
.title { | ||
padding: 16px 0; | ||
margin: 0; | ||
} | ||
|
||
.subtitle { | ||
padding-bottom: 16px; | ||
margin: 0; | ||
} | ||
|
||
.page { | ||
padding-left: 30px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,56 @@ | ||
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, | ||
"url_home": True | ||
} | ||
|
||
return render(request, "taxi/index.html", context=context) | ||
|
||
|
||
class ManufacturerListView(generic.ListView): | ||
class ManufacturerListView(LoginRequiredMixin, generic.ListView): | ||
model = Manufacturer | ||
extra_context = {"url_manufacturer": True} | ||
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 | ||
extra_context = {"url_car": True} | ||
paginate_by = 5 | ||
queryset = Car.objects.select_related("manufacturer") | ||
|
||
|
||
class CarDetailView(generic.DetailView): | ||
class CarDetailView(LoginRequiredMixin, generic.DetailView): | ||
model = Car | ||
extra_context = {"url_car": True} | ||
|
||
|
||
class DriverListView(generic.ListView): | ||
class DriverListView(LoginRequiredMixin, generic.ListView): | ||
model = Driver | ||
extra_context = {"url_driver": True} | ||
paginate_by = 5 | ||
|
||
|
||
class DriverDetailView(generic.DetailView): | ||
class DriverDetailView(LoginRequiredMixin, generic.DetailView): | ||
model = Driver | ||
extra_context = {"url_driver": True} | ||
queryset = Driver.objects.prefetch_related("cars__manufacturer") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% load bootstrap_icons %} | ||
|
||
<header class="d-flex justify-content-between align-items-center px-4"> | ||
<h1 class="title">Taxi Service</h1> | ||
|
||
<div class="d-flex justify-content-between align-items-center"> | ||
{% if user.is_authenticated %} | ||
<span>Welcome, <a href="{% url "taxi:driver-detail" user.id %}">{{ user.first_name }}</a></span> | ||
<a class="btn btn-primary d-flex align-items-center ml-3" href="{% url "logout" %}" role="button"> | ||
{% bs_icon "box-arrow-right" size='1.1em' extra_classes="mr-2" %}Logout | ||
</a> | ||
{% else %} | ||
<a class="btn btn-primary d-flex align-items-center ml-3" href="{% url "login" %}" role="button"> | ||
{% bs_icon "box-arrow-in-right" size='1.1em' extra_classes="mr-2" %}Login | ||
</a> | ||
{% endif %} | ||
</div> | ||
</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
{% if is_paginated %} | ||
<ul class="pagination"> | ||
{% if page_obj.has_previous %} | ||
<li class="page-item"> | ||
<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> | ||
<ul class="pagination justify-content-end mt-3"> | ||
<li class="page-item {% if not page_obj.has_previous %}disabled{% endif %}"> | ||
<a class="page-link" href="{% if page_obj.has_previous %}?page={{ page_obj.previous_page_number }}{% endif %}"> | ||
<span>«</span> | ||
</a> | ||
</li> | ||
<li class="page-item bg-primary"><span class="page-link">{{ page_obj.number }} / {{ paginator.num_pages }}</span></li> | ||
<li class="page-item {% if not page_obj.has_next %}disabled{% endif %}"> | ||
<a class="page-link" href="{% if page_obj.has_next %}?page={{ page_obj.next_page_number }}{% endif %}"> | ||
<span>»</span> | ||
</a> | ||
</li> | ||
{% if page_obj.has_next %} | ||
<li class="page-item"> | ||
<a href="?page= {{ page_obj.next_page_number }}" class="page-link">next</a> | ||
</li> | ||
{% endif %} | ||
</ul> | ||
{% endif %} |
Oops, something went wrong.