-
Notifications
You must be signed in to change notification settings - Fork 845
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
1 parent
46d9023
commit a791301
Showing
8 changed files
with
48 additions
and
5 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,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", 1) | ||
request.session["num_visits"] = num_visits + 1 | ||
|
||
context = { | ||
"num_drivers": num_drivers, | ||
"num_cars": num_cars, | ||
"num_manufacturers": num_manufacturers, | ||
"num_visits": num_visits, | ||
} | ||
|
||
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") |
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,7 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<p>Logged out!</p> | ||
|
||
<a href="{% url 'login' %}">Click here to login</a> | ||
{% 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,14 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
{% if form.errors %} | ||
<p style="color:red">Invalid credentials</p> | ||
{% endif %} | ||
|
||
<form method="post" , action="{% url 'login' %}"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<input type="submit" name="Login"> | ||
<input type="hidden" name="next" value="{{ next }}"> | ||
</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