-
Notifications
You must be signed in to change notification settings - Fork 885
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
Done #745
Open
antonver
wants to merge
10
commits into
mate-academy:master
Choose a base branch
from
antonver:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Done #745
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a6383a8
Done
antonver eda7e05
Done2
antonver 090a0c4
Done2
antonver 4c6372f
Done2
antonver 6401706
Done2
antonver 51acd12
Done2
antonver 6fb381d
Done2
antonver adce1fc
Done2
antonver 542b196
Done3
antonver 704ca8c
Done3
antonver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 +1,7 @@ | ||
django==4.1 | ||
django~=5.0.7 | ||
flake8==5.0.4 | ||
flake8-quotes==3.3.1 | ||
flake8-variables-names==0.0.5 | ||
pep8-naming==0.13.2 | ||
|
||
django-debug-toolbar~=4.4.6 | ||
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 |
---|---|---|
@@ -1,47 +1,55 @@ | ||
from django.contrib.auth import authenticate, login, logout | ||
from django.contrib.auth.decorators import login_required | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
from django.contrib.auth.forms import AuthenticationForm | ||
from django.http import HttpResponse, HttpResponseRedirect, HttpRequest | ||
from django.shortcuts import render | ||
from django.urls import reverse | ||
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", 0) | ||
request.session["num_visits"] = num_visits + 1 | ||
context = { | ||
"num_drivers": num_drivers, | ||
"num_cars": num_cars, | ||
"num_manufacturers": num_manufacturers, | ||
"num_visits": request.session["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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
https://docs.djangoproject.com/en/4.0/ref/settings/ | ||
""" | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
# Build paths inside the project like this: BASE_DIR / "subdir". | ||
|
@@ -20,9 +21,8 @@ | |
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = ( | ||
SECRET_KEY = \ | ||
"django-insecure-8ovil3xu6=eaoqd#-#&ricv159p0pypoh5_lgm*)-dfcjqe=yc" | ||
) | ||
Comment on lines
-23
to
-25
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. Why you change this? 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. Flake8 said that it is too much of symbols |
||
|
||
# SECURITY WARNING: don"t run with debug turned on in production! | ||
DEBUG = True | ||
|
@@ -40,6 +40,7 @@ | |
"django.contrib.messages", | ||
"django.contrib.staticfiles", | ||
"taxi", | ||
"debug_toolbar", | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
@@ -50,14 +51,15 @@ | |
"django.contrib.auth.middleware.AuthenticationMiddleware", | ||
"django.contrib.messages.middleware.MessageMiddleware", | ||
"django.middleware.clickjacking.XFrameOptionsMiddleware", | ||
"debug_toolbar.middleware.DebugToolbarMiddleware", | ||
] | ||
|
||
ROOT_URLCONF = "taxi_service.urls" | ||
|
||
TEMPLATES = [ | ||
{ | ||
"BACKEND": "django.template.backends.django.DjangoTemplates", | ||
"DIRS": [BASE_DIR / "templates"], | ||
"DIRS": [os.path.join(BASE_DIR, "templates")], | ||
"APP_DIRS": True, | ||
"OPTIONS": { | ||
"context_processors": [ | ||
|
@@ -94,15 +96,15 @@ | |
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation." | ||
"MinimumLengthValidator", | ||
"MinimumLengthValidator", | ||
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation." | ||
"CommonPasswordValidator", | ||
"CommonPasswordValidator", | ||
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation." | ||
"NumericPasswordValidator", | ||
"NumericPasswordValidator", | ||
}, | ||
] | ||
|
||
|
@@ -133,3 +135,11 @@ | |
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" | ||
|
||
INTERNAL_IPS = [ | ||
# ... | ||
"127.0.0.1", | ||
# ... | ||
] | ||
|
||
LOGIN_REDIRECT_URL = "taxi:index" |
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,25 +1,12 @@ | ||
"""taxi_service URL Configuration | ||
|
||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/4.0/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path("", views.home, name="home") | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path("", Home.as_view(), name="home") | ||
Including another URLconf | ||
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, include | ||
from django.conf import settings | ||
from django.conf.urls.static import static | ||
|
||
from django.contrib import admin | ||
from django.urls import path, include | ||
import debug_toolbar | ||
|
||
urlpatterns = [ | ||
path("admin/", admin.site.urls), | ||
path("", include("taxi.urls", namespace="taxi")), | ||
path("accounts/", include("django.contrib.auth.urls")), | ||
path("__debug__/", include(debug_toolbar.urls)), | ||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) |
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,4 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<p>You logged out of the site, to go back use this link:<a href="{% url "login" %}" class="btn btn-primary">Login</a></p> | ||
{% 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,12 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<h1>Login</h1> | ||
{% if form.errors %} | ||
<p style="color:red">Invalid credentials</p> | ||
{% endif %} | ||
<form action="{% url 'login' %}" method="post"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<input type="submit" value="Submit" 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
remove an unnecessary blank line