-
Notifications
You must be signed in to change notification settings - Fork 845
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' #896
base: master
Are you sure you want to change the base?
'Solution' #896
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
from django.urls import path | ||
|
||
from .views import ( | ||
index, | ||
CarListView, | ||
CarDetailView, | ||
DriverListView, | ||
DriverDetailView, | ||
ManufacturerListView, | ||
) | ||
index, CarListView, CarDetailView, | ||
DriverListView, DriverDetailView, ManufacturerListView) | ||
|
||
urlpatterns = [ | ||
path("", index, name="index"), | ||
path( | ||
"manufacturers/", | ||
ManufacturerListView.as_view(), | ||
name="manufacturer-list", | ||
), | ||
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("drivers/<int:pk>/", | ||
DriverDetailView.as_view(), | ||
name="driver-detail" | ||
), | ||
] | ||
|
||
app_name = "taxi" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,59 @@ | ||
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 django.contrib.auth import logout as auth_logout | ||
|
||
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") | ||
|
||
|
||
def logout(request): | ||
auth_logout(request) | ||
return render(request, "registration/logout.html") | ||
omnigun marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+57
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ок |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,14 @@ | |
2. Add a URL to urlpatterns: path("blog/", include("blog.urls")) | ||
""" | ||
from django.contrib import admin | ||
from django.urls import path, include | ||
from django.urls import path, include, re_path | ||
from django.conf import settings | ||
from django.conf.urls.static import static | ||
|
||
from taxi.views import logout | ||
|
||
urlpatterns = [ | ||
path("admin/", admin.site.urls), | ||
path("", include("taxi.urls", namespace="taxi")), | ||
path("accounts/", include("django.contrib.auth.urls")), | ||
re_path(r"^logout/$", logout, name="logout") | ||
omnigun marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,32 +9,33 @@ | |
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' %}"> | ||
</head> | ||
|
||
<body> | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-2"> | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-2"> | ||
|
||
{% block sidebar %} | ||
{% include "includes/sidebar.html" %} | ||
{% endblock %} | ||
|
||
</div> | ||
<div class="col-sm-10 "> | ||
</div> | ||
<div class="col-sm-10 "> | ||
|
||
{% block content %}{% endblock %} | ||
|
||
{% block pagination %} | ||
{% include "includes/pagination.html" %} | ||
<p>You have visited this page {{ num_visits }} time{{ num_visits|pluralize }}</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
{% endblock %} | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
{% endif %} | ||
</ul> | ||
{% endif %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
<ul class="sidebar-nav"> | ||
{% if user.is_authenticated %} | ||
<li> User: <a href="{% url "taxi:driver-detail" pk=user.id %}"> {{ user.username }}</a></li> | ||
omnigun marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the URL name |
||
<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> | ||
|
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: red">Invalid credentials</p> | ||
{% endif %} | ||
<form method="post" action="{% url 'login' %}"> | ||
omnigun marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify that the URL name 'login' matches the URL pattern defined in your project's |
||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<input type="submit" value="Submit"> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<p>Logged out!</p> | ||
<a href="{% url 'login'%}">Click here to login again.</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify that the URL name 'login' matches the URL pattern defined in your project's |
||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,13 @@ | |
<h1>Driver list</h1> | ||
{% if driver_list %} | ||
<ul> | ||
{% for driver in driver_list%} | ||
{% for driver in driver_list %} | ||
<li> | ||
<a href="{% url "taxi:driver-detail" pk=driver.id %}">{{ driver.username }}</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the URL name |
||
({{ driver.first_name }} {{ driver.last_name }}) | ||
{% if driver.id == user.id %} | ||
(Me) | ||
{% endif %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the task requirements, URL names should use hyphens (
-
) instead of underscores (_
). Please changemanufacturer-list
tomanufacturer-list
to follow this convention.