Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ venv/
*.pyc
app/db.sqlite3
db.sqlite3
.venv/
Empty file added static/css/styles.css
Empty file.
8 changes: 8 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from taxi.views import index
Comment on lines +1 to +2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the Code Style requirement [CHECKLIST ITEM #2]:

"Add a blank line between different groups of imports and ensure appropriate ordering of imports:

  • Standard library imports.
  • Related third party imports.
  • Local application/library specific imports."

Currently the third-party import (from django.urls import path) and the local import (from taxi.views import index) are not separated by a blank line. Add a blank line between these two import groups (for example, keep line 1, add a blank line, then line 2).

Comment on lines +1 to +2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item #2: "Add a blank line between different groups of imports and ensure appropriate ordering of imports. Imports should be grouped in the following order: 1.Standard library imports. 2.Related third party imports. 3.Local application/library specific imports." Here you have a third-party import (from django.urls import path) followed immediately by a local import (from taxi.views import index) without a separating blank line. Add a blank line between these imports so groups are separated.


urlpatterns = [
path("", index, name="index"),
]

app_name = "taxi"
15 changes: 14 additions & 1 deletion taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render

# Create your views here.
from taxi.models import Driver, Manufacturer, Car


def index(request: HttpRequest) -> HttpResponse:
num_drivers = Driver.objects.count()
num_manufacturers = Manufacturer.objects.count()
num_cars = Car.objects.count()
context = {
"num_drivers": num_drivers,
"num_manufacturers": num_manufacturers,
"num_cars": num_cars,
}
return render(request, "taxi/index.html", context=context)
7 changes: 6 additions & 1 deletion taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -124,6 +124,11 @@

STATIC_URL = "static/"


STATICFILES_DIRS = [
BASE_DIR / "static",
]

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

Expand Down
3 changes: 2 additions & 1 deletion taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path("admin/", admin.site.urls),
path("", include("taxi.urls", namespace="taxi")),
]
26 changes: 26 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{% block title %}
<title>Taxi Service</title>
{% endblock %}
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3">
{% block sidebar %}
{% include "includes/sidebar.html" %}
{% endblock %}
</div>
<div class="col-sm-9">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>
7 changes: 7 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ul>
<li><a href="{% url 'taxi:index' %}">Home page</a></li>
<li><a href="#">Manufacturers</a></li>
<li><a href="#">Cars</a></li>
<li><a href="#">Drivers</a></li>
</ul>

10 changes: 10 additions & 0 deletions templates/taxi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block title %}
<title>Home page</title>
{% endblock %}
<ul>
<li>Number of cars: {{ num_cars }}</li>
<li>Number of drivers: {{ num_drivers }}</li>
<li>Number of manufacturers: {{ num_manufacturers }}</li>
</ul>
{% endblock %}
Loading