-
Notifications
You must be signed in to change notification settings - Fork 886
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 #874
Open
yulia-pl
wants to merge
4
commits into
mate-academy:master
Choose a base branch
from
yulia-pl:develop
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
Solution #874
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Requirement already satisfied: django in c:\users\asus\py-taxi-service-forms\venv\lib\site-packages (4.1) | ||
Requirement already satisfied: asgiref<4,>=3.5.2 in c:\users\asus\py-taxi-service-forms\venv\lib\site-packages (from django) (3.8.1) | ||
Requirement already satisfied: sqlparse>=0.2.2 in c:\users\asus\py-taxi-service-forms\venv\lib\site-packages (from django) (0.5.2) | ||
Requirement already satisfied: tzdata in c:\users\asus\py-taxi-service-forms\venv\lib\site-packages (from django) (2024.2) |
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,30 @@ | ||
from django import forms | ||
from .models import Car, Manufacturer | ||
from crispy_forms.helper import FormHelper | ||
from crispy_forms.layout import Submit | ||
|
||
|
||
class CarForm(forms.ModelForm): | ||
class Meta: | ||
model = Car | ||
fields = ["model", "manufacturer", "drivers"] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.helper = FormHelper() | ||
self.helper.add_input(Submit("submit", "Save")) | ||
|
||
|
||
class ManufacturerForm(forms.ModelForm): | ||
class Meta: | ||
model = Manufacturer | ||
fields = ["name", "country"] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.helper = FormHelper() | ||
self.helper.add_input(Submit("submit", "Save")) | ||
|
||
|
||
class DriverForm: | ||
pass |
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,27 +1,104 @@ | ||
from django.urls import path | ||
|
||
from .views import ( | ||
index, | ||
CarListView, | ||
CarDetailView, | ||
CarCreateView, | ||
CarUpdateView, | ||
CarDeleteView, | ||
ManufacturerListView, | ||
ManufacturerCreateView, | ||
ManufacturerUpdateView, | ||
ManufacturerDeleteView, | ||
DriverListView, | ||
DriverCreateView, | ||
DriverUpdateView, | ||
DriverDeleteView, | ||
ManufacturerDetailView, | ||
DriverDetailView, | ||
ManufacturerListView, | ||
) | ||
|
||
app_name = "taxi" | ||
|
||
urlpatterns = [ | ||
path("", index, name="index"), | ||
path( | ||
"", | ||
index, | ||
name="index" | ||
), | ||
path( | ||
"cars/", | ||
CarListView.as_view(), | ||
name="car-list" | ||
), | ||
path( | ||
"cars/create/", | ||
CarCreateView.as_view(), | ||
name="car-create" | ||
), | ||
path( | ||
"cars/<int:pk>/", | ||
CarDetailView.as_view(), | ||
name="car-detail" | ||
), | ||
path( | ||
"cars/<int:pk>/update/", | ||
CarUpdateView.as_view(), | ||
name="car-update" | ||
), | ||
path( | ||
"cars/<int:pk>/delete/", | ||
CarDeleteView.as_view(), | ||
name="car-delete" | ||
), | ||
path( | ||
"manufacturers/", | ||
ManufacturerListView.as_view(), | ||
name="manufacturer-list", | ||
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" | ||
"manufacturers/create/", | ||
ManufacturerCreateView.as_view(), | ||
name="manufacturer-create" | ||
), | ||
path( | ||
"manufacturers/<int:pk>/", | ||
ManufacturerDetailView.as_view(), | ||
name="manufacturer-detail" | ||
), | ||
path( | ||
"manufacturers/<int:pk>/update/", | ||
ManufacturerUpdateView.as_view(), | ||
name="manufacturer-update" | ||
), | ||
path( | ||
"manufacturers/<int:pk>/delete/", | ||
ManufacturerDeleteView.as_view(), | ||
name="manufacturer-delete" | ||
), | ||
path( | ||
"drivers/", | ||
DriverListView.as_view(), | ||
name="driver-list" | ||
), | ||
path( | ||
"drivers/<int:pk>/", | ||
DriverDetailView.as_view(), | ||
name="driver-detail" | ||
), | ||
path( | ||
"drivers/create/", | ||
DriverCreateView.as_view(), | ||
name="driver-create" | ||
), | ||
path( | ||
"drivers/<int:pk>/update/", | ||
DriverUpdateView.as_view(), | ||
name="driver-update" | ||
), | ||
path( | ||
"drivers/<int:pk>/delete/", | ||
DriverDeleteView.as_view(), | ||
name="driver-delete" | ||
), | ||
] | ||
|
||
app_name = "taxi" |
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,54 +1,125 @@ | ||
from django.shortcuts import render, get_object_or_404 | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import render | ||
from django.views import generic | ||
from django.views.generic import (ListView, | ||
DetailView, | ||
CreateView, | ||
UpdateView, | ||
DeleteView) | ||
from django.urls import reverse_lazy | ||
from .models import Car, Manufacturer, Driver | ||
from .forms import CarForm, ManufacturerForm, DriverForm | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
|
||
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_drivers = Driver.objects.count() | ||
num_manufacturers = Manufacturer.objects.count() | ||
|
||
num_visits = request.session.get("num_visits", 0) | ||
request.session["num_visits"] = num_visits + 1 | ||
|
||
num_visits = request.session.get("num_visits", 0) + 1 | ||
request.session["num_visits"] = num_visits | ||
context = { | ||
"num_drivers": num_drivers, | ||
"num_cars": num_cars, | ||
"num_drivers": num_drivers, | ||
"num_manufacturers": num_manufacturers, | ||
"num_visits": num_visits + 1, | ||
"num_visits": num_visits, | ||
} | ||
return render(request, "taxi/index.html", context) | ||
|
||
|
||
class CarListView(LoginRequiredMixin, ListView): | ||
model = Car | ||
context_object_name = "car_list" | ||
template_name = "taxi/car_list.html" | ||
|
||
|
||
class CarDetailView(LoginRequiredMixin, DetailView): | ||
model = Car | ||
template_name = "taxi/car_detail.html" | ||
|
||
|
||
class CarCreateView(LoginRequiredMixin, CreateView): | ||
model = Car | ||
form_class = CarForm | ||
template_name = "taxi/car_form.html" | ||
success_url = reverse_lazy("taxi:car-list") | ||
|
||
|
||
class CarUpdateView(LoginRequiredMixin, UpdateView): | ||
model = Car | ||
form_class = CarForm | ||
template_name = "taxi/car_form.html" | ||
success_url = reverse_lazy("taxi:car-list") | ||
|
||
|
||
return render(request, "taxi/index.html", context=context) | ||
class CarDeleteView(LoginRequiredMixin, DeleteView): | ||
model = Car | ||
template_name = "taxi/car_confirm_delete.html" | ||
success_url = reverse_lazy("taxi:car-list") | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context["previous_page"] = self.request.META.get("HTTP_REFERER", "/") | ||
return context | ||
|
||
|
||
class ManufacturerListView(LoginRequiredMixin, generic.ListView): | ||
class ManufacturerListView(LoginRequiredMixin, ListView): | ||
model = Manufacturer | ||
context_object_name = "manufacturer_list" | ||
template_name = "taxi/manufacturer_list.html" | ||
paginate_by = 5 | ||
|
||
|
||
class CarListView(LoginRequiredMixin, generic.ListView): | ||
model = Car | ||
paginate_by = 5 | ||
queryset = Car.objects.all().select_related("manufacturer") | ||
class ManufacturerDetailView(LoginRequiredMixin, DetailView): | ||
model = Manufacturer | ||
template_name = "taxi/manufacturer_detail.html" | ||
|
||
|
||
class CarDetailView(LoginRequiredMixin, generic.DetailView): | ||
model = Car | ||
class ManufacturerCreateView(LoginRequiredMixin, CreateView): | ||
model = Manufacturer | ||
form_class = ManufacturerForm | ||
template_name = "taxi/manufacturer_form.html" | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
|
||
|
||
class ManufacturerUpdateView(LoginRequiredMixin, UpdateView): | ||
model = Manufacturer | ||
form_class = ManufacturerForm | ||
template_name = "taxi/manufacturer_form.html" | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
|
||
|
||
class ManufacturerDeleteView(LoginRequiredMixin, DeleteView): | ||
model = Manufacturer | ||
template_name = "taxi/manufacturer_confirm_delete.html" | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
|
||
|
||
class DriverListView(LoginRequiredMixin, ListView): | ||
model = Driver | ||
context_object_name = "driver_list" | ||
template_name = "taxi/driver_list.html" | ||
|
||
|
||
class DriverDetailView(LoginRequiredMixin, DetailView): | ||
model = Driver | ||
template_name = "taxi/driver_detail.html" | ||
|
||
|
||
class DriverCreateView(LoginRequiredMixin, CreateView): | ||
model = Driver | ||
form_class = DriverForm | ||
template_name = "taxi/driver_form.html" | ||
success_url = reverse_lazy("taxi:driver-list") | ||
|
||
|
||
class DriverListView(LoginRequiredMixin, generic.ListView): | ||
class DriverUpdateView(LoginRequiredMixin, UpdateView): | ||
model = Driver | ||
paginate_by = 5 | ||
form_class = DriverForm | ||
template_name = "taxi/driver_form.html" | ||
success_url = reverse_lazy("taxi:driver-list") | ||
|
||
|
||
class DriverDetailView(LoginRequiredMixin, generic.DetailView): | ||
class DriverDeleteView(LoginRequiredMixin, DeleteView): | ||
model = Driver | ||
queryset = Driver.objects.all().prefetch_related("cars__manufacturer") | ||
template_name = "taxi/driver_confirm_delete.html" | ||
success_url = reverse_lazy("taxi:driver-list") |
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,10 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Are you sure you want to delete this car?</h1> | ||
<form method="post"> | ||
{% csrf_token %} | ||
<button type="submit" class="btn btn-danger">Delete</button> | ||
<a href="{{ previous_page }}" class="btn btn-secondary">Cancel</a> | ||
</form> | ||
{% endblock %} |
Oops, something went wrong.
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.
The
DriverForm
class should extendforms.ModelForm
to be consistent with the other forms and to function correctly as a Django form. Consider implementing it similarly toCarForm
andManufacturerForm
.