-
Notifications
You must be signed in to change notification settings - Fork 880
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
Мар'яна Тиха
committed
Dec 19, 2024
1 parent
e4d52bc
commit a28fa9c
Showing
9 changed files
with
50 additions
and
62 deletions.
There are no files selected for viewing
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,27 +1,8 @@ | ||
from django.urls import path | ||
from . import views | ||
|
||
from .views import ( | ||
index, | ||
CarListView, | ||
CarDetailView, | ||
DriverListView, | ||
DriverDetailView, | ||
ManufacturerListView, | ||
) | ||
app_name = "taxi" | ||
|
||
urlpatterns = [ | ||
path("", index, name="index"), | ||
path( | ||
"manufacturers/", | ||
ManufacturerListView.as_view(), | ||
name="manufacturer-list", | ||
), | ||
path("cars/", CarListView.as_view(), name="car-list"), | ||
path("cars/<int:pk>/", CarDetailView.as_view(), name="car-detail"), | ||
path("drivers/", DriverListView.as_view(), name="driver-list"), | ||
path( | ||
"drivers/<int:pk>/", DriverDetailView.as_view(), name="driver-detail" | ||
), | ||
path("", views.index, name="index"), | ||
] | ||
|
||
app_name = "taxi" |
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,17 @@ | ||
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() | ||
|
||
context = { | ||
"num_drivers": num_drivers, | ||
"num_cars": num_cars, | ||
"num_manufacturers": num_manufacturers, | ||
} | ||
|
||
return render(request, "taxi/index.html", context=context) | ||
|
||
|
||
class ManufacturerListView(generic.ListView): | ||
model = Manufacturer | ||
context_object_name = "manufacturer_list" | ||
template_name = "taxi/manufacturer_list.html" | ||
paginate_by = 5 | ||
|
||
|
||
class CarListView(generic.ListView): | ||
model = Car | ||
paginate_by = 5 | ||
queryset = Car.objects.select_related("manufacturer") | ||
|
||
|
||
class CarDetailView(generic.DetailView): | ||
model = Car | ||
|
||
|
||
class DriverListView(generic.ListView): | ||
model = Driver | ||
paginate_by = 5 | ||
|
||
|
||
class DriverDetailView(generic.DetailView): | ||
model = Driver | ||
queryset = Driver.objects.prefetch_related("cars__manufacturer") | ||
num_visits = request.session.get("num_visits", 1) | ||
request.session["num_visits"] = num_visits + 1 |
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,12 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block sidebar %} | ||
<a href="{% url 'taxi:index' %}">Home page</a> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="text-center"> | ||
<h1 class="mb-4">You're Logged Out</h1> | ||
<a href="{% url 'login' %}" class="btn btn-primary btn-lg">Log in</a> | ||
</div> | ||
{% endblock %} |
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,13 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block sidebar %} | ||
<a href="{% url 'taxi:index' %}">Home page</a> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<form method="post" class="form-group"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<input type="submit" value="Login" class="btn btn-primary"> | ||
</form> | ||
{% endblock %} |
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