Skip to content
Open

Develop #1359

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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ max-complexity = 18
select = B,C,E,F,W,T4,B9,Q0,N8,VNE
exclude =
**migrations
venv
.venv
tests
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

Expand Down
25 changes: 25 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
body {
padding: 20px;
}

a {
text-decoration: none;
}

.visits {
font-weight: normal;
}

.nav-content {
list-style-type: none;
padding: 0;
margin: 0;
}

.nav-content>li{
padding: 10px;
}

a:hover {
text-decoration: underline;
}
9 changes: 9 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from taxi.views import index

app_name = "taxi"

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

Choose a reason for hiding this comment

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

This violates checklist item #1: 'Ensure each file ends with a single blank line.' Please add a blank line at the end of the file.

20 changes: 19 additions & 1 deletion taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.utils.translation.trans_real import catalog

Choose a reason for hiding this comment

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

This catalog import is not used anywhere in the file. It's best to remove unused imports to keep the code clean.


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


def index(request: HttpRequest) -> HttpResponse:
visits = request.session.get("visits", 0)
request.session["visits"] = visits + 1

Choose a reason for hiding this comment

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

This visit counting logic was not part of the task requirements. While it's a good feature, it's important to implement only what is requested in the task description.

num_drivers = Driver.objects.count()
num_manufacturers = Manufacturer.objects.count()
num_cars = Car.objects.count()
context = {
"visits": request.session["visits"],
"num_drivers": num_drivers,
"num_manufacturers": num_manufacturers,
"num_cars": num_cars,
}

return render(request, template_name="taxi/index.html", context=context)

Choose a reason for hiding this comment

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

This violates checklist item #1: 'Ensure each file ends with a single blank line.' Please add a newline at the end of the file.

11 changes: 8 additions & 3 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-8ovil3xu6=eaoqd#" \
SECRET_KEY = "django-insecure-8ovil3xu6=eaoqd#"\

Choose a reason for hiding this comment

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

This violates checklist item #1 from the 'Clean Code' section: 'Don't forget to delete comments when you are ready to commit and push your code.' Please remove all auto-generated comments from this file to keep the code clean.

"-#&ricv159p0pypoh5_lgm*)-dfcjqe=yc"

# SECURITY WARNING: don't run with debug turned on in production!
Expand All @@ -39,6 +39,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"taxi",
"django_extensions",

Choose a reason for hiding this comment

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

The django_extensions app is not required for this task. Please remove any unnecessary applications from INSTALLED_APPS to keep the configuration minimal and focused on the project's requirements.

]

MIDDLEWARE = [
Expand All @@ -56,7 +57,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -89,7 +90,7 @@
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation"
".UserAttributeSimilarityValidator",
".UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation"
Expand Down Expand Up @@ -124,6 +125,10 @@

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
4 changes: 3 additions & 1 deletion taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
1. Import the include() function: from django.urls import include, path
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("taxi/", include("taxi.urls", namespace="taxi")),

Choose a reason for hiding this comment

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

The requirement is for the home page to be accessible at http://127.0.0.1:8000/. To achieve this, the path should be an empty string "" instead of "taxi/".

]
17 changes: 17 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Taxi Service</title>

Choose a reason for hiding this comment

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

The task requires creating a title block here. While you have the correct text, it should be wrapped in {% block title %} and {% endblock %} tags to allow child templates to override it if needed.

{% load static %}
<link rel="stylesheet" href="{% static "css/styles.css" %}">
</head>
<body>
{% block sidebar %}
{% include "includes/sidebar.html" %}
{% endblock %}

{% block content %}
{% endblock %}
</body>
</html>

Choose a reason for hiding this comment

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

This violates checklist item #1: 'Ensure each file ends with a single blank line.' Please add a blank line at the end of this file.

Choose a reason for hiding this comment

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

The task requirements state that each HTML file should end with an empty line. Please add a blank line at the end of this file to adhere to the coding standards for this project.

16 changes: 16 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h1>Library Home</h1>
<h3>Welcome to the Greatest Library</h3>

Choose a reason for hiding this comment

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

These headings seem to be from a different project context (a library). The task is about a taxi service. Please remove these or update the text to be relevant to the taxi service application. The requirements only specify the list of links.

<ul class="nav-content">
<li>
<a href="#">Home page</a>
</li>
<li>
<a href="#">Manufacturers</a>
</li>
<li>
<a href="#">Cars</a>
</li>
<li>
<a href="#">Drivers</a>
</li>
</ul>

Choose a reason for hiding this comment

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

This violates checklist item #1 and description item #9: 'Ensure each file ends with a single blank line.' Please add a blank line at the end of this HTML file.

12 changes: 12 additions & 0 deletions templates/taxi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}

{% block content %}
<h1>Library content</h1>

Choose a reason for hiding this comment

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

The heading "Library content" seems out of place for a taxi service application. It should be updated to something more relevant, like "Taxi Service Home".

<ul>
<li>Number of cars: {{ num_cars }}</li>
<li>Number of drivers: {{ num_drivers }}</li>
<li>Number of manufacturers: {{ num_manufacturers }}</li>
</ul>

<h4 class="visits">You have visited this page {{ visits }} times</h4>

Choose a reason for hiding this comment

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

This visit counter functionality was not part of the task requirements. Please implement only the features requested in the description.

{% endblock %}

Choose a reason for hiding this comment

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

This violates checklist item #1: 'Ensure each file ends with a single blank line.' Please add a blank line at the end of the file.

11 changes: 5 additions & 6 deletions tests/test_taxi_service_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

from taxi.models import Car, Manufacturer

TestCase.fixtures = ["taxi_service_db_data.json", ]
TestCase.fixtures = [
"taxi_service_db_data.json",
]


class HomePageTests(TestCase):
Expand All @@ -21,14 +23,11 @@ def test_index_count_content_correctly(self):
self.assertTemplateUsed(response, "taxi/index.html")
self.assertEqual(response.context["num_drivers"], num_drivers)
self.assertEqual(response.context["num_cars"], num_cars)
self.assertEqual(
response.context["num_manufacturers"],
num_manufacturers
)
self.assertEqual(response.context["num_manufacturers"], num_manufacturers)


class IsStylesCSSExistTests(TestCase):
def test_styles_exist(self):
file_exists = os.path.exists('static/css/styles.css')
file_exists = os.path.exists("static/css/styles.css")

self.assertTrue(file_exists)

Choose a reason for hiding this comment

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

This violates checklist item #1: 'Ensure each file ends with a single blank line.' Please add a blank line at the end of the file.

Loading